本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# ConstructorDeclarationSyntax类的具体用法?C# ConstructorDeclarationSyntax怎么用?C# ConstructorDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ConstructorDeclarationSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OrdonnerAssignations
/// <summary>
/// Réordonne les assignations d'un constructeur.
/// </summary>
/// <param name="document">Le document.</param>
/// <param name="constructeur">Le constructeur.</param>
/// <param name="jetonAnnulation">Le jeton d'annulation.</param>
/// <returns>Le nouveau document.</returns>
private async Task<Document> OrdonnerAssignations(Document document, ConstructorDeclarationSyntax constructeur, CancellationToken jetonAnnulation)
{
// On récupère la racine et le modèle sémantique.
var racine = await document
.GetSyntaxRootAsync(jetonAnnulation)
.ConfigureAwait(false);
var modèleSémantique = await document.GetSemanticModelAsync(jetonAnnulation);
// On récupère le corps du constructeur.
var corps = constructeur.ChildNodes().First(nœud => nœud as BlockSyntax != null) as BlockSyntax;
// On récupère toutes les conditions sur les paramètres.
var conditions = Partagé.TrouveConditionsParametres(corps.Statements, constructeur.ParameterList, modèleSémantique);
// On récupère les assignations et on les ordonne.
var assignations = Partagé.TrouverAssignations(corps.Statements, modèleSémantique)
.OrderBy(e => e.ToString());
// On construit le nouveau corps du constructeur.
var corpsOrdonné = corps.WithStatements(
SyntaxFactory.List(
conditions
.Concat(assignations)
.Concat(corps.Statements
.Except(conditions)
.Except(assignations))));
// Et on met à jour la racine.
var nouvelleRacine = racine.ReplaceNode(corps, corpsOrdonné);
return document.WithSyntaxRoot(nouvelleRacine);
}
示例2: WithConstructorInitializerLocalsBinder
public WithConstructorInitializerLocalsBinder(Binder enclosing, ConstructorDeclarationSyntax declaration)
: base(enclosing, enclosing.Flags)
{
Debug.Assert(declaration.Initializer != null);
this.scope = declaration;
this.initializerArgumentList = declaration.Initializer.ArgumentList;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:WithConstructorInitializerLocalsBinder.cs
示例3: Create
public static ClassDeclarationSyntax Create(string name, BaseTypeSyntax[] baseTypes, ConstructorDeclarationSyntax constructor, MemberDeclarationSyntax[] body)
{
return SyntaxFactory.ClassDeclaration(name)
.AddBaseListTypes(baseTypes)
.AddMembers(constructor)
.AddMembers(body);
}
示例4: SourceConstructorSymbol
private SourceConstructorSymbol(
SourceMemberContainerTypeSymbol containingType,
Location location,
ConstructorDeclarationSyntax syntax,
MethodKind methodKind,
DiagnosticBag diagnostics) :
base(containingType, syntax.GetReference(), syntax.Body.GetReferenceOrNull(), ImmutableArray.Create(location))
{
bool modifierErrors;
var declarationModifiers = this.MakeModifiers(syntax.Modifiers, methodKind, location, diagnostics, out modifierErrors);
this.flags = MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExtensionMethod: false);
var bodyOpt = syntax.Body;
if (bodyOpt != null)
{
if (IsExtern)
{
diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this);
}
}
var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers);
if (info != null)
{
diagnostics.Add(info, location);
}
if (!modifierErrors)
{
this.CheckModifiers(methodKind, location, diagnostics);
}
}
示例5: 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;
}
示例6: IntroduceFieldFromConstructor
public static SyntaxNode IntroduceFieldFromConstructor(SyntaxNode root, ConstructorDeclarationSyntax constructorStatement, ParameterSyntax parameter)
{
var oldClass = constructorStatement.FirstAncestorOrSelf<ClassDeclarationSyntax>();
var newClass = oldClass;
var fieldName = parameter.Identifier.ValueText;
var fieldType = parameter.Type;
var members = ExtractMembersFromClass(oldClass.Members);
var addMember = false;
if (!members.Any(p => p.Key == fieldName && p.Value == fieldType.ToString()))
{
var identifierPostFix = 0;
while (members.Any(p => p.Key == fieldName))
fieldName = parameter.Identifier.ValueText + ++identifierPostFix;
addMember = true;
}
var assignmentField = SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(),
SyntaxFactory.IdentifierName(fieldName)), SyntaxFactory.IdentifierName(parameter.Identifier.ValueText)));
var newConstructor = constructorStatement.WithBody(constructorStatement.Body.AddStatements(assignmentField));
newClass = newClass.ReplaceNode(constructorStatement, newConstructor);
if (addMember)
{
var newField = SyntaxFactory.FieldDeclaration(SyntaxFactory.VariableDeclaration(parameter.Type)
.WithVariables(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(SyntaxFactory.Identifier(fieldName)))))
.WithModifiers(SyntaxFactory.TokenList(new[] { SyntaxFactory.Token(SyntaxKind.PrivateKeyword), SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword) }))
.WithAdditionalAnnotations(Formatter.Annotation);
newClass = newClass.WithMembers(newClass.Members.Insert(0, newField)).WithoutAnnotations(Formatter.Annotation);
}
var newRoot = root.ReplaceNode(oldClass, newClass);
return newRoot;
}
示例7: VisitConstructorDeclaration
public override SyntaxNode VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
{
if(this._targetConstructor == null || node.ParameterList.ToString() == this._targetConstructor.ParameterList.ToString())
{
var fieldName = this._relatedField.Declaration.Variables
.Select(p => p.Identifier.Text)
.FirstOrDefault();
var paramName = fieldName.TrimStart('_');
if (this._rewriteParams)
{
var newParam = SyntaxFactory.Parameter(SyntaxFactory.Identifier(paramName))
.WithType(this._relatedField.Declaration.Type);
var newConstructorParams = node.ParameterList.AddParameters(newParam);
node = node.WithParameterList(newConstructorParams);
}
var newStatement = SyntaxExtenders.AssignmentStatement("this." + fieldName, paramName);
var newStatements = node.Body.Statements.Insert(0, newStatement);
node = node.WithBody(node.Body.WithStatements(newStatements));
}
return base.VisitConstructorDeclaration(node);
}
示例8: AddStatementToConstructorBody
internal static SyntaxNode AddStatementToConstructorBody(SyntaxNode root, ConstructorDeclarationSyntax constructor, StatementSyntax statement)
{
var body = constructor.Body ?? SyntaxFactory.Block();
return root.ReplaceNode(root.GetCurrentNode(constructor), constructor.WithBody(
body.WithStatements(SyntaxFactory.List(new[] { statement }.Concat(body.Statements)))
));
}
示例9: EntryPoint
internal void EntryPoint(ConstructorDeclarationSyntax ctor)
{
_entry = ctor;
foreach (var param in ctor.ParameterList.Parameters)
{
addProducer(param.Identifier.ToString(), param.Type);
}
}
示例10: IsEmpty
static bool IsEmpty(ConstructorDeclarationSyntax constructorDeclaration)
{
if (constructorDeclaration.Initializer != null && constructorDeclaration.Initializer.ArgumentList.Arguments.Count > 0)
return false;
return constructorDeclaration.ParameterList.Parameters.Count == 0 &&
EmptyDestructorAnalyzer.IsEmpty(constructorDeclaration.Body);
}
示例11: CreateConstructorSymbol
public static SourceConstructorSymbol CreateConstructorSymbol(
SourceMemberContainerTypeSymbol containingType,
ConstructorDeclarationSyntax syntax,
DiagnosticBag diagnostics)
{
var methodKind = syntax.Modifiers.Any(SyntaxKind.StaticKeyword) ? MethodKind.StaticConstructor : MethodKind.Constructor;
return new SourceConstructorSymbol(containingType, syntax.Identifier.GetLocation(), syntax, methodKind, diagnostics);
}
示例12: VisitConstructorDeclaration
public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
{
ConstructorWalker walker = this.CreateSyntaxWalker<ConstructorWalker>(node);
walker.Visit(node);
this.Constructors.Add(walker);
base.VisitConstructorDeclaration(node);
}
示例13: Go
public static void Go(OutputWriter writer, ConstructorDeclarationSyntax constructor)
{
//Only write out static constructors here. If we encounter an instance constructor, we can ignore it since it's already written out by WriteType
if (constructor.Modifiers.Any(SyntaxKind.StaticKeyword))
WriteStaticConstructor(writer, constructor, null);
else
WriteInstanceConstructor(writer, constructor,null);
}
示例14: VisitConstructorDeclaration
public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
{
if(!node.Modifiers.Any(predicate => predicate.Kind() == SyntaxKind.StaticKeyword))
{
this._nonStaticConstructors.Add(node);
}
base.VisitConstructorDeclaration(node);
}
示例15: ConstructorDeclarationTranslation
public ConstructorDeclarationTranslation(ConstructorDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
Identifier = syntax.Identifier.Get(this);
if (syntax.Initializer != null)
{
Initializer = syntax.Initializer.Get<ConstructorInitializerTranslation>(this);
}
}