本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# ClassDeclarationSyntax类的具体用法?C# ClassDeclarationSyntax怎么用?C# ClassDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ClassDeclarationSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitClassDeclaration
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
node = (ClassDeclarationSyntax)base.VisitClassDeclaration(node);
Classes.Add(node);
return node;
}
示例2: IsMachine
/// <summary>
/// Returns true if the given class declaration is a P# machine.
/// </summary>
/// <param name="compilation">Compilation</param>
/// <param name="classDecl">Class declaration</param>
/// <returns>Boolean</returns>
internal static bool IsMachine(CodeAnalysis.Compilation compilation,
ClassDeclarationSyntax classDecl)
{
var result = false;
if (classDecl.BaseList == null)
{
return result;
}
var model = compilation.GetSemanticModel(classDecl.SyntaxTree);
var symbol = model.GetDeclaredSymbol(classDecl);
while (true)
{
if (symbol.ToString() == typeof(Machine).FullName)
{
result = true;
break;
}
else if (symbol.BaseType != null)
{
symbol = symbol.BaseType;
continue;
}
break;
}
return result;
}
示例3: VisitClassDeclaration
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
var value = (ClassDeclarationSyntax)base.VisitClassDeclaration(node);
if (_first)
{
var statements = new[] { string.Format(" unityContainer.RegisterType<I{0}Service, {0}ServiceClient>(new InjectionConstructor());\r\n", _edmxName), string.Format(" unityContainer.RegisterType<I{0}ClientContext, {0}ClientContext>();\r\n", _edmxName), string.Format(" ClientContextFactory<I{0}ClientContext>.Factory = () => unityContainer.Resolve<I{0}ClientContext>();\r\n", _edmxName) };
if (_addApplicationStart)
value = value.AddMembers(
SyntaxFactory.MethodDeclaration(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)), "OnStartup")
.WithModifiers(SyntaxFactory.TokenList(
SyntaxFactory.Token(SyntaxKind.ProtectedKeyword),
SyntaxFactory.Token(SyntaxKind.OverrideKeyword)))
.AddParameterListParameters(
SyntaxFactory.Parameter(SyntaxFactory.Identifier("e")).WithType(SyntaxFactory.ParseTypeName("StartupEventArgs")))
.WithBody(SyntaxFactory.Block().AddStatements(
SyntaxFactory.ParseStatement("IUnityContainer unityContainer = new UnityContainer();"),
SyntaxFactory.ParseStatement("unityContainer.RegisterType<IMessageBoxService, MessageBoxService>();"),
SyntaxFactory.ParseStatement("DispatcherUnhandledException += (sender, ex) => { unityContainer.Resolve<IMessageBoxService>().ShowError(ex.Exception.Message);ex.Handled = true; };"),
SyntaxFactory.ParseStatement("TaskScheduler.UnobservedTaskException += (sender, ex) => { unityContainer.Resolve<IMessageBoxService>().ShowError(ex.Exception.InnerException.Message);ex.SetObserved(); };"),
SyntaxFactory.ParseStatement("InitWAQSModules(unityContainer);"),
SyntaxFactory.ParseStatement("UIThread.Dispatcher = Application.Current.Dispatcher;"),
SyntaxFactory.ParseStatement("UIThread.TaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();"),
SyntaxFactory.ParseStatement(string.Format("unityContainer.Resolve<{0}>().Show();", _pageTypeName)))));
if (_addInitWAQSModules)
return value.AddMembers(
SyntaxFactory.MethodDeclaration(
SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)), "InitWAQSModules")
.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)))
.AddParameterListParameters(
SyntaxFactory.Parameter(SyntaxFactory.Identifier("unityContainer")).WithType(SyntaxFactory.ParseTypeName("IUnityContainer")))
.WithBody(SyntaxFactory.Block().AddStatements(
statements.Select(s => SyntaxFactory.ParseStatement(s)).ToArray())));
}
return value;
}
示例4: VisitClassDeclaration
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
_cancellationToken.ThrowIfCancellationRequested();
var namedTypeSymbol = _semanticModel.GetDeclaredSymbol(node, _cancellationToken);
var classAssumptions = _classAssumptions.Where(ca => ca.Class == namedTypeSymbol).ToList();
if (classAssumptions.Count == 0)
{
return base.VisitClassDeclaration(node);
}
var newClass = (ClassDeclarationSyntax)base.VisitClassDeclaration(node);
foreach (var classAssumption in classAssumptions)
{
foreach (string attributeToDelete in classAssumption.GetAttributesToDelete(_objectTheoremResult))
{
newClass = RemoveAttribute(newClass, attributeToDelete);
}
foreach (string attributeToAdd in classAssumption.GetAttributesToAdd(_objectTheoremResult))
{
newClass = EnsureAttribute(newClass, attributeToAdd);
}
}
return newClass;
}
示例5: AddStaticKeyword
private Task<Document> AddStaticKeyword(Document document, SyntaxNode root, ClassDeclarationSyntax classDeclaration)
{
var staticKeyword = SyntaxFactory.Token(SyntaxKind.StaticKeyword).WithAdditionalAnnotations(Formatter.Annotation);
var newDeclaration = classDeclaration.AddModifiers(staticKeyword);
var newRoot = root.ReplaceNode(classDeclaration, newDeclaration);
return Task.FromResult(document.WithSyntaxRoot(newRoot));
}
示例6: GetTestFixtureDetails
public TestFixtureDetails GetTestFixtureDetails(ClassDeclarationSyntax fixtureNode, ISemanticModel semanticModel)
{
var fixture = ExtractTests(fixtureNode, semanticModel);
fixture.AssemblyName = PathHelper.GetCoverageDllName(semanticModel.GetAssemblyName());
return fixture;
}
示例7: GetFactoryMethodDeclaration
private static MethodDeclarationSyntax GetFactoryMethodDeclaration(ClassDeclarationSyntax @class)
{
return
F.MethodDeclaration(
F.ParseName(@class.Identifier.Text),
F.Identifier(F.TriviaList(F.Space), @"Factory", F.TriviaList()))
.WithModifiers(F.TokenList(
F.Token(F.TriviaList(), K.PublicKeyword, F.TriviaList(F.Space)),
F.Token(F.TriviaList(), K.StaticKeyword, F.TriviaList(F.Space))))
.WithBody(
F.Block(F.SingletonList<StatementSyntax>(
F.ReturnStatement(CallConstuctor(@class))
.WithReturnKeyword(
F.Token(
F.TriviaList(
F.Whitespace(
" ")),
K.ReturnKeyword,
F.TriviaList(
F.Space)))
.WithSemicolonToken(
F.Token(
F.TriviaList(),
K.SemicolonToken,
F.TriviaList()
))
)));
}
示例8: VisitClassDeclaration
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
var typesList = new List<TypeSyntax> { _baseTypeSyntax };
if (node.BaseList != null)
typesList.AddRange(node.BaseList.Types);
var types = new SeparatedSyntaxList<TypeSyntax>();
types = types.AddRange(typesList);
var identifier = SyntaxFactory.Identifier(FurnaceTypeIdentifier + _typeName);
var newNode = node.Update(
node.AttributeLists,
node.Modifiers,
node.Keyword,
identifier,
node.TypeParameterList,
SyntaxFactory.BaseList(types),
node.ConstraintClauses,
node.OpenBraceToken,
node.Members,
node.CloseBraceToken,
node.SemicolonToken).NormalizeWhitespace();
return base.VisitClassDeclaration(newNode);
}
示例9: AddCodeFix
private static void AddCodeFix(CodeFixContext context, SyntaxNode root,
Diagnostic diagnostic, ClassDeclarationSyntax classNode)
{
var newRoot = IsBusinessObjectSerializableMakeSerializableCodeFix.AddAttribute(
root, classNode, IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SerializableName);
if (!root.HasUsing(IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SystemNamespace))
{
newRoot = (newRoot as CompilationUnitSyntax).AddUsings(
SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(
IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SystemNamespace)));
}
if (!root.HasUsing(IsBusinessObjectSerializableMakeSerializableCodeFixConstants.CslaSerializationNamespace))
{
newRoot = (newRoot as CompilationUnitSyntax).AddUsings(
SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(
IsBusinessObjectSerializableMakeSerializableCodeFixConstants.CslaSerializationNamespace)));
}
context.RegisterCodeFix(
CodeAction.Create(
IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableAndUsingDescription,
_ => Task.FromResult<Document>(context.Document.WithSyntaxRoot(newRoot))), diagnostic);
}
示例10: CallConstuctor
private static ObjectCreationExpressionSyntax CallConstuctor(ClassDeclarationSyntax @class)
{
var typeName = F.ParseName(@class.Identifier.Text);
var args = F.ArgumentList();
var ctor = @class.DescendantNodes().OfType<ConstructorDeclarationSyntax>().FirstOrDefault();
if(ctor != null)
{
var parameters = ctor.ParameterList.DescendantNodes().OfType<ParameterSyntax>().ToList();
foreach (var parameter in parameters)
{
var ident = parameter.DescendantNodes().OfType<IdentifierNameSyntax>().Single();
var parameterType = ident.Identifier.Text;
var invocation = F.InvocationExpression(F.MemberAccessExpression(
K.SimpleMemberAccessExpression,
F.IdentifierName(parameterType),
F.IdentifierName("Factory")));
args = args.AddArguments(F.Argument(invocation));
}
}
return F.ObjectCreationExpression(typeName)
.WithNewKeyword(F.Token(F.TriviaList(), K.NewKeyword, F.TriviaList(F.Space)))
.WithArgumentList(args);
}
示例11: 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);
}
示例12: 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)));
}
示例13: 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;
}
示例14: LookForAggregates
private void LookForAggregates(ClassDeclarationSyntax classNode)
{
if (classNode.Modifiers.Any(SyntaxKind.AbstractKeyword) || classNode.BaseList == null || !classNode.BaseList.Types.Any()) return;
// Dong Xie: Need review:
if (classNode.BaseList.Types.Any<TypeSyntax>(x => AggregateRootPlainIfx.Contains(x.ToString()))) AggregateRoots.Add(classNode);
}
示例15: VisitClassDeclaration
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
{
if (node.Modifiers.Any(m => m.Kind() == SyntaxKind.PartialKeyword))
return base.VisitClassDeclaration(node);
_notPartialClass = true;
return ((ClassDeclarationSyntax)base.VisitClassDeclaration(node)).WithModifiers(SyntaxFactory.TokenList(node.Modifiers.Union(new[] { SyntaxFactory.Token(SyntaxKind.PartialKeyword) })));
}