如何使用CodeDOM
;
public string Name
{
get
{
return name;
}
protected set
{
name = value;
}
}
我发现了一个重复的问题here但是,现在运行中的C#5.0和.NET framework 4.5。现在也不可能吗?
通过此代码;
//Declare a property in target class and set attributes of the property
CodeMemberProperty newPropertyGetter = new CodeMemberProperty();
newPropertyGetter.Attributes = (MemberAttributes)Enum.Parse(typeof(MemberAttributes), visibilityGetter) | MemberAttributes.Final;
newPropertyGetter.Name = propName;
newPropertyGetter.Type = new CodeTypeReference(propType);
newPropertyGetter.HasGet = needGet;
CodeMemberProperty newPropertySetter = new CodeMemberProperty();
newPropertySetter.Attributes = (MemberAttributes)Enum.Parse(typeof(MemberAttributes), visibilitySetter) | MemberAttributes.Final;
newPropertySetter.Name = propName;
newPropertySetter.Type = new CodeTypeReference(propType);
newPropertySetter.HasSet = needSet;
我可以这样;
public string Name
{
get
{
return name;
}
}
public string Name
{
protected set
{
name = value;
}
}
有效吗?或者这不是一个好习惯吗?