我想通过codedom生成这样的代码,就像这样
public class Class1
{
private dynamic mDynamicObject;
public dynamic DynamicObject
{
get { return mDynamicObject; }
set { mDynamicObject = value; }
}
}
我想使用CodeMemberField的编码来声明“mDynamicObject”,但动态的类型我不知道如何声明这种类型。
答案 0 :(得分:1)
CodeMemberField dynamicMember = new CodeMemberField ( );
dynamicMember.Name = dynamicMemberName;
dynamicMember.Attributes = MemberAttributes.Private;
dynamicMember.Type = new CodeTypeReference ( "dynamic" );
operationCodeType.Members.Add ( dynamicMember );