4 using System.Runtime.CompilerServices;
6 namespace SiliconStudio.Core.Reflection
14 private static readonly ConditionalWeakTable<object, ShadowContainer> Shadows =
new ConditionalWeakTable<object, ShadowContainer>();
32 public static bool TryGetDynamicProperty<T>(
this object instance,
object memberKey,
PropertyKey<T> attributeKey, out T value)
34 if (instance == null)
throw new ArgumentNullException(
"instance");
35 if (memberKey == null)
throw new ArgumentNullException(
"memberKey");
36 if (attributeKey == null)
throw new ArgumentNullException(
"attributeKey");
38 ShadowContainer shadow;
39 ShadowAttributes attributes;
41 return (Shadows.TryGetValue(instance, out shadow) && shadow.TryGetAttributes(memberKey, out attributes) && attributes.TryGetAttribute(attributeKey, out value));
59 public static void SetDynamicProperty<T>(
this object instance,
object memberKey,
PropertyKey<T> attributeKey, T value)
61 if (instance == null)
throw new ArgumentNullException(
"instance");
62 if (memberKey == null)
throw new ArgumentNullException(
"memberKey");
63 if (attributeKey == null)
throw new ArgumentNullException(
"attributeKey");
64 Shadows.GetOrCreateValue(instance)[memberKey].SetAttribute(attributeKey, value);
Allows to attach dynamic properties to an object at runtime.
A class that represents a typed tag propety.