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


C# ConstructorDeclarationSyntax.IsStatic方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax.IsStatic方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructorDeclarationSyntax.IsStatic方法的具体用法?C# ConstructorDeclarationSyntax.IsStatic怎么用?C# ConstructorDeclarationSyntax.IsStatic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax的用法示例。


在下文中一共展示了ConstructorDeclarationSyntax.IsStatic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtendExistingConstructor

        /// <summary>
        /// if the child class already has a constructor, 
        /// a new parameter will be added to the constructor
        /// </summary>
        /// <param name="oldConstructor">constructor to which
        /// we are going to add the new parameter</param>
        /// <returns>the constructor with the additional new parameter</returns>
        public ConstructorDeclarationSyntax ExtendExistingConstructor(
            ConstructorDeclarationSyntax oldConstructor)
        {
            if (oldConstructor.IsStatic())
                return oldConstructor;

            var parameterName = _mixin.Name.ConvertFieldNameToParameterName();
            // if there is already a parameter with the same name, skip further processing
            var alreadyHasParameter = oldConstructor.ParameterList.Parameters.Any(x => x.Identifier.Text == parameterName);
            if (alreadyHasParameter)
                return oldConstructor;

            // first rule: extend the constructors parameter list
            var parameter = CreateConstructorParameterForMixin(parameterName);
            var newConstructor = oldConstructor.AddParameterListParameters(parameter);
            // second rule: check for initializer
            // if we have no initializer or a base initializer, do the assignment in this constructor
            // but do not delegate the parameter to further constructors
            var initializer = oldConstructor.Initializer;
            if(initializer == null || initializer.IsKind(SyntaxKind.BaseConstructorInitializer))
            {
                newConstructor = newConstructor
                    .AddBodyStatements(CreateAssigmentStatementForConstructorBody(parameterName));
            }
            return newConstructor;
        }  
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:33,代码来源:InjectConstructorImplementationStrategy.cs

示例2: VisitConstructorDeclaration

 public override SyntaxNode VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
 {
     node = (ConstructorDeclarationSyntax)base.VisitConstructorDeclaration(node);
     if(!node.IsStatic())  // ignore static constructors
         node = _injectMixinIntoConstructor.ExtendExistingConstructor(node);
     // remember that class already has a constructor,
     // so no need to create a new one
     _SourceClassHasConstructor = true;
     return node;
 }
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:10,代码来源:ConstructorInjectionSyntaxWriter.cs

示例3: VisitConstructorDeclaration

        public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
        {
            // ignore static constructors
            if (node.IsStatic())
                return;

            var constructor = new Constructor();
            // read parameters
            var parameterSyntaxReader = new ParameterSyntaxReader(constructor, _semantic);
            parameterSyntaxReader.Visit(node);
            _constructors.AddConstructor(constructor);
            base.VisitConstructorDeclaration(node);
        }
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:13,代码来源:ConstructorSyntaxReader.cs


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