本文整理汇总了C#中ConstructorInitializerSyntax类的典型用法代码示例。如果您正苦于以下问题:C# ConstructorInitializerSyntax类的具体用法?C# ConstructorInitializerSyntax怎么用?C# ConstructorInitializerSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorInitializerSyntax类属于命名空间,在下文中一共展示了ConstructorInitializerSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(")");
}
示例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;
}
示例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));
示例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);
示例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);
}
示例6: ConstructorInitializerTranslation
public ConstructorInitializerTranslation(ConstructorInitializerSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
ThisOrBaseKeyword = syntax.ThisOrBaseKeyword.Get(this);
ArgumentList = syntax.ArgumentList.Get<ArgumentListTranslation>(this);
}
示例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);
}
示例8: VisitConstructorInitializer
/// <summary>
///
/// </summary>
/// <param name="node"></param>
public override sealed void VisitConstructorInitializer(ConstructorInitializerSyntax node)
{
this.OnNodeVisited(node);
if (!this.traverseRootOnly) base.VisitConstructorInitializer(node);
}
示例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();
}
示例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);
}
}
示例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);
}
示例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();
}
示例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);
}
示例15: IsArgumentListToken
private static bool IsArgumentListToken(ConstructorInitializerSyntax expression, SyntaxToken token)
{
return expression.ArgumentList != null &&
expression.ArgumentList.Span.Contains(token.SpanStart) &&
token != expression.ArgumentList.CloseParenToken;
}