Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
 /// <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));
 }
Esempio n. 3
0
        public static Guid GetId(object instance)
        {
            var shadow = ShadowObject.GetShadow(instance);

            if (shadow == null)
            {
                return(Guid.Empty);
            }
            return(shadow.GetId(instance));
        }
Esempio n. 4
0
        public void CopyTo(ShadowObject copy)
        {
            copy.id             = id;
            copy.isIdentifiable = isIdentifiable;

            foreach (var keyValue in this)
            {
                copy.Add(keyValue.Key, keyValue.Value);
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        /// <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);
            }
        }
Esempio n. 9
0
 /// <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;
 }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        /// <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);
                }
            }
        }
Esempio n. 12
0
 public static bool HasCollectionItemIds(object instance)
 {
     return(ShadowObject.Get(instance)?.ContainsKey(CollectionItemIdKey) ?? false);
 }
Esempio n. 13
0
        public static void SetId(object instance, Guid id)
        {
            var shadow = ShadowObject.GetShadow(instance);

            shadow?.SetId(instance, id);
        }
Esempio n. 14
0
        public static Guid GetId(object instance)
        {
            var shadow = ShadowObject.GetOrCreate(instance);

            return(shadow.GetId(instance));
        }