Hi Michael,
Thanks for the reply.
I am not writing a OBJECT Serializater. But implementing Code Generation for WindowsForm control at Design-Time using a Custom CodeDomSerializer.
Here is what I have.
- I have a user control i.e. MyControl written in C#.
- MyControl has a property MyControlProperty of type ObjectXXX that is accessible publicly.(like myControl.MyControlProperty).
- The type ObjectYYY has a public property PropertyXXX of type Collection<double>.
- The ObjectXXX has a internal field of type ObjectYYY.
- The ObjectXXX should be initialized by passing Collection<double> which is nothing but ObjectYYY.PropertyXXX.
The code generated should be as given in the code snippet below.
Line1. NamespaceX.NamespaceY.ObjectXXX x = new NamespaceX.NamespaceY.ObjectXXX(NamespaceX.NamespaceY.ObjectYYY.PropertyXXX);Line2. myControl.MyControlProperty = x;I succeeded in generating the aforementioned code at Design-Time by writing a custom CodeDomSerializer
FOR C# Language.
But, if i use MyControl for developing an application in C++ Language, the DOT operator is serialized for both ScopeResolution and Pointer-To-Member operator.
What I am doing for code in Line1 is,
string fullyQualifiedName = "NamespaceX.NamespaceY.ObjectYYY.PropertyXXX"; // HERE VARIABLE NAME IS HARDCODED WITH TWO TYPES OF OPERATORS
CodeExpression[] parameters = new CodeExpression[] {new CodeVariableReferenceExpression(fullyQualifiedName);};
CodeStatement code = new CodeVariableDeclarationStatement(typeof(ObjectXXX), "objectXXX1", new CodeObjectCreateExpression(new CodeTypeReference(typeof(ObjectXXX)), parameters));
generatedCode.Add(code); //generatedCode has the final codeFor Line2,
CodeExpression codeLhs = new CodeVariableReferenceExpression(myControlVariable + "." + "MyControlProperty"); // HERE Pointer-To-Member IS HARDCODED AS DOT
CodeExpression codeRhs = new CodeVariableReferenceExpression("objectXXX1");
CodeAssignStatement codeAssignStmt = new CodeAssignStatement(codeLhs, codeRhs);
generatedCode.Add(codeAssignStmt); //generatedCode has the final codeObviously the C++ Designer generated code should have '
::' operator(and not DOT) for the ScopeResolution and '
->' for the Pointer-To-Member resolution. I was not able to figure out how to make the code serialization for any CLR supported language.
How to solve this problem?