• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ConstructorInitializerSyntax类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ConstructorInitializerSyntax的典型用法代码示例。如果您正苦于以下问题:C# ConstructorInitializerSyntax类的具体用法?C# ConstructorInitializerSyntax怎么用?C# ConstructorInitializerSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConstructorInitializerSyntax类属于命名空间,在下文中一共展示了ConstructorInitializerSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Go

        public static void Go(OutputWriter writer, ConstructorInitializerSyntax method)
        {
            writer.WriteIndent();
            //    var symbl = TypeProcessor.GetSymbolInfo(method);
            //	var mysymbl = TypeProcessor.GetSymbolInfo(method.Parent);

            //   var className = symbl.Symbol.ContainingType;
            if (method.ThisOrBaseKeyword.RawKind == (int) SyntaxKind.ThisKeyword)
                writer.Write("this");
            else
                writer.Write("super");
//                writer.Write(TypeProcessor.ConvertType(className));

            writer.Write("(");
            bool first = true;
            foreach (var expression in method.ArgumentList.Arguments)
            {
                if (first)
                    first = false;
                else
                    writer.Write(", ");

                Core.Write(writer, expression.Expression);
            }
            writer.Write(")");
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:26,代码来源:WriteConstructorInitializer.cs


示例2: TryGetConstructorInitializer

        private bool TryGetConstructorInitializer(SyntaxNode root, int position, ISyntaxFactsService syntaxFacts, SignatureHelpTriggerReason triggerReason, CancellationToken cancellationToken, out ConstructorInitializerSyntax expression)
        {
            if (!CommonSignatureHelpUtilities.TryGetSyntax(root, position, syntaxFacts, triggerReason, IsTriggerToken, IsArgumentListToken, cancellationToken, out expression))
            {
                return false;
            }

            return expression.ArgumentList != null;
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:9,代码来源:ConstructorInitializerSignatureHelpProvider.cs


示例3: ConstructorDeclaration

 public static ConstructorDeclarationSyntax ConstructorDeclaration(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     SyntaxToken identifier,
     ParameterListSyntax parameterList,
     ConstructorInitializerSyntax initializer,
     ArrowExpressionClauseSyntax expressionBody)
     => ConstructorDeclaration(
         attributeLists,
         modifiers,
         identifier,
         parameterList,
         initializer,
         default(BlockSyntax),
         expressionBody,
         default(SyntaxToken));
开发者ID:XieShuquan,项目名称:roslyn,代码行数:16,代码来源:ConstructorDeclarationSyntax.cs


示例4: Update

 public ConstructorDeclarationSyntax Update(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers, 
     SyntaxToken identifier,
     ParameterListSyntax parameterList, 
     ConstructorInitializerSyntax initializer, 
     BlockSyntax body, 
     SyntaxToken semicolonToken)
     => Update(
         attributeLists, 
         modifiers, 
         identifier, 
         parameterList, 
         initializer, 
         body, 
         default(ArrowExpressionClauseSyntax), 
         semicolonToken);
开发者ID:XieShuquan,项目名称:roslyn,代码行数:17,代码来源:ConstructorDeclarationSyntax.cs


示例5: PropagateConstructorParams

        private async Task<Document> PropagateConstructorParams(
            Document document, 
            ConstructorInitializerSyntax constructorInitializerNode, 
            ImmutableArray<IParameterSymbol> baseConstrParams, 
            CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync();
            var classDecl = constructorInitializerNode.FirstAncestorOrSelf<ClassDeclarationSyntax>();
            var classSymbol = semanticModel.GetDeclaredSymbol(classDecl);
            var constructorDecl = constructorInitializerNode.FirstAncestorOrSelf<ConstructorDeclarationSyntax>();

            var constructorSymbol = classSymbol.Constructors
                .Where(p => p.Parameters.Count() == constructorDecl.ParameterList.Parameters.Count)
                .FirstOrDefault();

            var invArgList = constructorInitializerNode.ArgumentList;
            var declParamList = constructorDecl.ParameterList;

            int idx = -1;
            foreach(var baseP in baseConstrParams)
            {
                idx++;

                if (constructorSymbol.Parameters.Any(p => p.Type.Name == baseP.Type.Name))
                    continue;

                declParamList = declParamList.AddParameters(
                    SyntaxFactory.Parameter(
                        SyntaxFactory.Identifier(baseP.Name))
                    .WithType(
                        SyntaxFactory.IdentifierName(baseP.Type.Name)));

                invArgList = SyntaxFactory.ArgumentList(invArgList.Arguments.Insert(idx, SyntaxFactory.Argument(SyntaxFactory.IdentifierName(baseP.Name))));
            }

            var root = await document.GetSyntaxRootAsync();

            var newConstructor = constructorDecl.WithParameterList(declParamList)
                .WithInitializer(constructorInitializerNode.WithArgumentList(invArgList));

            root = root.ReplaceNode(constructorDecl, newConstructor);


            return document.WithSyntaxRoot(root);
        }
开发者ID:yohney,项目名称:common-refactorings-plugin,代码行数:45,代码来源:PropagateConstructorParamCodeFix.cs


示例6: ConstructorInitializerTranslation

        public ConstructorInitializerTranslation(ConstructorInitializerSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
        {

            ThisOrBaseKeyword = syntax.ThisOrBaseKeyword.Get(this);
            ArgumentList = syntax.ArgumentList.Get<ArgumentListTranslation>(this);
        }
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:6,代码来源:ConstructorInitializerTranslation.cs


示例7: InferTypeInConstructorInitializer

 private IEnumerable<ITypeSymbol> InferTypeInConstructorInitializer(ConstructorInitializerSyntax initializer, int index, ArgumentSyntax argument = null)
 {
     var info = this.semanticModel.GetSymbolInfo(initializer, cancellationToken);
     var methods = info.GetBestOrAllSymbols().OfType<IMethodSymbol>();
     return InferTypeInArgument(index, methods, argument);
 }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:6,代码来源:CSharpTypeInferenceService.TypeInferrer.cs


示例8: VisitConstructorInitializer

 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitConstructorInitializer(ConstructorInitializerSyntax node)
 {
     this.OnNodeVisited(node);
     if (!this.traverseRootOnly) base.VisitConstructorInitializer(node);
 }
开发者ID:andry-tino,项目名称:Rosetta,代码行数:9,代码来源:MultiPurposeASTWalker.cs


示例9: RegisterActionForBaseCall

        private static void RegisterActionForBaseCall(CodeFixContext context, SyntaxNode root, ConstructorInitializerSyntax initializer)
        {
            var constructor = initializer.Parent as ConstructorDeclarationSyntax;
            if (constructor == null)
            {
                return;
            }

            context.RegisterCodeFix(
                CodeAction.Create(
                    TitleRemoveBaseCall,
                    c =>
                    {
                        var newRoot = RemoveInitializer(root, constructor);
                        return Task.FromResult(context.Document.WithSyntaxRoot(newRoot));
                    },
                    TitleRemoveBaseCall),
                context.Diagnostics);
        }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:19,代码来源:RedundancyInConstructorDestructorDeclarationCodeFixProvider.cs


示例10: IsInitializerRedundant

 private static bool IsInitializerRedundant(ConstructorInitializerSyntax initializer)
 {
     return initializer.IsKind(SyntaxKind.BaseConstructorInitializer) &&
         initializer.ArgumentList != null &&
         !initializer.ArgumentList.Arguments.Any();
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:6,代码来源:RedundancyInConstructorDestructorDeclaration.cs


示例11: VisitConstructorInitializer

            public override void VisitConstructorInitializer(ConstructorInitializerSyntax node)
            {
                base.VisitConstructorInitializer(node);

                var method = context.SemanticModel.GetSymbolInfo(node).Symbol as IMethodSymbol;
                if (method != null)
                {
                    CheckArguments(node.ArgumentList.Arguments, method.Parameters);
                }
            }
开发者ID:uxsoft,项目名称:nullaby,代码行数:10,代码来源:NullAnalyzer.cs


示例12: IsInitializerEmptyOrRedundant

        private static bool IsInitializerEmptyOrRedundant(ConstructorInitializerSyntax initializer)
        {
            if (initializer == null)
            {
                return true;
            }

            return initializer.ArgumentList != null &&
                !initializer.ArgumentList.Arguments.Any() &&
                initializer.ThisOrBaseKeyword.IsKind(SyntaxKind.BaseKeyword);
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:11,代码来源:RedundancyInConstructorDestructorDeclaration.cs


示例13: VisitConstructorInitializer

        public void VisitConstructorInitializer(ConstructorInitializerSyntax node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.Validate();

            if (_writer.Configuration.LineBreaksAndWrapping.Other.PlaceConstructorInitializerOnSameLine)
            {
                _writer.WriteSpace();
            }
            else
            {

                _writer.WriteLine();

                _writer.PushIndent();
                _writer.WriteIndent();
            }

            _writer.WriteSyntax(Syntax.Colon);
            _writer.WriteSpace();
            _writer.WriteKeyword(node.Kind == ThisOrBase.This ? PrinterKeyword.This : PrinterKeyword.Base);
            node.ArgumentList.Accept(this);

            if (!_writer.Configuration.LineBreaksAndWrapping.Other.PlaceConstructorInitializerOnSameLine)
                _writer.PopIndent();
        }
开发者ID:modulexcite,项目名称:CSharpSyntax,代码行数:28,代码来源:SyntaxPrinter.cs


示例14: VisitConstructorInitializer

 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitConstructorInitializer(ConstructorInitializerSyntax node)
 {
     this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
     base.VisitConstructorInitializer(node);
 }
开发者ID:andry-tino,项目名称:Rosetta,代码行数:9,代码来源:ASTWalkerNodeTypeOperationExecutor.cs


示例15: IsArgumentListToken

 private static bool IsArgumentListToken(ConstructorInitializerSyntax expression, SyntaxToken token)
 {
     return expression.ArgumentList != null &&
         expression.ArgumentList.Span.Contains(token.SpanStart) &&
         token != expression.ArgumentList.CloseParenToken;
 }
开发者ID:RoryVL,项目名称:roslyn,代码行数:6,代码来源:ConstructorInitializerSignatureHelpProvider.cs


示例16: Create

 /// <summary>
 /// Creates a SemanticModel for a constructor initializer (": this(...)" or ": base(...)").
 /// </summary>
 internal static InitializerSemanticModel Create(CSharpCompilation compilation, ConstructorInitializerSyntax syntax, MethodSymbol methodSymbol, Binder rootBinder)
 {
     return new InitializerSemanticModel(compilation, syntax, methodSymbol, rootBinder);
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:InitializerSemanticModel.cs


示例17: ExtendConstructorInitialization

        /// <summary>
        /// the constructor initializer will be extended
        /// so that it will accept the mixin as parameter.
        /// See rule 3 from above
        /// </summary>
        /// <param name="oldConstructorInitializer"></param>
        /// <returns></returns>
        public ConstructorInitializerSyntax ExtendConstructorInitialization(
            ConstructorInitializerSyntax oldConstructorInitializer)
        {
            // don't do anything if initializer points to base
            if (oldConstructorInitializer.IsKind(SyntaxKind.BaseConstructorInitializer))
                return oldConstructorInitializer;
            var parameterName = _mixin.Name.ConvertFieldNameToParameterName();

            // arguments that are already used in the constructor initializer
            var arguments = oldConstructorInitializer
                .ArgumentList
                .Arguments
                .ToArray();

            // the initializer can have default parameters that are not visible in the syntax tree,
            // therefore we have to use some additional semantic information here
            var initalizerSymbol = _semantic.GetSymbolInfo(oldConstructorInitializer).Symbol as IMethodSymbol;
            if (initalizerSymbol != null)
            {
                var constructorArguments = new List<ConstructorArgument>();

                // special case: the initializer does not have any parameters yet
                // so we simply add one
                if(initalizerSymbol.Parameters.Length == 0)
                {
                    return oldConstructorInitializer
                        .AddArgumentListArguments(
                            Argument(IdentifierName(parameterName)));
                }

                // otherwise, try to map the arguments from the initializer
                // with the parameters of the constructor and add the new argument
                // at the correct position
                for (var i=0; i < initalizerSymbol.Parameters.Length;i++)
                {
                    var parameter = initalizerSymbol.Parameters[i];
                    // this constructor argument will hold our new mixin
                    if (parameter.Name == parameterName)
                    {
                        constructorArguments.Add(
                            new ConstructorArgument(
                                parameter.Name,
                                expression: IdentifierName(parameterName),
                                isMixinParameter: true));
                    }
                    else
                    {
                        // we either have an argument with an explicit name
                        // or we have an argument at the same position
                        // or we can ommit this parameter
                        ArgumentSyntax argument = arguments
                            .Where(x => x.NameColon != null)
                            .FirstOrDefault(x => x.NameColon.Name.GetText().ToString() == parameter.Name);
                        // argument identified by name or by position
                        if (argument == null)
                            if (arguments.Length > i)
                                argument = arguments[i];
                        if (argument != null)
                            constructorArguments.Add(new ConstructorArgument(parameter.Name,expression: argument.Expression));
                        else // no argument found => argument was omitted
                            constructorArguments.Add(new ConstructorArgument(parameter.Name,canBeOmitted:true));
                    }
                }

                // now we have to check again if we must use explicit naming
                // this is the case if a previous parameter is omitted but
                // the current one is not
                ConstructorArgument previous = null;
                foreach (var constructorArgument in constructorArguments)
                {
                    constructorArgument.NeedsExplicitNaming =
                        previous != null &&
                        previous.CanBeOmitted &&
                        !constructorArgument.CanBeOmitted;
                    previous = constructorArgument;
                }                    

                // create the new initializer by recreating the complete argument list
                var newConstructorInitializer = oldConstructorInitializer
                    .WithArgumentList(ArgumentList()
                    .AddArguments(constructorArguments
                        .Where(x => x.Expression != null)
                        .Select(x => x.NeedsExplicitNaming ? 
                            Argument(NameColon(x.Name), default(SyntaxToken),x.Expression) : 
                            Argument(x.Expression))                           
                        .ToArray()));
                return newConstructorInitializer;
            }

            return oldConstructorInitializer;
        } 
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:98,代码来源:InjectConstructorImplementationStrategy.cs


示例18: TryGetSpeculativeSemanticModelCore

        internal sealed override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ConstructorInitializerSyntax constructorInitializer, out SemanticModel speculativeModel)
        {
            position = CheckAndAdjustPosition(position);

            var model = this.GetMemberModel(position);
            if (model != null)
            {
                return model.TryGetSpeculativeSemanticModelCore(parentModel, position, constructorInitializer, out speculativeModel);
            }

            speculativeModel = null;
            return false;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:13,代码来源:SyntaxTreeSemanticModel.cs


示例19: TryGetSpeculativeSemanticModelCore

 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ConstructorInitializerSyntax constructorInitializer, out SemanticModel speculativeModel)
 {
     throw ExceptionUtilities.Unreachable;
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:4,代码来源:MemberSemanticModel.SpeculativeMemberSemanticModel.cs


示例20: TryGetSpeculativeSemanticModelCore

 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ConstructorInitializerSyntax constructorInitializer, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return false;
 }
开发者ID:riversky,项目名称:roslyn,代码行数:5,代码来源:MethodBodySemanticModel.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ConsulClient类代码示例发布时间:2022-05-24
下一篇:
C# ConstructorInfo类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap