Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using CodeDOM in .NET to AutoGenereate a constant member field

Using CodeDOM in .NET to AutoGenereate a constant member field

Scheduled Pinned Locked Moved C#
csharphelptutorial
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Giorgi Dalakishvili

    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

    R Offline
    R Offline
    rameshbhojan
    wrote on last edited by
    #5

    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???

    G 1 Reply Last reply
    0
    • R rameshbhojan

      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???

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #6

      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

      R 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        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

        R Offline
        R Offline
        rameshbhojan
        wrote on last edited by
        #7

        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

        G 1 Reply Last reply
        0
        • R rameshbhojan

          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

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #8

          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

          R 1 Reply Last reply
          0
          • R rameshbhojan

            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

            I Offline
            I Offline
            Insincere Dave
            wrote on last edited by
            #9

            CodeMemberField field = new CodeMemberField("System.String", "NAME");
            field.InitExpression = new CodePrimitiveExpression("CSharp");
            field.Attributes = MemberAttributes.Const | MemberAttributes.Private;
            field.Type = new CodeTypeReference("System.String");

            R 1 Reply Last reply
            0
            • I Insincere Dave

              CodeMemberField field = new CodeMemberField("System.String", "NAME");
              field.InitExpression = new CodePrimitiveExpression("CSharp");
              field.Attributes = MemberAttributes.Const | MemberAttributes.Private;
              field.Type = new CodeTypeReference("System.String");

              R Offline
              R Offline
              rameshbhojan
              wrote on last edited by
              #10

              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....

              R 1 Reply Last reply
              0
              • R rameshbhojan

                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....

                R Offline
                R Offline
                rameshbhojan
                wrote on last edited by
                #11

                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

                I 1 Reply Last reply
                0
                • G Giorgi Dalakishvili

                  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

                  R Offline
                  R Offline
                  rameshbhojan
                  wrote on last edited by
                  #12

                  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

                  1 Reply Last reply
                  0
                  • R rameshbhojan

                    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

                    I Offline
                    I Offline
                    Insincere Dave
                    wrote on last edited by
                    #13

                    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);

                    R 1 Reply Last reply
                    0
                    • I Insincere Dave

                      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);

                      R Offline
                      R Offline
                      rameshbhojan
                      wrote on last edited by
                      #14

                      and wat bout getting the #region and #endregion Dave????

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups