/// <summary> /// Tries to get the value of a dynamic property. /// </summary> /// <typeparam name="T">Type of the value</typeparam> /// <param name="instance">The instance object.</param> /// <param name="memberKey">The member key.</param> /// <param name="attributeKey">The attribute key.</param> /// <param name="value">The value attached.</param> /// <returns><c>true</c> if there is a value attached, <c>false</c> otherwise.</returns> /// <exception cref="System.ArgumentNullException"> /// instance /// or /// memberKey /// or /// attributeKey /// </exception> public static bool TryGetDynamicProperty <T>(this object instance, object memberKey, PropertyKey <T> attributeKey, out T value) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } if (memberKey == null) { throw new ArgumentNullException(nameof(memberKey)); } if (attributeKey == null) { throw new ArgumentNullException(nameof(attributeKey)); } ShadowObject shadow; value = default(T); object objValue = null; var result = (ShadowObject.TryGet(instance, out shadow) && shadow.TryGetValue(new ShadowObjectPropertyKey(memberKey, attributeKey), out objValue)); if (result) { value = (T)objValue; } return(result); }
/// <summary> /// Tries to get the <see cref="ShadowObject"/> instance associated. /// </summary> /// <param name="instance">The live instance</param> /// <param name="shadow">The shadow object</param> /// <returns><c>true</c> if the shadow object was found, <c>false</c> otherwise</returns> public static bool TryGet(object instance, out ShadowObject shadow) { shadow = null; if (!Enable || instance == null) { return(false); } return(Shadows.TryGetValue(instance, out shadow)); }
public static Guid GetId(object instance) { var shadow = ShadowObject.GetShadow(instance); if (shadow == null) { return(Guid.Empty); } return(shadow.GetId(instance)); }
public void CopyTo(ShadowObject copy) { copy.id = id; copy.isIdentifiable = isIdentifiable; foreach (var keyValue in this) { copy.Add(keyValue.Key, keyValue.Value); } }
internal void CopyTo(ShadowObject copy) { copy.id = id; copy.isIdentifiable = isIdentifiable; copy.IsSelected = IsSelected; copy.IsHover = IsHover; foreach (var keyValue in this) { copy.Add(keyValue.Key, keyValue.Value); } }
public static bool TryGetId(object instance, out Guid id) { var shadow = ShadowObject.Get(instance); if (shadow == null) { id = Guid.Empty; return(false); } id = shadow.GetId(instance); return(true); }
public static bool TryGetCollectionItemIds(object instance, out CollectionItemIdentifiers itemIds) { var shadow = ShadowObject.Get(instance); if (shadow == null) { itemIds = null; return(false); } object result; itemIds = shadow.TryGetValue(CollectionItemIdKey, out result) ? (CollectionItemIdentifiers)result : null; return(result != null); }
/// <summary> /// Remove all overrides information attached to an instance (Note that this method is not recursive and must be applied on all object). /// </summary> /// <param name="instance">An object instance</param> public static void RemoveFrom(object instance) { if (instance == null) throw new ArgumentNullException(nameof(instance)); var shadow = ShadowObject.GetShadow(instance); if (shadow == null) { return; } // Remove override information from an object foreach (var attributes in shadow.Members) { attributes.Attributes.Remove(OverrideKey); } }
/// <summary> /// Sets a dynamic property. /// </summary> /// <typeparam name="T">Type of the value</typeparam> /// <param name="instance">The instance object.</param> /// <param name="memberKey">The member key.</param> /// <param name="attributeKey">The attribute key.</param> /// <param name="value">The value.</param> /// <exception cref="System.ArgumentNullException"> /// instance /// or /// memberKey /// or /// attributeKey /// </exception> public static void SetDynamicProperty <T>(this object instance, object memberKey, PropertyKey <T> attributeKey, T value) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } if (memberKey == null) { throw new ArgumentNullException(nameof(memberKey)); } if (attributeKey == null) { throw new ArgumentNullException(nameof(attributeKey)); } ShadowObject.GetOrCreate(instance)[new ShadowObjectPropertyKey(memberKey, attributeKey)] = value; }
public static CollectionItemIdentifiers GetCollectionItemIds(object instance) { if (instance.GetType().IsValueType) { throw new ArgumentException(@"The given instance is a value type and cannot have a item ids attached to it.", nameof(instance)); } var shadow = ShadowObject.GetOrCreate(instance); object result; if (shadow.TryGetValue(CollectionItemIdKey, out result)) { return((CollectionItemIdentifiers)result); } var itemIds = new CollectionItemIdentifiers(); shadow.Add(CollectionItemIdKey, itemIds); return(itemIds); }
/// <summary> /// Remove all overrides information attached to an instance (Note that this method is not recursive and must be applied on all object). /// </summary> /// <param name="instance">An object instance</param> public static void RemoveFrom(object instance) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } var shadow = ShadowObject.Get(instance); if (shadow == null) { return; } // Remove override information from an object foreach (var memberKey in shadow.Keys.ToList()) { if (memberKey.Item2 == OverrideKey) { shadow.Remove(memberKey); } } }
public static bool HasCollectionItemIds(object instance) { return(ShadowObject.Get(instance)?.ContainsKey(CollectionItemIdKey) ?? false); }
public static void SetId(object instance, Guid id) { var shadow = ShadowObject.GetShadow(instance); shadow?.SetId(instance, id); }
public static Guid GetId(object instance) { var shadow = ShadowObject.GetOrCreate(instance); return(shadow.GetId(instance)); }