Skip to content

Commit 189b9b6

Browse files
Remove the subject argument
1 parent c8b72b0 commit 189b9b6

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

com.unity.render-pipelines.core/Runtime/Utilities/Attributes/SupportedOnAttribute.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public class SupportedOnAttribute : Attribute
2222
/// </summary>
2323
/// <param name="subject">Which type will support <paramref name="target" />.</param>
2424
/// <param name="target">Defines what to support.</param>
25-
public SupportedOnAttribute(Type subject, Type target)
25+
public SupportedOnAttribute(Type target)
2626
{
27-
// Call directly registration here. This avoids storing properties in the memory footprint
28-
IsSupportedOn.RegisterStaticRelation(subject, target);
29-
IsSupportedOn.RegisterDynamicRelation(subject, target);
27+
this.target = target;
3028
}
29+
30+
public Type target { get; }
3131
}
3232

3333
/// <summary>
@@ -76,12 +76,14 @@ internal static void RegisterStaticRelation(Type subject, Type target)
7676
// So there must be no situation where the properties are not found.
7777

7878
var hasIsSupportedOn = typeof(HasIsSupportedOn<>).MakeGenericType(subject);
79+
7980
// ReSharper disable once PossibleNullReferenceException
8081
hasIsSupportedOn
8182
.GetProperty(nameof(HasIsSupportedOn<bool>.Value), BindingFlags.Static | BindingFlags.Public)
8283
.SetValue(null, true);
8384

8485
var isSupportedOn = typeof(IsSupportedOn<,>).MakeGenericType(subject, target);
86+
8587
// ReSharper disable once PossibleNullReferenceException
8688
isSupportedOn
8789
.GetProperty(nameof(IsSupportedOn<bool, bool>.internalValue), BindingFlags.Static | BindingFlags.NonPublic)
@@ -139,6 +141,7 @@ public static bool HasRelations(Type subject)
139141
/// Use <see cref="Value" /> to know if <typeparamref name="TSubject" /> explicitly support at least one type.
140142
/// </summary>
141143
/// <typeparam name="TSubject">The type to query.</typeparam>
144+
142145
// ReSharper disable once UnusedTypeParameter
143146
public struct HasIsSupportedOn<TSubject>
144147
{
@@ -147,8 +150,9 @@ public struct HasIsSupportedOn<TSubject>
147150
/// <typeparam name="TSubject" />
148151
/// explicitly support at least one type.
149152
/// </summary>
153+
150154
// ReSharper disable once StaticMemberInGenericType
151-
public static bool Value { get; } = false;
155+
public static bool Value { get; set; } = false;
152156
}
153157

154158
/// <summary>
@@ -157,11 +161,12 @@ public struct HasIsSupportedOn<TSubject>
157161
/// </summary>
158162
/// <typeparam name="TSubject">The subject to query.</typeparam>
159163
/// <typeparam name="TTarget">The type that defines what to support.</typeparam>
164+
160165
// ReSharper disable once UnusedTypeParameter
161166
public struct IsSupportedOn<TSubject, TTarget>
162167
{
163168
// ReSharper disable once StaticMemberInGenericType
164-
internal static bool internalValue { get; } = false;
169+
internal static bool internalValue { get; set; } = false;
165170

166171
/// <summary>
167172
/// Use it to know if <typeparamref name="TSubject" /> explicitly supports <typeparamref name="TTarget" />.
@@ -191,8 +196,12 @@ static void Initialize()
191196
// Note: Querying type with attribute with TypeCache is 4x faster that querying for assembly attribute
192197
foreach (var type in TypeCache.GetTypesWithAttribute<SupportedOnAttribute>())
193198
{
194-
// Trigger attribute constructor here
195-
var _ = type.GetCustomAttributes(typeof(SupportedOnAttribute)).FirstOrDefault() as SupportedOnAttribute;
199+
var attribute = type.GetCustomAttributes(typeof(SupportedOnAttribute)).FirstOrDefault() as SupportedOnAttribute;
200+
if (attribute?.target == null)
201+
continue;
202+
203+
IsSupportedOn.RegisterStaticRelation(type, attribute.target);
204+
IsSupportedOn.RegisterDynamicRelation(type, attribute.target);
196205
}
197206
}
198207
}

com.unity.render-pipelines.core/Tests/Editor/IsSupportedOn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace UnityEngine.Rendering.Tests
44
{
5-
[SupportedOn(typeof(__A), typeof(__B))]
5+
[SupportedOn(typeof(__B))]
66
class __A { }
77
class __B { }
88
class __C { }

com.unity.render-pipelines.core/Tests/Runtime/IsSupportedOn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace UnityEngine.Rendering.Tests
44
{
5-
[SupportedOn(typeof(__A), typeof(__B))]
5+
[SupportedOn(typeof(__B))]
66
class __A { }
77
class __B { }
88
class __C { }

0 commit comments

Comments
 (0)