本文整理汇总了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()));
}
}
});
}
示例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);
}
}
}
示例3: IsRequested
private bool IsRequested(IStore requestStore, string operationName)
{
Condition.Requires(requestStore).IsNotNull();
var req = requestStore.Get<OperationArg>(operationName);
return req != null;
}
示例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;
}