static IEnumerable <Delegate> ExtractPrivateFieldValues(object instance, bool ensureMaximumOfOne, AttributeFullName attributeFullName) { var details = FieldInspectionArguments <Delegate> .CreateFromInstance(instance, ensureMaximumOfOne, attributeFullName); CollectFieldDetails(details); return(details.Items); }
public static FieldInspectionArguments <T> CreateFromInstance(object instance, bool ensureMaximumOfOne, AttributeFullName attributeFullName) { var delegates = new List <T>(); var type = instance.GetType(); return(new FieldInspectionArguments <T>(type, () => instance, delegates, ensureMaximumOfOne, attributeFullName)); }
public FieldInspectionArguments(Type target, Func <object> instanceResolver, ICollection <T> items, bool ensureMaximumOfOne, AttributeFullName attributeFullName) { _target = target; _instanceResolver = instanceResolver; _ensureMaximumOfOne = ensureMaximumOfOne; _attributeFullName = attributeFullName; _instance = instanceResolver(); Items = items; }
public static bool IsOfUsage(this FieldInfo fieldInfo, AttributeFullName attributeFullName) { return(GetDelegateUsage(fieldInfo) == attributeFullName); }
public static IEnumerable <FieldInfo> GetInstanceFieldsOfUsage(this Type type, AttributeFullName attributeFullName) { return(GetInstanceFields(type).Where(x => GetDelegateUsage(x) == attributeFullName)); }
public static bool IsOfUsage(this FieldInfo fieldInfo, AttributeFullName attributeFullName) { return GetDelegateUsage(fieldInfo) == attributeFullName; }
public static IEnumerable<FieldInfo> GetInstanceFieldsOfUsage(this Type type, AttributeFullName attributeFullName) { return GetInstanceFields(type).Where(x => GetDelegateUsage(x) == attributeFullName); }
static List <Delegate> ExtractPrivateFieldValues(object instance, bool ensureMaximumOfOne, AttributeFullName attributeFullName) { var delegates = new List <Delegate>(); var type = instance.GetType(); CollectDetailsOf(type, () => instance, delegates, ensureMaximumOfOne, attributeFullName); return(delegates); }
static void CollectDetailsOf <T>(Type target, Func <object> instanceResolver, ICollection <T> items, bool ensureMaximumOfOne, AttributeFullName attributeFullName) { if (target == typeof(Object) || target == null) { return; } if (target.IsAbstract) { } if (!IsStatic(target)) { var instance = instanceResolver(); if (instance == null) { return; } var fields = target.GetInstanceFieldsOfUsage(attributeFullName); if (ensureMaximumOfOne && fields.Count() > 1) { throw new SpecificationUsageException(String.Format("You cannot have more than one {0} clause in {1}", fields.First().FieldType.Name, target.FullName)); } var field = fields.FirstOrDefault(); if (field != null) { var val = (T)field.GetValue(instance); items.Add(val); } CollectDetailsOf(target.BaseType, () => instance, items, ensureMaximumOfOne, attributeFullName); } CollectDetailsOf(target.DeclaringType, () => Activator.CreateInstance(target.DeclaringType), items, ensureMaximumOfOne, attributeFullName); }