本文整理汇总了C#中CodeClass类的典型用法代码示例。如果您正苦于以下问题:C#CodeClass类的具体用法?C#CodeClass怎么用?C#CodeClass使用的例子?这里精选的类代码示例或许可以为您提供帮助。
示例1:AddProperty
///
///Addstheproperty.
///
///
Thecodeclass.
///Thevar.
///
publicstaticCodePropertyAddProperty(CodeClasscodeClass,CodeVariablevar)
{
CodePropertyprop=null;
try
{
prop=codeClass.AddProperty(
FormatPropertyName(var.Name),
FormatPropertyName(var.Name),
var.Type.AsFullName,-1,
vsCMAccess.vsCMAccessPublic,null);
EditPointeditPoint=prop.Getter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();
//Deletereturndefault(int);addedbycodeClass.AddProperty
editPoint.Delete(editPoint.LineLength);
editPoint.Indent(null,4);
editPoint.Insert(string.Format(CultureInfo.InvariantCulture,"return{0};",var.Name));
editPoint=prop.Setter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();
editPoint.Indent(null,1);
editPoint.Insert(string.Format(CultureInfo.InvariantCulture,"{0}=value;",var.Name));
editPoint.SmartFormat(editPoint);
returnprop;
}
catch
{
//Propertyalreadyexists
returnnull;
}
}
原文链接:http://www.jxszl.com/biancheng/C/556795.html