diff --git a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerConstructorBuilder.cs b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerConstructorBuilder.cs index bf2da32a..3a2c3dc0 100644 --- a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerConstructorBuilder.cs +++ b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerConstructorBuilder.cs @@ -201,10 +201,14 @@ public static CsOnlinerConstructorBuilder Create(IxNodeVisitor visitor, IStructu HumanReadable = {typeof(Connector.Connector).n()}.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = {typeof(Connector.Connector).n()}.CreateSymbol(parent.Symbol, symbolTail);"); + builder.AddToSource(@$"PreConstruct(parent, readableTail, symbolTail);"); + semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder)); builder.AddToSource("parent.AddChild(this);"); builder.AddToSource("parent.AddKid(this);"); + builder.AddToSource(@$"PostConstruct(parent, readableTail, symbolTail);"); + builder.AddToSource("}"); return builder; diff --git a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerMemberBuilder.cs b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerMemberBuilder.cs index 35105da0..46a9f85d 100644 --- a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerMemberBuilder.cs +++ b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerMemberBuilder.cs @@ -196,6 +196,10 @@ public static CsOnlinerMemberBuilder Create(IxNodeVisitor visitor, IStructuredTy var builder = new CsOnlinerMemberBuilder(sourceBuilder); builder.AddToSource(semantics.DeclareProperties()); semantics.Fields.ToList().ForEach(p => p.Accept(visitor, builder)); + + builder.AddToSource(@$"partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail);"); + return builder; } diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/compileromitsattribute.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/compileromitsattribute.g.cs index 75699b34..88caabe1 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/compileromitsattribute.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/compileromitsattribute.g.cs @@ -1157,6 +1157,8 @@ public partial class Motor : AXSharp.Connector.ITwinObject { public OnlinerBool isRunning { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -1164,9 +1166,11 @@ public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string s this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); isRunning = @Connector.ConnectorAdapter.AdapterFactory.CreateBOOL(this, "isRunning", "isRunning"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() @@ -1363,6 +1367,8 @@ public partial class Vehicle : AXSharp.Connector.ITwinObject public OnlinerInt displacement { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -1370,10 +1376,12 @@ public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); m = new misc.Motor(this, "m", "m"); displacement = @Connector.ConnectorAdapter.AdapterFactory.CreateINT(this, "displacement", "displacement"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/configuration.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/configuration.g.cs index b3d301d6..9817e0dd 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/configuration.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/configuration.g.cs @@ -867,6 +867,8 @@ public partial class Motor : AXSharp.Connector.ITwinObject { public OnlinerBool isRunning { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -874,9 +876,11 @@ public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string s this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); isRunning = @Connector.ConnectorAdapter.AdapterFactory.CreateBOOL(this, "isRunning", "isRunning"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() @@ -1073,6 +1077,8 @@ public partial class Vehicle : AXSharp.Connector.ITwinObject public OnlinerInt displacement { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -1080,10 +1086,12 @@ public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); m = new Motor(this, "m", "m"); displacement = @Connector.ConnectorAdapter.AdapterFactory.CreateINT(this, "displacement", "displacement"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/misc.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/misc.g.cs index be130728..95fb29b3 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/misc.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/misc.g.cs @@ -705,6 +705,8 @@ public partial class Motor : AXSharp.Connector.ITwinObject { public OnlinerBool isRunning { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -712,9 +714,11 @@ public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string s this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); isRunning = @Connector.ConnectorAdapter.AdapterFactory.CreateBOOL(this, "isRunning", "isRunning"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() @@ -911,6 +915,8 @@ public partial class Vehicle : AXSharp.Connector.ITwinObject public OnlinerInt displacement { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -918,10 +924,12 @@ public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); m = new misc.Motor(this, "m", "m"); displacement = @Connector.ConnectorAdapter.AdapterFactory.CreateINT(this, "displacement", "displacement"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/mixed_access.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/mixed_access.g.cs index 318b3d82..f6824be0 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/mixed_access.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/mixed_access.g.cs @@ -261,6 +261,8 @@ public partial class struct1 : AXSharp.Connector.ITwinObject { public struct2 s2 { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public struct1(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -268,9 +270,11 @@ public struct1(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); s2 = new struct2(this, "s2", "s2"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() @@ -471,6 +475,8 @@ public partial class struct2 : AXSharp.Connector.ITwinObject { public struct3 s3 { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public struct2(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -478,9 +484,11 @@ public struct2(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); s3 = new struct3(this, "s3", "s3"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() @@ -681,6 +689,8 @@ public partial class struct3 : AXSharp.Connector.ITwinObject { public struct4 s4 { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public struct3(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -688,9 +698,11 @@ public struct3(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); s4 = new struct4(this, "s4", "s4"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() @@ -891,6 +903,8 @@ public partial class struct4 : AXSharp.Connector.ITwinObject { public OnlinerInt s5 { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public struct4(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -898,9 +912,11 @@ public struct4(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); s5 = @Connector.ConnectorAdapter.AdapterFactory.CreateINT(this, "s5", "s5"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/struct_simple.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/struct_simple.g.cs index 484d813b..e3270ea2 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/struct_simple.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/struct_simple.g.cs @@ -8,6 +8,8 @@ public partial class Motor : AXSharp.Connector.ITwinObject { public OnlinerBool isRunning { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -15,9 +17,11 @@ public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string s this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); isRunning = @Connector.ConnectorAdapter.AdapterFactory.CreateBOOL(this, "isRunning", "isRunning"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() @@ -214,6 +218,8 @@ public partial class Vehicle : AXSharp.Connector.ITwinObject public OnlinerInt displacement { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -221,10 +227,12 @@ public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); m = new Motor(this, "m", "m"); displacement = @Connector.ConnectorAdapter.AdapterFactory.CreateINT(this, "displacement", "displacement"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/types_with_name_attributes.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/types_with_name_attributes.g.cs index 27eeec36..33480590 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/types_with_name_attributes.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/types_with_name_attributes.g.cs @@ -11,6 +11,8 @@ public partial class Motor : AXSharp.Connector.ITwinObject { public OnlinerBool isRunning { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -18,9 +20,11 @@ public Motor(AXSharp.Connector.ITwinObject parent, string readableTail, string s this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); isRunning = @Connector.ConnectorAdapter.AdapterFactory.CreateBOOL(this, "isRunning", "isRunning"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain() @@ -217,6 +221,8 @@ public partial class Vehicle : AXSharp.Connector.ITwinObject public OnlinerInt displacement { get; } + partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); + partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail); public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail) { this.@SymbolTail = symbolTail; @@ -224,10 +230,12 @@ public Vehicle(AXSharp.Connector.ITwinObject parent, string readableTail, string this.@Parent = parent; HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail); Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail); + PreConstruct(parent, readableTail, symbolTail); m = new TypeWithNameAttributes.Motor(this, "m", "m"); displacement = @Connector.ConnectorAdapter.AdapterFactory.CreateINT(this, "displacement", "displacement"); parent.AddChild(this); parent.AddKid(this); + PostConstruct(parent, readableTail, symbolTail); } public async virtual Task OnlineToPlain()