当前位置: 首页>>代码示例>>C#>>正文


C# IStore.Get方法代码示例

本文整理汇总了C#中IStore.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IStore.Get方法的具体用法?C# IStore.Get怎么用?C# IStore.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IStore的用法示例。


在下文中一共展示了IStore.Get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Check

        public void Check(IEnumerable<IComponent> components, IStore<string, IArtificialIntelligence> aiStore)
        {
            var groupedByOwener = components.GroupBy(x => x.OwnerId);

            foreach (var group in groupedByOwener) {
                var enemies = components.Except(group).OfType<IFieldOfVision>();
                foreach (var component in group) {
                    foreach (var enemy in enemies) {
                        var isInFieldOfVision = enemy.IsInFieldOfVision(component.Position);
                        if (isInFieldOfVision) {
                            var artificialIntelligence = aiStore.Get(enemy.OwnerId);
                            artificialIntelligence.Fire(new ComponentSpottedEvent(enemy.OwnerId, enemy.Id, component.Id, component.OwnerId, component.Position.X, component.Position.Y, component.GetType()));
                            SpottedUnitsStore.Store(component.Id, enemy.OwnerId);
                        }
                    }
                }

            }

            //foreach (var group in groupedByOwener) {
            //    var others = components.Except(group).OfType<IFieldOfVision>();
            //    foreach (var component in group) {
            //        var spottingUnits = others.Where(x => x.IsInFieldOfVision(component.Position));

            //        foreach (var fieldOfVision in spottingUnits) {
            //            var artificialIntelligence = aiStore.Get(fieldOfVision.OwnerId);
            //            artificialIntelligence.Fire(new ComponentSpottedEvent(fieldOfVision.OwnerId,fieldOfVision.Id,component.Id,component.OwnerId,component.Position.X,component.Position.Y, component.GetType()));
            //            SpottedUnitsStore.Store(component.Id,fieldOfVision.OwnerId);
            //        }
            //    }
            //}

            var spottedUnits = SpottedUnitsStore.GetKeys();
            Parallel.ForEach(spottedUnits, (suid,loopState) =>
                                                    {
                                                        var spottedComponent = components.SingleOrDefault(x => x.Id.Equals(suid));
                                                        if(spottedComponent == null)
                                                        {
                                                            SpottedUnitsStore.Remove(suid);
                                                        }
                                                        else
                                                        {
                                                            var enemyOwnerId = SpottedUnitsStore.Get(suid);
                                                            if(enemyOwnerId == null)
                                                                return;
                                                                var enemyUnits =
                                                                components.Where(x => x.OwnerId.Equals(enemyOwnerId)).OfType<IFieldOfVision>();

                                                            if(enemyUnits.All(x => !x.IsInFieldOfVision(spottedComponent.Position)))
                                                            {
                                                                SpottedUnitsStore.Remove(spottedComponent.Id);
                                                                var artificialIntelligence = aiStore.Where(x => x.Id.Equals(enemyOwnerId)).First();
                                                                artificialIntelligence.Fire(new ComponentLeftFieldOfVisionEvent(artificialIntelligence.Id,spottedComponent.Id,spottedComponent.OwnerId,spottedComponent.Position.X,spottedComponent.Position.Y,spottedComponent.GetType()));
                                                            }

                                                        }
                                                    });
        }
开发者ID:Ostblock,项目名称:Ostzone,代码行数:58,代码来源:ComponentHitsFieldOfVisionService.cs

示例2: HydrateFromStore

        /// <summary>
        /// hydrates an object
        /// </summary>
        /// <param name="store"></param>
        /// <param name="obj"></param>
        /// <param name="filter"></param>
        public static void HydrateFromStore(IStore store, object obj, Func<FieldInfo, bool> filter)
        {
            Condition.Requires(obj).IsNotNull();
            Condition.Requires(store).IsNotNull();

            //validate we're dealing with the right object
            var objectTypeEntry = store.Get<ContextualAsId<string, Type>>(TYPEKEY);
            Condition.Requires(objectTypeEntry).IsNotNull();

            Type objType = obj.GetType();
            Condition.Requires(objType.Equals(objectTypeEntry.Context));

            var fields = ReflectionUtil.GetFieldInfosIncludingBaseClasses(objType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            //for each field, build data to save to the store
            foreach (FieldInfo field in fields)
            {
                if (filter != null && filter(field))
                    continue;

                //key the field 
                var id = field.DeclaringType.Name + "_" + field.Name;

                //is it null?
                var isNullEntry = store.Get<ContextualAsId<string, bool>>(id);
                Condition.Requires(isNullEntry).IsNotNull();
                if (!isNullEntry.Context)
                {
                    //var typeEntry = store.Get<ContextualAsId<string, Type>>(id);
                    var val = store.Get<ContextualAsId<string, object>>(id);

                    //now set it
                    field.SetValue(obj, val.Context);
                }
            }
        }
开发者ID:Piirtaa,项目名称:Decoratid,代码行数:42,代码来源:Object2StoreConverter.cs

示例3: IsRequested

 private bool IsRequested(IStore requestStore, string operationName)
 {
     Condition.Requires(requestStore).IsNotNull();
     var req = requestStore.Get<OperationArg>(operationName);
     return req != null;
 }
开发者ID:Piirtaa,项目名称:Decoratid,代码行数:6,代码来源:OperationManager.cs

示例4: ConvertFromStore

        public static object ConvertFromStore(IStore store, Func<FieldInfo, bool> filter)
        {
            Condition.Requires(store).IsNotNull();

            //validate we're dealing with the right object
            var objectTypeEntry = store.Get<ContextualAsId<string, Type>>(TYPEKEY);
            Condition.Requires(objectTypeEntry).IsNotNull();

            var obj = New.Create(objectTypeEntry.Context);
            HydrateFromStore(store, obj, filter);

            return obj;
        }
开发者ID:Piirtaa,项目名称:Decoratid,代码行数:13,代码来源:Object2StoreConverter.cs


注:本文中的IStore.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。