Using CodeDOM in .NET to AutoGenereate a constant member field
-
Hi All, I have used CodeDOM in .net to auto-generate C# code, which in essence generates a class file having a class along with its member fields, methods and properties. However, i don know how to generate the following line of code: private const string NAME = "CSharp"; Here, i have a generate a CodeMemberField which is a constant string with a private specifier as shown above. Please send me the sample code which would help me to auto-generate the above line of code. Thanks, Ramesh
-
Hi All, I have used CodeDOM in .net to auto-generate C# code, which in essence generates a class file having a class along with its member fields, methods and properties. However, i don know how to generate the following line of code: private const string NAME = "CSharp"; Here, i have a generate a CodeMemberField which is a constant string with a private specifier as shown above. Please send me the sample code which would help me to auto-generate the above line of code. Thanks, Ramesh
How do you auto-generate c# code? You can build your code from strings and then compile it into dll file or executable dynamically during runtime
#region signature my articles #endregion
-
How do you auto-generate c# code? You can build your code from strings and then compile it into dll file or executable dynamically during runtime
#region signature my articles #endregion
ya .... tats wat i meant Giorgi.... as u mentioned i can build the code from string... in the content of tat string i want one such statement which i mentioned in my query above........ do u know how to do tat?????? Thanks, ramesh
-
ya .... tats wat i meant Giorgi.... as u mentioned i can build the code from string... in the content of tat string i want one such statement which i mentioned in my query above........ do u know how to do tat?????? Thanks, ramesh
So it means that you need help in string manipulation? You need string which says private const string NAME = "CSharp"; ? I guess your problem is having " inside you string isn't it?
#region signature my articles #endregion
-
So it means that you need help in string manipulation? You need string which says private const string NAME = "CSharp"; ? I guess your problem is having " inside you string isn't it?
#region signature my articles #endregion
No Giorgi.... m speakin of using CodeDOM to do tat... However, i would also like to know the solution for the problem you mentioned above.... i mean how do i have " inside my string usually in string manipulation???
-
No Giorgi.... m speakin of using CodeDOM to do tat... However, i would also like to know the solution for the problem you mentioned above.... i mean how do i have " inside my string usually in string manipulation???
So you want to generate string content using CodeDOM? I'm not aware how to that but why would you want it? Why can't you just build your source from strings?
#region signature my articles #endregion
-
So you want to generate string content using CodeDOM? I'm not aware how to that but why would you want it? Why can't you just build your source from strings?
#region signature my articles #endregion
Well..... :-) i started with CodeDOM.... Actually i am creating a whole C# file which has a namespace.... a class.... its member fields.... methods..... properties.... i have been able to do a major part.... the places where i had issues.... are the ones i have posted.... :-) so i need a solution to tat using "MemberField" class in CodeDOM... hey Giorgi...... u din tell me how to do tat string manipulation stuff.... i mean if a wanna have " in my string... then how do i do tat???? -- modified at 7:51 Tuesday 21st August, 2007
-
Well..... :-) i started with CodeDOM.... Actually i am creating a whole C# file which has a namespace.... a class.... its member fields.... methods..... properties.... i have been able to do a major part.... the places where i had issues.... are the ones i have posted.... :-) so i need a solution to tat using "MemberField" class in CodeDOM... hey Giorgi...... u din tell me how to do tat string manipulation stuff.... i mean if a wanna have " in my string... then how do i do tat???? -- modified at 7:51 Tuesday 21st August, 2007
rameshbhojan wrote:
i mean if a wanna have " in my string... then how do i do tat????
Search for escape characters. As for your first question, will your code be changing during runtime or do you have some static piece of code you want to compile during runtime?
#region signature my articles #endregion
-
Hi All, I have used CodeDOM in .net to auto-generate C# code, which in essence generates a class file having a class along with its member fields, methods and properties. However, i don know how to generate the following line of code: private const string NAME = "CSharp"; Here, i have a generate a CodeMemberField which is a constant string with a private specifier as shown above. Please send me the sample code which would help me to auto-generate the above line of code. Thanks, Ramesh
CodeMemberField field = new CodeMemberField("System.String", "NAME");
field.InitExpression = new CodePrimitiveExpression("CSharp");
field.Attributes = MemberAttributes.Const | MemberAttributes.Private;
field.Type = new CodeTypeReference("System.String"); -
CodeMemberField field = new CodeMemberField("System.String", "NAME");
field.InitExpression = new CodePrimitiveExpression("CSharp");
field.Attributes = MemberAttributes.Const | MemberAttributes.Private;
field.Type = new CodeTypeReference("System.String");Thanks Dave for both of your answers :-) its all fine now........ hey Dave do you know how to creat regions using CodeDOM and i have one more issue..... all the statements inside a method or a constructor are aligned to the extreme left...... i want it to be properly indented. for example: public Data(string name, string age, string city) { this.m_name=name; this.m_age=age; this.m_city=city; } this i wat i am getting instead of getting a well indented code like: public Data(string name, string age, string city) { this.m_name=name; this.m_age=age; this.m_city=city; } How do i get it indented....
-
Thanks Dave for both of your answers :-) its all fine now........ hey Dave do you know how to creat regions using CodeDOM and i have one more issue..... all the statements inside a method or a constructor are aligned to the extreme left...... i want it to be properly indented. for example: public Data(string name, string age, string city) { this.m_name=name; this.m_age=age; this.m_city=city; } this i wat i am getting instead of getting a well indented code like: public Data(string name, string age, string city) { this.m_name=name; this.m_age=age; this.m_city=city; } How do i get it indented....
Sorry Dave, i don know how to add a section of code here.... both my indented version and non-indented version look the same above!!!!:-( Sorry..... but i hope u got wat i wanted to say....... i want the statement inside the method to be indented to one more tab towards right
-
rameshbhojan wrote:
i mean if a wanna have " in my string... then how do i do tat????
Search for escape characters. As for your first question, will your code be changing during runtime or do you have some static piece of code you want to compile during runtime?
#region signature my articles #endregion
The Code will change Giorgi During Runtime...... :-) its not static..... anyways i ve got my answer from Dave........ u can check the same...... Thanks, ramesh
-
Sorry Dave, i don know how to add a section of code here.... both my indented version and non-indented version look the same above!!!!:-( Sorry..... but i hope u got wat i wanted to say....... i want the statement inside the method to be indented to one more tab towards right
You can specify a different indent string inside CodeGenerationOptions. But there isn't much else you can do, you might be better off just formating the document in visual studio afterwards.
CodeGeneratorOptions options = new System.CodeDom.Compiler.CodeGeneratorOptions();
options.IndentString = "\t";
cs.GenerateCodeFromMember(prop, w, options); -
You can specify a different indent string inside CodeGenerationOptions. But there isn't much else you can do, you might be better off just formating the document in visual studio afterwards.
CodeGeneratorOptions options = new System.CodeDom.Compiler.CodeGeneratorOptions();
options.IndentString = "\t";
cs.GenerateCodeFromMember(prop, w, options);and wat bout getting the #region and #endregion Dave????