/// <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 void CheckValueType(object value, SourceInfo current) { FARLogger.AssertFormat(ValueType.IsBaseOf(value.GetType()), "Invalid value type {0}, expected {1}", current, value.GetType(), ValueType); }
protected void CheckInstanceType(object instance, SourceInfo current) { FARLogger.AssertFormat(StaticParser && instance == null || instance != null && (DeclaringType?.IsBaseOf(instance.GetType()) ?? true), "Invalid instance type {0}, expected {1}", current, instance?.GetType(), DeclaringType); }