/// <inheritdoc/> protected override void OnSetup(Type type, ConfigValueAttribute attribute) { ConfigNodeAttribute node = type.GetCustomAttribute <ConfigNodeAttribute>(); Id = node?.Id ?? type.Name; // there should only be 1 root node for one type if (node != null) { IsRootNode = node.IsRoot; ShouldSave = node.ShouldSave; if (node.IsRoot) { AllowMultiple = node.AllowMultiple; } } // if this is a member of some type if (attribute != null) { FARLogger.AssertFormat(!string.IsNullOrEmpty(attribute.Name), "Nested nodes required ConfigValue.Name to be set"); Name = attribute.Name; } // get all public fields var fields = new HashSet <FieldInfo>(type.GetFields(PublicFlags)); // and add all the other fields that declare ConfigValueAttribute fields.UnionWith(type.GetFieldsWithAttribute <ConfigValueAttribute>(flags: AllFlags) .Select(pair => pair.Second)); // only get properties that declare ConfigValueAttribute var properties = new List <PropertyInfo>(type.GetPropertiesWithAttribute <ConfigValueAttribute>(AllFlags) .Select(pair => pair.Second)); FARLogger.TraceFormat("Found {0} fields and {1} properties in {2}", fields.Count.ToString(), properties.Count.ToString(), type); foreach (FieldInfo fi in fields) { SetupType(fi, fi.FieldType); } foreach (PropertyInfo pi in properties) { SetupType(pi, pi.PropertyType); } if (!Children.TryGetValue(type, out List <Type> list)) { return; } foreach (Type subnode in list) { SetupType(null, subnode); } }
protected override void OnSetup(Type type, ConfigValueAttribute attribute) { ValueType = ReflectionUtils.ListType(ValueType) ?? ValueType; if (attribute != null) { Name = attribute.Name; } ConfigNodeAttribute node = ValueType.GetCustomAttribute <ConfigNodeAttribute>(); NodeId ??= node?.Id; }
private void SetupType(MemberInfo mi, Type memberType) { // if ignored, nothing to do if (mi?.GetCustomAttribute <ConfigValueIgnoreAttribute>() != null) { return; } // check if the type is a node and contains ConfigValueAttribute ConfigNodeAttribute node = memberType.GetCustomAttribute <ConfigNodeAttribute>(); ConfigValueAttribute value = mi?.GetCustomAttribute <ConfigValueAttribute>(); // try to get the list value type Type listValueType = ReflectionUtils.ListType(ReflectionUtils.ConfigValueType(memberType) ?? memberType); if (listValueType != null) { // is a list var reflection = ListValueReflection.Create(mi, value, listValueType); ListValues.Add(reflection); FARLogger.TraceFormat("Added list value '{1} -> <{0}, {2}>'", reflection.Name ?? "{null}", reflection.NodeId ?? "{null}", reflection.ValueType); } else if (node == null) { // not a node or a list -> simple value ValueReflection reflection = Create(mi, value); Values.Add(reflection); FARLogger.TraceFormat("Added value '{0} -> {1}'", reflection.Name, reflection.ValueType); } else { // ConfigValue name string name = value?.Name; // get clone or create new reflection for the type NodeReflection nodeReflection = GetReflection(memberType, true, name, mi); Nodes.Add(nodeReflection); FARLogger.TraceFormat("Added node '{1} -> <{0}, {2}>'", name ?? "{null}", nodeReflection.Id, nodeReflection.ValueType); } }