本文整理匯總了C#中CodeClass.AddProperty方法的典型用法代碼示例。如果您正苦於以下問題:C# CodeClass.AddProperty方法的具體用法?C# CodeClass.AddProperty怎麽用?C# CodeClass.AddProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CodeClass
的用法示例。
在下文中一共展示了CodeClass.AddProperty方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AddProperty
/// <summary>
/// Adds the property.
/// </summary>
/// <param name="codeClass">The code class.</param>
/// <param name="var">The var.</param>
/// <returns></returns>
public static CodeProperty AddProperty(CodeClass codeClass, CodeVariable var)
{
CodeProperty prop = null;
try
{
prop = codeClass.AddProperty(
FormatPropertyName(var.Name),
FormatPropertyName(var.Name),
var.Type.AsFullName, -1,
vsCMAccess.vsCMAccessPublic, null);
EditPoint editPoint = prop.Getter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();
//Delete return default(int); added by codeClass.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);
return prop;
}
catch
{
//Property already exists
return null;
}
}