如何通过codedom生成“动态”成员?

时间:2011-04-07 07:05:09

标签: c# dynamic field member codedom

我想通过codedom生成这样的代码,就像这样

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

我想使用CodeMemberField的编码来声明“mDynamicObject”,但动态的类型我不知道如何声明这种类型。

1 个答案:

答案 0 :(得分:1)

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