本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.AddMembers方法的典型用法代码示例。如果您正苦于以下问题:C# ClassDeclarationSyntax.AddMembers方法的具体用法?C# ClassDeclarationSyntax.AddMembers怎么用?C# ClassDeclarationSyntax.AddMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax
的用法示例。
在下文中一共展示了ClassDeclarationSyntax.AddMembers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCodeFixWithNewPublicConstructor
private static void AddCodeFixWithNewPublicConstructor(CodeFixContext context, SyntaxNode root,
Diagnostic diagnostic, ClassDeclarationSyntax classNode)
{
// Generated from http://roslynquoter.azurewebsites.net/
var constructor = SyntaxFactory.ConstructorDeclaration(classNode.Identifier)
.WithModifiers(
SyntaxFactory.TokenList(
SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
.WithParameterList(SyntaxFactory.ParameterList()
.WithOpenParenToken(
SyntaxFactory.Token(SyntaxKind.OpenParenToken))
.WithCloseParenToken(
SyntaxFactory.Token(
SyntaxKind.CloseParenToken)))
.WithBody(SyntaxFactory.Block()
.WithOpenBraceToken(
SyntaxFactory.Token(
SyntaxKind.OpenBraceToken))
.WithCloseBraceToken(
SyntaxFactory.Token(
SyntaxKind.CloseBraceToken))).NormalizeWhitespace().WithAdditionalAnnotations(Formatter.Annotation);
var newClassNode = classNode.AddMembers(constructor);
var newRoot = root.ReplaceNode(classNode, newClassNode);
context.RegisterCodeFix(
CodeAction.Create(
CheckConstructorsAnalyzerPublicConstructorCodeFixConstants.AddPublicConstructorDescription,
_ => Task.FromResult(context.Document.WithSyntaxRoot(newRoot)),
CheckConstructorsAnalyzerPublicConstructorCodeFixConstants.AddPublicConstructorDescription), diagnostic);
}
示例2: AddField
public static ClassDeclarationSyntax AddField(ClassDeclarationSyntax classDeclaration, string type, string name)
{
return classDeclaration.AddMembers(
SF.FieldDeclaration(SF.VariableDeclaration(SF.ParseTypeName(type),
SF.SeparatedList(new[] { SF.VariableDeclarator(SF.Identifier(name)) })))
.AddModifiers(SF.Token(SyntaxKind.PrivateKeyword)));
}
示例3: VisitClassDeclaration
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
TypeName = node.Identifier.ValueText;
TypeSyntax clientContextInterface = SyntaxFactory.ParseTypeName(string.Format("I{0}ClientContext", _edmxName));
var value = node.AddMembers(
SyntaxFactory.FieldDeclaration(
attributeLists: default(SyntaxList<AttributeListSyntax>),
modifiers: SyntaxFactory.TokenList(
SyntaxFactory.Token(SyntaxKind.PrivateKeyword)),
declaration: SyntaxFactory.VariableDeclaration(
clientContextInterface,
SyntaxFactory.SeparatedList(
new[] { SyntaxFactory.VariableDeclarator(
SyntaxFactory.Identifier("_context")) }))),
SyntaxFactory.ConstructorDeclaration(SyntaxFactory.Identifier(node.Identifier.ValueText))
.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
.AddParameterListParameters(SyntaxFactory.Parameter(SyntaxFactory.Identifier("context")).WithType(clientContextInterface))
.WithInitializer(SyntaxFactory.ConstructorInitializer(
kind: SyntaxKind.BaseConstructorInitializer,
argumentList: SyntaxFactory.ArgumentList(
arguments: SyntaxFactory.SeparatedList(
new[] { SyntaxFactory.Argument(
expression: SyntaxFactory.IdentifierName("context")) })))
.WithThisOrBaseKeyword(SyntaxFactory.Token(SyntaxKind.BaseKeyword)))
.WithBody(SyntaxFactory.Block(SyntaxFactory.ParseStatement("_context = context;"))))
.AddBaseListTypes(SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName("ViewModelBase")));
if (!value.Modifiers.Any(m => m.Kind() == SyntaxKind.PublicKeyword || m.Kind() == SyntaxKind.InternalKeyword))
value = value.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
return value;
}
示例4: VisitClassDeclaration
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
var yieldClasses = new List<ClassDeclarationSyntax>();
foreach (var method in node.Members.OfType<MemberDeclarationSyntax>().Where(j=>j is MethodDeclarationSyntax || j is PropertyDeclarationSyntax).Where(x => YieldChecker.HasYield(x)))
{
var yieldGenerator = new YieldClassGenerator(compilation, node, method);
var enumerator = yieldGenerator.CreateEnumerator();
yieldClasses.Add(enumerator);
}
if (yieldClasses.Any())
{
return node.AddMembers(yieldClasses.ToArray());
}
else
{
return base.VisitClassDeclaration(node);
}
}
示例5: AddSuppDiagAsync
private async Task<Document> AddSuppDiagAsync(Document document, ClassDeclarationSyntax declaration, CancellationToken c)
{
SyntaxList<MemberDeclarationSyntax> members = declaration.Members;
MethodDeclarationSyntax insertPoint = null;
foreach (MemberDeclarationSyntax member in members)
{
insertPoint = member as MethodDeclarationSyntax;
if (insertPoint == null || insertPoint.Identifier.Text != "Initialize")
{
continue;
}
else
{
break;
}
}
SyntaxNode insertPointNode = insertPoint as SyntaxNode;
SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document);
var semanticModel = await document.GetSemanticModelAsync();
INamedTypeSymbol notImplementedException = semanticModel.Compilation.GetTypeByMetadataName("System.NotImplementedException");
PropertyDeclarationSyntax propertyDeclaration = CodeFixNodeCreator.CreateSupportedDiagnostics(generator, notImplementedException);
var newNodes = new SyntaxList<SyntaxNode>();
newNodes = newNodes.Add(propertyDeclaration);
var root = await document.GetSyntaxRootAsync();
if (insertPoint != null)
{
var newRoot = root.InsertNodesBefore(insertPointNode, newNodes);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
else
{
var newRoot = root.ReplaceNode(declaration, declaration.AddMembers(propertyDeclaration));
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
}
示例6: AddRuleAsync
private async Task<Document> AddRuleAsync(Document document, ClassDeclarationSyntax declaration, CancellationToken c)
{
SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document);
SyntaxList<MemberDeclarationSyntax> members = declaration.Members;
PropertyDeclarationSyntax insertPoint = null;
foreach (MemberDeclarationSyntax member in members)
{
insertPoint = member as PropertyDeclarationSyntax;
if (insertPoint == null || insertPoint.Identifier.Text != "SupportedDiagnostics")
{
insertPoint = null;
continue;
}
else
{
break;
}
}
SyntaxNode insertPointNode = insertPoint as SyntaxNode;
FieldDeclarationSyntax fieldDeclaration = CodeFixNodeCreator.CreateEmptyRule(generator);
var newNode = new SyntaxList<SyntaxNode>();
newNode = newNode.Add(fieldDeclaration.WithLeadingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.Whitespace(" "), SyntaxFactory.ParseLeadingTrivia("// If the analyzer finds an issue, it will report the DiagnosticDescriptor rule").ElementAt(0), SyntaxFactory.EndOfLine("\r\n"), SyntaxFactory.Whitespace(" "))));
var root = await document.GetSyntaxRootAsync();
if (insertPointNode != null)
{
var newRoot = root.InsertNodesBefore(insertPointNode, newNode);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
else
{
var newRoot = root.ReplaceNode(declaration, declaration.AddMembers(fieldDeclaration.WithLeadingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.ParseLeadingTrivia("// If the analyzer finds an issue, it will report the DiagnosticDescriptor rule").ElementAt(0), SyntaxFactory.EndOfLine("\r\n")))));
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
}
示例7: addType
private ClassDeclarationSyntax addType(PropertyWithName p, ClassDeclarationSyntax @class)
{
var tn = ParseTypeName(p.PropertyName);
var pi = p.Type.GetProperties();
var method = createGetMethod(p.Type, pi)
.WithLeadingTrivia(Trivia(RegionDirectiveTrivia(true)
.WithEndOfDirectiveToken(
Token(TriviaList().Add(PreprocessingMessage(p.PropertyName)),
SyntaxKind.EndOfDirectiveToken,
TriviaList())
)
));
method = method.WithTrailingTrivia(
Trivia(
EndRegionDirectiveTrivia(true)
)
);
return @class.AddMembers(method);
}
示例8: DecorateClassWithWrapperFunction
private static ClassDeclarationSyntax DecorateClassWithWrapperFunction(MethodDeclarationSyntax methodDeclaration,
IdentifierNameSyntax invokeMethodIdentifier,
ClassDeclarationSyntax classDeclaration)
{
if (classDeclaration.Members
.OfType<MethodDeclarationSyntax>()
.Any(x => x.Identifier.Text == invokeMethodIdentifier.Identifier.Text))
{
return classDeclaration;
}
var dllImport = methodDeclaration.AttributeLists
.First(x => x.OpenBracketToken.HasLeadingTrivia);
var arguments = methodDeclaration.ParameterList
.Parameters
.Select((x, i) =>
{
var identifierName = SyntaxFactory.Argument(
null,
x.Modifiers
.FirstOrDefault(z => z.IsKind(SyntaxKind.RefKeyword) || z.IsKind(SyntaxKind.OutKeyword))
.WithLeadingTrivia(),
SyntaxFactory.IdentifierName(x.Identifier));
if (i > 0)
{
identifierName = identifierName.WithLeadingTrivia(WhitespaceCharacter);
}
return identifierName;
});
var arrowBody = SyntaxFactory.ArrowExpressionClause(
SyntaxFactory.Token(SyntaxKind.EqualsGreaterThanToken)
.WithLeadingTrivia(
NewLineCharacter,
TabCharacter,
TabCharacter,
TabCharacter)
.WithTrailingTrivia(WhitespaceCharacter),
SyntaxFactory.InvocationExpression(
SyntaxFactory.IdentifierName(methodDeclaration.Identifier),
SyntaxFactory.ArgumentList(
SyntaxFactory.SeparatedList(arguments))));
var wrapperMethodDeclaration = SyntaxFactory.MethodDeclaration(
SyntaxFactory.List(new[] {
GetCompilerGeneratedAttribute()
.WithTrailingTrivia(
NewLineCharacter,
TabCharacter,
TabCharacter)
}),
GetModifiersForWrapperFunction(methodDeclaration)
.Add(SyntaxFactory.Token(SyntaxKind.PublicKeyword)
.WithTrailingTrivia(WhitespaceCharacter)),
methodDeclaration.ReturnType,
default(ExplicitInterfaceSpecifierSyntax),
invokeMethodIdentifier.Identifier,
methodDeclaration.TypeParameterList,
methodDeclaration.ParameterList,
methodDeclaration.ConstraintClauses,
default(BlockSyntax),
arrowBody,
SyntaxFactory.Token(SyntaxKind.SemicolonToken));
classDeclaration = classDeclaration
.AddMembers(
wrapperMethodDeclaration
.WithTrailingTrivia(
NewLineCharacter,
TabCharacter)
.WithLeadingTrivia(dllImport.OpenBracketToken.LeadingTrivia));
return classDeclaration;
}
示例9: addType
private ClassDeclarationSyntax addType(PropertyWithName pwn, ClassDeclarationSyntax @class)
{
var tn = ParseTypeName(pwn.Type.Name);
var pi = pwn.Type.GetProperties();
var method = createGetMethod(pwn.Type, pi)
.WithLeadingTrivia(Trivia(RegionDirectiveTrivia(true)
.WithEndOfDirectiveToken(
Token(TriviaList().Add(PreprocessingMessage(pwn.Type.Name)),
SyntaxKind.EndOfDirectiveToken,
TriviaList())
)
));
method = method.WithTrailingTrivia(
Trivia(
EndRegionDirectiveTrivia(true)
)
);
return @class.AddMembers(method);
/*cu.NormalizeWhitespace("\t", true).WriteTo(writer);
writer.WriteLine();
writer.WriteLine();*/
}
示例10: FinalizeSyntax
private void FinalizeSyntax()
{
// Dispose method handling
var disposeFound = false;
// For empty dispose we dont want to merge it really
for (var i = 0; i < m_methodDeclarations.Count; i++)
{
if (m_methodDeclarations[i].Identifier.ToString() == m_disposeMethod.Identifier.ToString())
{
// Dont add empty body to the already created one
if(m_disposeMethod.Body.Statements.Count > 0)
{
m_methodDeclarations[i] = m_methodDeclarations[i].AddBodyStatements(m_disposeMethod.Body);
}
disposeFound = true;
break;
}
}
if(!disposeFound)
m_methodDeclarations.Add(m_disposeMethod);
AddMissingInterfaceMethods();
// if the interface type is objective logic script we need to hack in the rest of the interface methods
if(m_baseType == typeof(IMyStateMachineScript))
AddMissionLogicScriptMethods();
m_scriptClassDeclaration = m_scriptClassDeclaration.AddMembers(m_fieldDeclarations.ToArray());
m_scriptClassDeclaration = m_scriptClassDeclaration.AddMembers(m_constructor);
m_scriptClassDeclaration = m_scriptClassDeclaration.AddMembers(m_methodDeclarations.ToArray());
m_namespaceDeclaration = m_namespaceDeclaration.AddMembers(m_scriptClassDeclaration);
var usings = new List<UsingDirectiveSyntax>();
var usingsUniqueSet = new HashSet<string>();
var defaultUsing = MySyntaxFactory.UsingStatementSyntax("VRage.Game.VisualScripting");
usings.Add(defaultUsing);
usingsUniqueSet.Add(defaultUsing.ToFullString());
foreach (var node in m_navigator.OfType<MyVisualSyntaxFunctionNode>())
{
if(usingsUniqueSet.Add(node.Using.ToFullString()))
usings.Add(node.Using);
}
foreach (var node in m_navigator.OfType<MyVisualSyntaxVariableNode>())
{
if (usingsUniqueSet.Add(node.Using.ToFullString()))
usings.Add(node.Using);
}
m_compilationUnit = SyntaxFactory.CompilationUnit().WithUsings(SyntaxFactory.List(
usings
)).AddMembers(m_namespaceDeclaration).NormalizeWhitespace();
}
示例11: AddClass
private static ClassDeclarationSyntax AddClass(ClassDeclarationSyntax baseClass, string name, Property[] properties, Configuration config)
{
if (name.Equals("object", StringComparison.OrdinalIgnoreCase))
{
return baseClass;
}
var className = ClassNameNormaliser(name);
var @class = SyntaxFactory.ClassDeclaration(className)
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.PartialKeyword));
if (config.AddRefactoringEssentialsPartialClassSupression)
{
@class = @class.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(new[] {
SyntaxFactory.Attribute(SyntaxFactory.ParseName("System.Diagnostics.CodeAnalysis.SuppressMessage"))
.AddArgumentListArguments(SyntaxFactory.AttributeArgument(SyntaxFactory.ParseExpression("\"\"")),
SyntaxFactory.AttributeArgument(SyntaxFactory.ParseExpression("\"RECS0001:Class is declared partial but has only one part\"")),
SyntaxFactory.AttributeArgument(SyntaxFactory.ParseExpression("Justification = \"This is partial to allow the file to extended in a seperate file if needed. Changes to this file would be lost when the code is regenerated and so supporting a seperate file for this is ideal.\"")))
})));
}
if (properties != null)
{
foreach (var property in properties)
{
var propertyType = "";
if (!string.IsNullOrWhiteSpace(property.Type))
{
switch (property.Type.ToUpperInvariant())
{
case "ARRAY":
{
var arrayClass = property.ArrayItemType;
if (arrayClass.StartsWith("#/definitions", StringComparison.OrdinalIgnoreCase))
{
arrayClass = RefToClass(arrayClass);
}
else
{
arrayClass = JsonSchemaToDotNetType(className, property.Name, property);
}
propertyType = arrayClass + "[]";
break;
}
case "STRING":
{
propertyType = JsonSchemaToDotNetType(className, property.Name, property);
if (IsJsonSchemaEnum(property))
{
@class = AddEnum(@class, propertyType, property.Enum);
}
break;
}
default:
{
propertyType = JsonSchemaToDotNetType(className, property.Name, property);
break;
}
}
}
else
{
propertyType = RefToClass(property.Ref);
}
@class = @class.AddMembers(Property(property.Name, propertyType));
}
}
return baseClass.AddMembers(@class);
}
示例12: AddOperation
//.........这里部分代码省略.........
{
var bodyParam = parameters.SingleOrDefault(_ => _.Location != null && (_.Location.Equals("body", StringComparison.OrdinalIgnoreCase)));
if (bodyParam != null)
{
httpMethod += $", new StringContent(JsonConvert.SerializeObject({bodyParam.Name}))";
}
var formDataParams = parameters.Where(_ => _.Location != null && (_.Location.Equals("formdata", StringComparison.OrdinalIgnoreCase)));
if (formDataParams.Any())
{
var formDataValue = formDataParams.Aggregate("", (curr, next) => curr + (curr.Length > 0 ? ", " : "") + next.Name);
httpMethod += [email protected]", new StringContent(JsonConvert.SerializeObject(new {{{formDataValue}}}))";
}
}
if (authedCall)
{
httpMethod += ", token: oauthToken";
}
httpMethod += ");";
var methodBody = [email protected]"
{{
{(addQueryParameterCode ? queryParameterCode : "")}
var response = {httpMethod}
if (response == null)
{{
return new APIResponse<{responseClass}>(false);
}}
switch ((int)response.StatusCode)
{{";
var successId = config.Operation.Responses.First(_ => _.HttpStatusCode >= 200 && _.HttpStatusCode <= 299).HttpStatusCode;
foreach (var response in config.Operation.Responses)
{
methodBody += [email protected]"case {response.HttpStatusCode}:
{{
";
if (response.HttpStatusCode == successId)
{
if (response.Schema == null || response.Schema.Type == "object")
{
methodBody += $"return new APIResponse<{responseClass}>(response.StatusCode);";
}
else
{
methodBody += [email protected]"var data = JsonConvert.DeserializeObject<{responseClass}>(await response.Content.ReadAsStringAsync());
return new APIResponse<{responseClass}>(data, response.StatusCode);";
}
}
else
{
if (response.Schema == null || response.Schema.Type == "object")
{
methodBody += $"return new APIResponse<{responseClass}>(response.StatusCode);";
}
else
{
var specialData = string.IsNullOrWhiteSpace(response.Schema.Type) ? RefToClass(response.Schema.Ref) : ClassNameNormaliser(response.Schema.Type);
methodBody += [email protected]"var data = JsonConvert.DeserializeObject<{ClassNameNormaliser(specialData)}>(await response.Content.ReadAsStringAsync());
return new APIResponse<{responseClass}>(data, response.StatusCode);";
}
}
methodBody += "}";
}
methodBody += [email protected]"default:
{{
return new APIResponse<{responseClass}>(response.StatusCode);
}}
}}
}}";
var xmlComments = new List<SyntaxTrivia>();
if (!string.IsNullOrWhiteSpace(config.Operation.Summary))
{
xmlComments.AddRange(AddXmlComment("summary", CleanXMLComment(config.Operation.Summary)));
}
if (!string.IsNullOrWhiteSpace(config.Operation.Description))
{
xmlComments.AddRange(AddXmlComment("remarks", CleanXMLComment(config.Operation.Description)));
}
if (!string.IsNullOrWhiteSpace(successResponse.Description))
{
xmlComments.AddRange(AddXmlComment("returns", CleanXMLComment(successResponse.Description)));
}
xmlComments.AddRange(parameters.Select(_ => AddXmlParamComment(_.Name, _.Description)));
method = method
.AddBodyStatements(SyntaxFactory.ParseStatement(methodBody))
.WithLeadingTrivia(SyntaxExtensions.ToSyntaxTriviaList(xmlComments));
return @class.AddMembers(method);
}
示例13: AddEnum
private static ClassDeclarationSyntax AddEnum(ClassDeclarationSyntax @class, string enumName, string[] enumValues)
{
var @enum = SyntaxFactory.EnumDeclaration(enumName)
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
.AddMembers(enumValues.Select(_ => SyntaxFactory.EnumMemberDeclaration(_)).ToArray());
return @class.AddMembers(@enum);
}
示例14: GetCollectible
internal static ClassDeclarationSyntax GetCollectible(ClassDeclarationSyntax classDecl)
{
foreach(var c in ClassNames)
{
var anyCards = false;
var className = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(c.ToLower());
var cCard = ClassDeclaration(className).AddModifiers(Token(PublicKeyword));
foreach(var card in
Cards.All.Values.Where(x => x.Collectible && x.Class.ToString().Equals(c)))
{
var name = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(card.Name.ToLower());
name = Regex.Replace(name, @"[^\w\d]", "");
cCard = cCard.AddMembers(GenerateConst(name, card.Id));
anyCards = true;
}
if(anyCards)
classDecl = classDecl.AddMembers(cCard);
}
return classDecl;
}
示例15: VisitClassDeclaration
//public SemanticModel Model { get; private set; }
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
node = (ClassDeclarationSyntax)base.VisitClassDeclaration(node);
MethodDeclarationSyntax prector = SyntaxFactory.MethodDeclaration(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)), ".prector");
MethodDeclarationSyntax precctor = SyntaxFactory.MethodDeclaration(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)), ".precctor");
precctor = precctor.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword));
List<StatementSyntax> Initializers = new List<StatementSyntax>();
List<StatementSyntax> StaticInitializers = new List<StatementSyntax>();
foreach (MemberDeclarationSyntax member in node.Members)
{
if (member.CSharpKind() == SyntaxKind.FieldDeclaration)
{
FieldDeclarationSyntax fds = (FieldDeclarationSyntax)member;
foreach (VariableDeclaratorSyntax vds in fds.Declaration.Variables)
{
if (vds.Initializer != null)
{
if (fds.Modifiers.ToString().Contains("static"))
{
StaticInitializers.Add(SyntaxFactory.ExpressionStatement(SyntaxFactory.BinaryExpression(SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName(vds.Identifier), vds.Initializer.Value)));
}
else
{
Initializers.Add(SyntaxFactory.ExpressionStatement(SyntaxFactory.BinaryExpression(SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName(vds.Identifier), vds.Initializer.Value)));
}
}
}
}
}
if (Initializers.Count == 0 && StaticInitializers.Count == 0)
return node;
SyntaxList<MemberDeclarationSyntax> newMembers = new SyntaxList<MemberDeclarationSyntax>();
if (Initializers.Count > 0)
{
int constructors = node.Members.Count((m) => (m is ConstructorDeclarationSyntax && !((ConstructorDeclarationSyntax)m).Modifiers.ToString().Contains("static")));
prector = prector.AddBodyStatements(Initializers.ToArray());
node = node.AddMembers(prector);
if (constructors == 0)
{
ConstructorDeclarationSyntax ctor = SyntaxFactory.ConstructorDeclaration(node.Identifier);
ctor = ctor.AddBodyStatements(SyntaxFactory.ExpressionStatement(SyntaxFactory.InvocationExpression(SyntaxFactory.IdentifierName(".prector"))));
ctor = ctor.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
newMembers = newMembers.Add(ctor);
}
// else
{
foreach (MemberDeclarationSyntax member in node.Members)
{
if (member.CSharpKind() == SyntaxKind.ConstructorDeclaration && !((ConstructorDeclarationSyntax)member).Modifiers.ToString().Contains("static"))
{
newMembers = newMembers.Add((MemberDeclarationSyntax)ConstructorPrefixerDeclaration((ConstructorDeclarationSyntax)member));
}
else
{
newMembers = newMembers.Add(member);
}
}
}
}
if (StaticInitializers.Count > 0)
{
int constructors = node.Members.Count((m) => (m is ConstructorDeclarationSyntax && ((ConstructorDeclarationSyntax)m).Modifiers.ToString().Contains("static")));
precctor = precctor.AddBodyStatements(StaticInitializers.ToArray());
node = node.AddMembers(precctor);
if (constructors == 0)
{
ConstructorDeclarationSyntax ctor = SyntaxFactory.ConstructorDeclaration(node.Identifier);
ctor = ctor.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword));
ctor = ctor.AddBodyStatements(SyntaxFactory.ExpressionStatement(SyntaxFactory.InvocationExpression(SyntaxFactory.IdentifierName(".precctor"))));
ctor = ctor.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
newMembers = newMembers.Add(ctor);
}
//else
{
foreach (MemberDeclarationSyntax member in node.Members)
{
if (member.CSharpKind() == SyntaxKind.ConstructorDeclaration && ((ConstructorDeclarationSyntax)member).Modifiers.ToString().Contains("static"))
{
newMembers = newMembers.Add((MemberDeclarationSyntax)StaticConstructorPrefixerDeclaration((ConstructorDeclarationSyntax)member));
}
else
{
newMembers = newMembers.Add(member);
}
}
}
}
//.........这里部分代码省略.........