コード例 #1
0
ファイル: ShadowObject.cs プロジェクト: Aggror/Stride
 /// <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));
 }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
 public static bool HasCollectionItemIds(object instance)
 {
     return(ShadowObject.Get(instance)?.ContainsKey(CollectionItemIdKey) ?? false);
 }