Blog Stats
  • Posts - 178
  • Articles - 0
  • Comments - 61
  • Trackbacks - 234

 

A Very Brief Overview of System.CodeDom #1

So, I am re-writing Gen.NET to use System.CodeDom to generate the classes representing the tables in the target database. CodeDom is not easy when you are going from 0 to anything. Here is what I have learned so far. I will post more when I learn more.

using System; ns.Imports("System");
namespace CodeDomSample CodeNamespace ns = new CodeNamespace("CodeDomSample");
{  
   
   /// aClass.Comments.Add(new CodeCommentStatement("");
   /// Summary description for Class1. aClass.Comments.Add(new CodeCommentStatement("Summary description for Class1");
   /// aClass.Comments.Add(new CodeCommentStatement(""));
   public class Sample1 CodeTypeDeclaration aClass = new CodeTypeDeclaration("Sample1");
ns.Types.Add(aClass);
   {  
      private string string1; CodeMemberField aField = new CodeMemberField("string", "string1");
aField.Attributes = MemberAttributes.Private;
aClass.Members.Add(aField);
   
      public Sample1(string astring)

CodeConstructor aClassConstructor = new CodeConstructor();
aClassConstructor.Attributes = MemberAttributes.Public
aClassConstructor.Parameters.Add(new CodeParameterDeclarationExpression(

   new CodeTypeReference("string"), "astring"));

aClass.Members.Add(aClassConstructor);

      {  
      }  
      public string String1

CodeMemberProperty p = new CodeMemberProperty();

p.Name = "String1";

p.Attributes = MemberAttributes.Public;

p.Type = new CodeTypeReference("string");

aClass.Members.Add(p);

      {  
         get p.HasGet = true;
         {  
            return string1;

p.GetStatements.Add(

new CodeMethodReturnStatement(

new CodeFieldReferenceExpression(

new CodeThisReferenceExpression(), "string1")));

         }  
      }  
   
      public void DeleteString()

CodeMemberMethod aMethod = new CodeMemberMethod();

aMethod.Name = "DeleteString";

aMethod.Attributes = MemberAttributes.Public;

aMethod.ReturnType = new CodeTypeReference("");

aClass.Members.Add(aMethod);

      {  
         string1 = "";

aMethod.Statements.Add(

new CodeMethodInvokeExpression(

new CodeSnippetExpression(

"System.Diagnostics.Debug"), "WriteLine",

new CodePropertyReferenceExpression(

new CodeThisReferenceExpression(), "Number")));

      }  
   }  
}  


Feedback

No comments posted yet.


Post a comment





 

Please add 1 and 7 and type the answer here:

 

 

Copyright © Jason Bentley