本文整理汇总了C#中CodeClass.AddFunction方法的典型用法代码示例。如果您正苦于以下问题:C# CodeClass.AddFunction方法的具体用法?C# CodeClass.AddFunction怎么用?C# CodeClass.AddFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeClass
的用法示例。
在下文中一共展示了CodeClass.AddFunction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddMethodToClass
private void AddMethodToClass(CodeClass serviceClass, string name, bool async)
{
string parameter = string.Format("{0}Input", _serviceName + name);
var returnName = string.Format(async ? "Task<{0}Output>" : "{0}Output", _serviceName + name);
var function = serviceClass.AddFunction(name, vsCMFunction.vsCMFunctionFunction, returnName, -1, vsCMAccess.vsCMAccessPublic);
function.AddParameter("input", parameter);
if (async)
{
function.StartPoint.CreateEditPoint().ReplaceText(6, "public async", (int) vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
}
function.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint().ReplaceText(0, "throw new System.NotImplementedException();", (int) vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
}
示例2: GenerateTest
public override CodeFunction GenerateTest(CodeClass unitTestCodeClass, CodeProperty originalClassCodeProperty)
{
vsCMFunction functionKind = vsCMFunction.vsCMFunctionFunction;
object functionType = null;
functionKind = vsCMFunction.vsCMFunctionSub;
functionType = vsCMTypeRef.vsCMTypeRefVoid;
string nextAvailableName = originalClassCodeProperty.Name;
if (!CodeSelectionHandler.CanGenerateHandleCodeFunction(unitTestCodeClass,
nextAvailableName))
{
nextAvailableName = GetNextAvailableCopyName(unitTestCodeClass, ref nextAvailableName, unitTestCodeClass.ProjectItem.ContainingProject);
}
CodeFunction unitTestCodeFunction = unitTestCodeClass.AddFunction(
nextAvailableName,
functionKind,
functionType,
-1,
originalClassCodeProperty.Access,
-1);
unitTestCodeFunction.AddAttribute("NUnit.Framework.Test", "", -1);
try
{
unitTestCodeFunction.Comment = originalClassCodeProperty.Comment;
unitTestCodeFunction.DocComment = originalClassCodeProperty.DocComment;
}
catch (Exception ex)
{
Logger.LogException(ex);
//ignore
}
TextPoint bodyStartingPoint =
unitTestCodeFunction.GetStartPoint(vsCMPart.vsCMPartBody);
EditPoint boydEditPoint = bodyStartingPoint.CreateEditPoint();
//Stop here if not read-write type property now...
if (originalClassCodeProperty.Setter == null)
{
boydEditPoint = bodyStartingPoint.CreateEditPoint();
boydEditPoint.Insert(StringHelper.GetTabString() + "' Property is not read-write please add your own code here." + Environment.NewLine);
return unitTestCodeFunction;
}
string tvFunctionCallTemplate = string.Empty; // "iv{0}Type.{1} = default({2});";
tvFunctionCallTemplate = "iv{0}Type.{1} = New {2}()" + Environment.NewLine;
string tvFunctionCall = tvFunctionCallTemplate;
CodeTypeRef tvPropertyType = originalClassCodeProperty.Type;
string tvPropertyTypeAsString = tvPropertyType.AsString;
tvFunctionCall = string.Format(tvFunctionCall, ((CodeClass)originalClassCodeProperty.Parent).Name, originalClassCodeProperty.Name, tvPropertyTypeAsString);
bodyStartingPoint = unitTestCodeFunction.GetStartPoint(vsCMPart.vsCMPartBody);
boydEditPoint = bodyStartingPoint.CreateEditPoint();
//FIX ME (tabing)
boydEditPoint.Insert(StringHelper.GetTabString() + tvFunctionCall + Environment.NewLine);
//FIX ME (tabbing)
string tvTempString = string.Empty; // "iv{0}Type.{1}, default({2})";
tvTempString = "iv{0}Type.{1}, New {2}()";
tvTempString = string.Format(tvTempString, ((CodeClass)originalClassCodeProperty.Parent).Name, originalClassCodeProperty.Name, tvPropertyTypeAsString);
boydEditPoint.Insert(Environment.NewLine);
boydEditPoint.Insert("\t\t\t'TODO: Update Assert to meet test needs" + Environment.NewLine);
boydEditPoint.Insert("\t\t\t'Assert.AreEqual(" + tvTempString + ")" + Environment.NewLine);
boydEditPoint.Insert("\t\t\t" + Environment.NewLine);
boydEditPoint.Insert("\t\t\tThrow New Exception 'Not Implemented'" + Environment.NewLine);
return unitTestCodeFunction;
}
示例3: CloneFunction
/// <summary>
/// 克隆一个方法
/// </summary>
/// <param name="cloneFunction">要克隆的方法</param>
/// <param name="codeClass">添加到类中</param>
private void CloneFunction(CodeFunction cloneFunction, CodeClass codeClass)
{
CodeFunction codeFunction = codeClass.AddFunction(cloneFunction.Name, cloneFunction.FunctionKind,
cloneFunction.Type, -1, cloneFunction.Access, null);
//添加参数
for (int i = 1; i <= cloneFunction.Parameters.Count; i++)
{
CodeParameter2 parameter = cloneFunction.Parameters.Item(i) as CodeParameter2;
CodeParameter2 cloneParameter = codeFunction.AddParameter(parameter.FullName, parameter.Type.AsFullName, i) as CodeParameter2;
cloneParameter.DefaultValue = parameter.DefaultValue;
cloneParameter.ParameterKind = parameter.ParameterKind;
}
//添加属性
for (int i = 1; i <= cloneFunction.Attributes.Count; i++)
{
CodeAttribute attribute = cloneFunction.Attributes.Item(i) as CodeAttribute;
codeFunction.AddAttribute(attribute.Name, attribute.Value, i);
}
//方法注释
codeFunction.Comment = cloneFunction.Comment;
//方法说明
codeFunction.DocComment = cloneFunction.DocComment;
//静态修饰
codeFunction.IsShared = cloneFunction.IsShared;
//抽象修饰
codeFunction.MustImplement = cloneFunction.MustImplement;
//重载修饰
codeFunction.CanOverride = cloneFunction.CanOverride;
}