public static Requirement[] GetAllRequirements(object @object) { var type = @object.GetType(); List <Requirement> requirements = null; if (_typeRequirementsDictionary.TryGetValue(type, out requirements)) { return(requirements.ToArray()); } else { requirements = new List <Requirement>(); var fieldList = StatesAssemblyExtension.GetAllFieldsWithAttribute(type, typeof(RequiredReferenceAttribute)); for (int i = 0; i < fieldList.Count; i++) { if (fieldList[i].FieldType.IsArray || fieldList[i].FieldType.GetInterfaces().Contains(typeof(IList))) { requirements.AddRange(GetRequirementsInList(fieldList[i].GetValue(@object) as IList)); } else { requirements.Add(new Requirement(@object, fieldList[i])); } } _typeRequirementsDictionary.Add(type, requirements); return(requirements.ToArray()); } }
private static Requirement[] GetRequirementsInList(IList list) { List <Requirement> Requirements = new List <Requirement>(); for (int i = 0; i < list.Count; i++) { var fields = StatesAssemblyExtension.GetAllFieldsWithAttribute(list[i].GetType(), typeof(RequiredReferenceAttribute)).ToArray(); for (int j = 0; j < fields.Length; j++) { if (fields[j].FieldType.IsArray || fields[j].FieldType.GetInterfaces().Contains(typeof(IList))) { Requirements.AddRange(GetRequirementsInList(fields[j].GetValue(list[i]) as IList)); } else { Requirements.Add(new Requirement(list[i], fields[j])); } } } return(Requirements.ToArray()); }
/// <summary> /// Collect information for all required references for state to work. /// </summary> /// <returns></returns> public static FieldInfo[] GetAllRequiredFields(object @object) { return(StatesAssemblyExtension.GetAllFieldsWithAttribute(@object.GetType(), typeof(RequiredReferenceAttribute)).ToArray()); }