2011-04-07 53 views
1

我想通過生成的CodeDOM這樣的代碼,這樣如何通過codedom生成'動態'成員?

public class Class1 
{ 
    private dynamic mDynamicObject; 
    public dynamic DynamicObject 
    { 
     get { return mDynamicObject; } 
     set { mDynamicObject = value; } 
    } 
} 

,我想用CodeMemberField的CodeDOM的申報「mDynamicObject」的,而是動態的類型,我不知道如何聲明此類型。

回答

1
CodeMemberField dynamicMember = new CodeMemberField (); 
dynamicMember.Name = dynamicMemberName; 
dynamicMember.Attributes = MemberAttributes.Private; 
dynamicMember.Type = new CodeTypeReference ("dynamic"); 
operationCodeType.Members.Add (dynamicMember);