/// <summary> /// Converts an element into a node. /// </summary> /// <param name="thing">The object.</param> /// <param name="info">The info to convert.</param> /// <param name="optionsLookup">The options.</param> /// <returns>The node if it can be converted, otherwise null.</returns> public static PropertyNode?ToNode(object?thing, ElementInfo info, ILookup <string, PropertyInfo>?optionsLookup = null) { optionsLookup ??= Array.Empty <PropertyInfo>().ToLookup(p => p.Name); IEnumerable <PropertyInfo> options = optionsLookup[info.Name]; if (info.PropertyType == typeof(string)) { if (info.Compiled != null) { return(new CompiledPropertyNode( thing, info, options)); } else { return(new StringPropertyNode( thing, info, options)); } } else if (info.PropertyType.IsSubclassOf(typeof(BaseDefinition))) { return(new DefinitionPropertyNode( thing, info, options)); } else if (info.PropertyType.IsEnum) { return(new EnumPropertyNode( thing, info, options)); } else if (info.PropertyType == typeof(bool)) { return(new BoolPropertyNode( thing, info, options)); } else if (info.PropertyType == typeof(int)) { return(new IntPropertyNode( thing, info, options)); } else if (typeof(IDictionary).IsAssignableFrom(info.PropertyType)) { return(new DictionaryPropertyNode( thing, info, options)); } else if (typeof(IList).IsAssignableFrom(info.PropertyType)) { return(new ListPropertyNode( thing, info, options)); } else { Console.WriteLine("asdf"); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="IntPropertyNode"/> class. /// </summary> /// <param name="thing">The thing this node points to.</param> /// <param name="property">The property info.</param> /// <param name="options">The options for this node.</param> /// <param name="readOnly">If this instance should be read only.</param> public IntPropertyNode(object?thing, ElementInfo property, IEnumerable <PropertyInfo> options, bool readOnly = false) : base(thing, property, options, readOnly) { }