Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public void AddConstructor()
        {
            Con = this.VarValue;
            // Declare the constructor
            CodeConstructor constructor = new CodeConstructor();
            constructor.Attributes = MemberAttributes.Public;
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(Type, Con));
            
            CodeFieldReferenceExpression widthReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), Con);

            constructor.Statements.Add(new CodeAssignStatement(widthReference, new CodeArgumentReferenceExpression(Con)));
            
            targetClass.Members.Add(constructor);
        }


Output of this code is

C#
public MyCode(String val)
        {
            this.val = val;
        }


i want only non parameterized Constructor
like this

C#
public MyCode()
        {
            val = "Value";
        }


i tried but didn't get.... plese give me any simple clue to generate c# source code file At runtime using c#...
Posted

1 solution

 
Share this answer
 
v2
Comments
Anjanee Kumar Singh 4-Jun-13 2:01am    
and any solution of my abouve problem sir...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900