当前位置: 首页>>代码示例>>C#>>正文


C# CodeClass.AddFunction方法代码示例

本文整理汇总了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);
 }
开发者ID:chimeramvp,项目名称:ABPHelper,代码行数:12,代码来源:AddNewServiceMethodHelper.cs

示例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;
      }
开发者ID:codemonkies,项目名称:UTGV1.0,代码行数:86,代码来源:NUnitVBTestClass.cs

示例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;
        }
开发者ID:Nacro8,项目名称:xiaobier,代码行数:37,代码来源:DTEHelper.cs


注:本文中的CodeClass.AddFunction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。