public ChildMapCategory(IMapCategory parent, string name, PropertyInfo propertyInfo) : base(parent.IsPropertyName, name, propertyInfo.PropertyType) { Parent = parent; this.name = name; this.propertyInfo = propertyInfo; }
public void GetSetValue() { var mapper = new CategoriesMapper(); IMapCategory construction = mapper.Construct <MainItem>(); MainItem main = new MainItem(); main.IsGood = true; main.Total = 2; main.SubCat.Weight = 4; DataTree tree = new DataTree(main, construction); Assert.AreEqual(true, tree.Leafs[1].Value); Assert.AreEqual(2, tree.Leafs[0].Value); Assert.AreEqual(4, tree.Branches[0].Leafs[0].Value); tree.Leafs[1].Value = false; Assert.AreEqual(false, tree.Leafs[1].Value); Assert.AreEqual(false, main.IsGood); tree.Leafs[0].Value = 88; Assert.AreEqual(88, tree.Leafs[0].Value); Assert.AreEqual(88, main.Total); tree.Branches[0].Leafs[0].Value = 7; Assert.AreEqual(7, tree.Branches[0].Leafs[0].Value); Assert.AreEqual(7, main.SubCat.Weight); }
public DataTree(object instance, IMapCategory category, IDataItemFactory dataItemFactory) { Instance = instance; currentCategory = category ?? throw new ArgumentNullException(nameof(category)); this.dataItemFactory = dataItemFactory ?? throw new ArgumentNullException(nameof(dataItemFactory)); Build(); }
private static void ExtractCollectionField(IMapCategory parent) { foreach (var mainProperty in GetProperties <InfoArrayCategoryAttribute>(parent.OwnerType)) { InfoArrayCategoryAttribute attribute = GetAttribute <InfoArrayCategoryAttribute>(mainProperty); MapCategory mapCategory = new CollectionMapCategory(parent, attribute, mainProperty); parent.AddCategory(mapCategory); } }
public void ResolveInstance() { var mapper = new CategoriesMapper(); IMapCategory construction = mapper.Construct <MainItem>(); MainItem main = new MainItem(); Assert.AreEqual(main, construction.ResolveInstance(main)); Assert.AreEqual(main.SubCat, construction.Categories.First().ResolveInstance(main)); }
public IDataTree Create(IDataTree tree, IMapCategory mapCategory) { object instance = mapCategory.Parent.IsCollapsed ? mapCategory.ResolveInstance(mapCategory.Parent.ResolveInstance(tree.Instance)) : mapCategory.ResolveInstance(tree.Instance); return(mapCategory.OwnerType == typeof(DataTree) ? (DataTree)instance : new DataTree(instance, mapCategory)); }
public void RegularConstruct() { var mapper = new CategoriesMapper(); IMapCategory construction = mapper.Construct <MainItem>(); Assert.AreEqual(3, construction.AllChildFields.Count()); Assert.AreEqual(2, construction.Fields.Count()); Assert.AreEqual(2, construction.Categories.Count()); Assert.AreEqual(1, construction.Categories.First().Fields.Count()); }
public void Create() { var mapper = new CategoriesMapper(); IMapCategory construction = mapper.Construct <MainItem>(); MainItem main = new MainItem(); DataTree tree = new DataTree(main, construction); Assert.AreEqual(main, tree.Instance); Assert.AreEqual(construction.Categories.Count(), tree.Branches.Count); Assert.AreEqual(main.SubCat, tree.Branches[0].Instance); Assert.AreEqual(construction.Fields.Count(), tree.Leafs.Count); Assert.AreEqual(construction.AllChildFields.Count(), tree.AllLeafs.Count()); }
public void SetValue() { var mapper = new CategoriesMapper(); IMapCategory construction = mapper.Construct <MainItem>(); MainItem main = new MainItem(); construction["IsGood"].First().SetValue(main, true); construction["Weight"].First().SetValue(main.SubCat, 10); construction["Total"].First().SetValue(main, 20); Assert.AreEqual(true, main.IsGood); Assert.AreEqual(20, main.Total); Assert.AreEqual(10, main.SubCat.Weight); }
public void GetValue() { var mapper = new CategoriesMapper(); IMapCategory construction = mapper.Construct <MainItem>(); MainItem main = new MainItem(); main.IsGood = true; main.Total = 2; main.SubCat.Weight = 4; Assert.AreEqual(true, construction["IsGood"].First().GetValue <bool>(main)); Assert.AreEqual(4, construction["Weight"].First().GetValue <int>(main.SubCat)); Assert.AreEqual(2, construction["Total"].First().GetValue <int>(main)); }
public EnumerableMapCategory(IMapCategory parent, string name, PropertyInfo propertyInfo) : base(parent, name, propertyInfo) { if (!typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType)) { throw new ArgumentException(nameof(propertyInfo.PropertyType)); } CategoriesMapper mapper = new CategoriesMapper(); var type = propertyInfo.PropertyType.IsGenericType ? propertyInfo.PropertyType.GetGenericArguments().First() : propertyInfo.PropertyType.GetElementType(); category = mapper.Construct(type); }
public void TestCollection() { var mapper = new CategoriesMapper(); IMapCategory construction = mapper.Construct <MainItem>(); MainItem main = new MainItem(); DataTree tree = new DataTree(main, construction); Assert.AreEqual(0, tree.Branches[1].Leafs.Count); main.Data["Test"] = 4; tree = new DataTree(main, construction); Assert.AreEqual(1, tree.Branches[1].Leafs.Count); Assert.AreEqual(4, tree.Branches[1].Leafs[0].Value); Assert.AreEqual("Test", tree.Branches[1].Leafs[0].Name); Assert.AreEqual("Test", tree.Branches[1].Leafs[0].Description); }
public void DictionaryValue() { Dictionary <string, double> map = new Dictionary <string, double>(); map["IsGood"] = 0.1; map["Weight"] = 3; var mapper = new CategoriesMapper(); IMapCategory construction = mapper.Construct <MainItem>(); MainItem main = new MainItem(); main.IsGood = true; main.Total = 2; main.SubCat.Weight = 4; DataTree tree = new DataTree(main, construction, new DictionaryDataItemFactory(map)); Assert.AreEqual(0.1, Math.Round((double)tree.Leafs[1].Value, 2)); Assert.AreEqual(0, tree.Leafs[0].Value); Assert.AreEqual(3, tree.Branches[0].Leafs[0].Value); }
private void ProcessType(IMapCategory parent) { foreach (var mainProperty in GetProperties <InfoCategoryAttribute>(parent.OwnerType)) { InfoCategoryAttribute attribute = GetAttribute <InfoCategoryAttribute>(mainProperty); if (attribute.Ignore) { continue; } MapCategory mapCategory = new ChildMapCategory(parent, attribute.Name, mainProperty); mapCategory.IsCollapsed = attribute.IsCollapsed; parent.AddCategory(mapCategory); ProcessType(mapCategory); } ExtractField(parent); ExtractCollectionField(parent); }
private static void ExtractField(IMapCategory parent) { foreach (var fieldProperty in GetProperties <InfoFieldAttribute>(parent.OwnerType)) { var ignore = GetAttribute <IgnoreAttribute>(fieldProperty); if (ignore != null) { continue; } InfoFieldAttribute attribute = GetAttribute <InfoFieldAttribute>(fieldProperty); if (fieldProperty.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(fieldProperty.PropertyType)) { var mapCategory = new EnumerableMapCategory(parent, attribute.Name, fieldProperty); parent.AddCategory(mapCategory); } else { parent.AddField(new MapField(parent, attribute, fieldProperty)); } } }
public CollectionMapCategory(IMapCategory parent, InfoArrayCategoryAttribute attribute, PropertyInfo propertyInfo) : base(parent, attribute.Name, propertyInfo) { Attribute = attribute; }
public void AddCategory(IMapCategory mapCategory) { categories.Add(mapCategory); Reset(); }
public IDataTree Create(IDataTree tree, IMapCategory mapCategory) { return(new DataTree(map, mapCategory, this)); }
public MapField(IMapCategory category, InfoFieldAttribute attribute, PropertyInfo propertyInfo) { Category = category ?? throw new ArgumentNullException(nameof(category)); this.attribute = attribute ?? throw new ArgumentNullException(nameof(attribute)); this.propertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); }
public DataTree(object instance, IMapCategory category) : this(instance, category, MapFieldDataItemFactory.Instance) { }