本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.NamespaceDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# NamespaceDeclarationSyntax类的具体用法?C# NamespaceDeclarationSyntax怎么用?C# NamespaceDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamespaceDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了NamespaceDeclarationSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUsingsSpan
private static TextSpan GetUsingsSpan(CompilationUnitSyntax root, NamespaceDeclarationSyntax namespaceDeclaration)
{
if (namespaceDeclaration != null)
{
var usings = namespaceDeclaration.Usings;
var start = usings.First().SpanStart;
var end = usings.Last().Span.End;
return TextSpan.FromBounds(start, end);
}
else
{
var rootUsings = root.Usings;
if (rootUsings.Any())
{
var start = rootUsings.First().SpanStart;
var end = rootUsings.Last().Span.End;
return TextSpan.FromBounds(start, end);
}
else
{
var start = 0;
var end = root.Members.Any()
? root.Members.First().GetFirstToken().Span.End
: root.Span.End;
return TextSpan.FromBounds(start, end);
}
}
}
示例2: VisitNamespaceDeclaration
//protected override void VisitInvocationExpression(InvocationExpressionSyntax node)
//{
//}
public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
foreach (var type in node.DescendantNodes().OfType<ClassDeclarationSyntax>())
{
Visit(type);
}
}
示例3: VisitNamespaceDeclaration
public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
var semanticModel = Context.Instance.Compilation.GetSemanticModel(node.SyntaxTree);
var symbol = semanticModel.GetDeclaredSymbol(node);
var fullName = symbol.GetFullName();
ProcessNamespace(fullName);
}
示例4: VisitNamespaceDeclaration
public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
string ns = node.Name.ToFullString();//Extend: seems no need to further break down.
var template = _template.CreateNamespaceTemplate();
template.Assign(NamespaceTemplate.NAMESPACE, ns);
if (!RegisteredNamespace.Contains(ns))
{
_output.WriteLine(node.Name, template.GetBeginString());
}
foreach (var member in node.Members)
{
var info = _semanticModel.GetDeclaredSymbol(member);
if (info.IsNoCompile())
continue;
this.Visit(member);
}
if (!RegisteredNamespace.Contains(ns))
{
_output.TrivialWriteLine(template.GetEndString());
RegisteredNamespace.Add(ns);
}
return node;
}
示例5: AddParameterClassToNamespaceAndUpdateClassToUseNamespace
private static NamespaceDeclarationSyntax AddParameterClassToNamespaceAndUpdateClassToUseNamespace(NamespaceDeclarationSyntax oldNamespace, ClassDeclarationSyntax oldClass, MethodDeclarationSyntax oldMethod)
{
var className = $"NewClass{oldMethod.Identifier.Text}";
var newParameterClass = CreateParameterClass(className, oldMethod);
var newNamespace = oldNamespace.ReplaceNode(oldClass, UpdateClassToUseNewParameterClass(className, oldClass, oldMethod))
.AddMembers(newParameterClass);
return newNamespace;
}
示例6: VisitNamespaceDeclaration
public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
if (node.Usings.Any() || node.Externs.Any())
{
node = node.WithAdditionalAnnotations(LayoutAnnotations.MultiLineConstructAnnotation);
}
return base.VisitNamespaceDeclaration(node);
}
示例7: AddMethodTo
internal static NamespaceDeclarationSyntax AddMethodTo(
NamespaceDeclarationSyntax destination,
IMethodSymbol method,
CodeGenerationOptions options,
IList<bool> availableIndices)
{
var declaration = GenerateMethodDeclaration(method, CodeGenerationDestination.Namespace, options);
var members = Insert(destination.Members, declaration, options, availableIndices, after: LastMethod);
return destination.WithMembers(members.ToSyntaxList());
}
示例8: VisitNamespaceDeclaration
/// <summary>Called when the visitor visits a NamespaceDeclarationSyntax node.</summary>
public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
var u = _namespaces.Select(each => SyntaxFactory.UsingDirective(SyntaxFactory.ParseName($" {each}"))
.WithLeadingTrivia(_leadingTrivia)
.WithTrailingTrivia(_trailingTrivia)
).ToArray();
node = node.AddUsings(u);
node = node.WithUsings(Sort(node.Usings));
return base.VisitNamespaceDeclaration(node);
}
示例9: AddNamedTypeTo
public static NamespaceDeclarationSyntax AddNamedTypeTo(
ICodeGenerationService service,
NamespaceDeclarationSyntax destination,
INamedTypeSymbol namedType,
CodeGenerationOptions options,
IList<bool> availableIndices)
{
var declaration = GenerateNamedTypeDeclaration(service, namedType, CodeGenerationDestination.Namespace, options);
var members = Insert(destination.Members, declaration, options, availableIndices);
return ConditionallyAddFormattingAnnotationTo(
destination.WithMembers(members),
members);
}
示例10: GenerateClasses
public static MemberDeclarationSyntax[] GenerateClasses(NamespaceDeclarationSyntax @namespace)
{
var isInterfaceToClass = @namespace.GetLeadingTrivia().Any(trivia => trivia.ToString().Trim() == "//Meta(interface-to-class)");
if (!isInterfaceToClass)
return Array<MemberDeclarationSyntax>.Empty;
var resultMembers = new List<MemberDeclarationSyntax>();
foreach (var @interface in @namespace.Members.OfType<InterfaceDeclarationSyntax>())
{
resultMembers.Add(ToClass(@interface));
}
return resultMembers.ToArray();
}
示例11: NewNameSpaceFactory
private static NamespaceDeclarationSyntax NewNameSpaceFactory(NamespaceDeclarationSyntax OldNameSpace, ClassDeclarationSyntax OldClass, MethodDeclarationSyntax OldMethod)
{
var newNameSpace = OldNameSpace;
var className = $"NewClass{OldMethod.Identifier.Text}";
var memberNameSpaceOld = (from member in OldNameSpace.Members
where member == OldClass
select member).FirstOrDefault();
newNameSpace = OldNameSpace.ReplaceNode(memberNameSpaceOld, NewClassFactory(className, OldClass, OldMethod));
var newParameterClass = NewClassParameterFactory(className, NewPropertyClassFactory(OldMethod));
newNameSpace = newNameSpace
.WithMembers(newNameSpace.Members.Add(newParameterClass))
.WithAdditionalAnnotations(Formatter.Annotation);
return newNameSpace;
}
示例12: AddNamespaceTo
public static NamespaceDeclarationSyntax AddNamespaceTo(
ICodeGenerationService service,
NamespaceDeclarationSyntax destination,
INamespaceSymbol @namespace,
CodeGenerationOptions options,
IList<bool> availableIndices)
{
var declaration = GenerateNamespaceDeclaration(service, @namespace, options);
if (!(declaration is NamespaceDeclarationSyntax))
{
throw new ArgumentException(CSharpWorkspaceResources.NamespaceCanNotBeAddedIn);
}
var members = Insert(destination.Members, (NamespaceDeclarationSyntax)declaration, options, availableIndices);
return destination.WithMembers(members);
}
示例13: VisitNamespaceDeclaration
public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
var result = (NamespaceDeclarationSyntax)base.VisitNamespaceDeclaration(node);
if (!_namespacesToImport.TryGetValue(node, out var namespaces))
{
return result;
}
if (!result.CanAddUsingDirectives(_cancellationToken))
{
return result;
}
var directives = CreateDirectives(namespaces);
return result.AddUsingDirectives(directives, _placeSystemNamespaceFirst, Formatter.Annotation);
}
示例14: VisitNamespaceDeclaration
public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
var parts = node.Name.ToString().Split('.');
cb.AppendIndent();
foreach (var part in parts)
{
cb.Append("namespace ").Append(part).Append(" { ");
}
cb.AppendLine();
base.VisitNamespaceDeclaration(node);
cb.AppendIndent();
foreach (var part in parts)
cb.Append("} /* " + part + "*/ ");
cb.AppendLine();
}
示例15: VisitNamespaceDeclaration
public override SyntaxNode VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
{
var identifierName = SyntaxFactory.IdentifierName(_typeNamespace);
var newNamespace = SyntaxFactory.NamespaceDeclaration(identifierName);
var newNode = node.Update(
node.NamespaceKeyword,
newNamespace.Name,
node.OpenBraceToken,
node.Externs,
node.Usings,
node.Members,
node.CloseBraceToken,
node.SemicolonToken);
return base.VisitNamespaceDeclaration(newNode);
}