public static void test6() { var builder = new FoClass("FoComponent"); var root = builder.ConstructInstanceCore("") as FoComponent; IFoProperty[] props1 = { new FoProperty <string>("proper name", "Stephen R. Strong"), }; IFoProperty[] props2 = { new FoProperty <double>("tax", .33), new FoProperty <double>("total", () => { return(1000); }) }; root.Properties.AddList(props1); IFoComponent[] comps = { new FoComponent("Comp1", props2), }; root.Subcomponents.AddList(comps); var comp = comps[0] as FoComponent; Console.WriteLine($"==========================="); Console.WriteLine($"{root.AsJson()}"); Console.WriteLine($"{comp.AsJson()}"); root.saveToFile(@"data/test6.json"); Console.WriteLine($".........................."); }
public static void test1() { var builder = new FoClass("FoComponent"); var root = builder.ConstructInstanceCore("") as FoComponent; IFoProperty[] props = { new FoProperty <double>("width", 100), new FoProperty <double>("height", .33), new FoProperty <double>("area", () => { var width = new FoReference("width"); var height = new FoReference("height"); var area = width.GetValue <double>(root) * height.GetValue <double>(root); return(area); }) }; root.Properties.AddList(props); //var root = new FoComponent("Comp1", props); Console.WriteLine($"==========================="); Console.WriteLine($"{root.AsJson()}"); Console.WriteLine($".........................."); }
public virtual bool AddInheritFrom(FoClass superClass) { if (superClass == null || superClass == this) { return(false); } _SuperClass.AddNoDuplicate(superClass); superClass.Subs.AddNoDuplicate(this); return(true); }
public static void test5() { var path = "C:\\Users\\Steve\\workspace\\FoundryDotNet5\\FoundryCore\\data\\create_root.json"; var body = JSONExtensions.readFromFile(path); //var body = JSONExtensions.readFromFile(@"data/create_root.json"); var name = body.GetProperty("MyName").ToString(); var type = body.GetProperty("MyType").ToString(); var builder = new FoClass(type); var root = builder.ConstructInstanceCore(""); Console.WriteLine($"==========================="); Console.WriteLine($"{root.toJson()}"); Console.WriteLine($"{root.AsJson()}"); root.saveToFile(@"data/test5.json"); Console.WriteLine($".........................."); }
private Type DetermineConstruction(Type DefaultType) { if (_ConstructionType != null) { return(_ConstructionType); } Type oType = ApprenticeType(MyName); if (oType != null && oType.IsClass && oType.IsSubclassOf(DefaultType)) { return(oType); } FoClass oClass = _SuperClass[0] as FoClass; if (oClass == null) { return(DefaultType); } else { oType = oClass.DetermineConstruction(DefaultType); } if (_SuperClass.Count > 1) { foreach (FoClass oSuper in _SuperClass.Value) { if (oSuper == oClass) { continue; } Type oNewType = oSuper.DetermineConstruction(DefaultType); oType = oNewType.IsSubclassOf(oType) ? oNewType : oType; } } return(oType); }