NamespaceNode

Namespace: WebGrease
We found 10 examples in language CSharp for this search. You will see 24 fragments of code.

        protected NamespaceNode AllocateNamespaceNode(IdentifierToken identifier)
        {
            NamespaceNode namespaceNode = new NamespaceNode(identifier);
            Leaves.Add(namespaceNode);
            return namespaceNode;
        }

        protected bool FindNamespaceNode(IdentifierToken identifier, [NotNullWhen(true)] out NamespaceNode? namespaceNode)
        {
            namespaceNode = Leaves.FirstOrDefault(node => node is NamespaceNode nsNode && nsNode.Identifier.Equals(identifier)) as NamespaceNode;
            return namespaceNode is not null;
        }





        /// <summary>
        /// 根据命名空间和类的位置获取类型
        /// </summary>
        /// <param name="namespaceNode">命名空间节点</param>
        /// <param name="index">命名空间里的第index-1个 类</param>
        /// <returns></returns>
        internal static string? GetClassName(this SyntaxNode namespaceNode, int index = 0)
        {

            return GetDataStructString<ClassDeclarationSyntax>(namespaceNode, index);

        }




        /// <summary>
        /// 根据命名空间和结构体的位置获取类型
        /// </summary>
        /// <param name="namespaceNode">命名空间节点</param>
        /// <param name="index">命名空间里的第index-1个 结构体</param>
        /// <returns></returns>
        internal static string? GetStructName(this SyntaxNode namespaceNode, int index = 0)
        {

            return GetDataStructString<StructDeclarationSyntax>(namespaceNode, index);

        }


        /// <summary>
        /// 根据命名空间和记录的位置获取类型
        /// </summary>
        /// <param name="namespaceNode">命名空间节点</param>
        /// <param name="index">命名空间里的第index-1个 Record</param>
        /// <returns></returns>
        internal static string? GetRecordName(this SyntaxNode namespaceNode, int index = 0)
        {

            return GetDataStructString<RecordDeclarationSyntax>(namespaceNode, index);

        }




        /// <summary>
        /// 根据命名空间和接口的位置获取类型
        /// </summary>
        /// <param name="namespaceNode">命名空间节点</param>
        /// <param name="index">命名空间里的第index-1个接口</param>
        /// <returns></returns>
        internal static string GetInterfaceName(this SyntaxNode namespaceNode, int index = 0)
        {

            return GetDataStructString<InterfaceDeclarationSyntax>(namespaceNode, index);

        }




        /// <summary>
        /// 根据命名空间和枚举的位置获取类型
        /// </summary>
        /// <param name="namespaceNode">命名空间节点</param>
        /// <param name="index">命名空间里的第index-1个枚举</param>
        /// <returns></returns>
        internal static string GetEnumName(this SyntaxNode namespaceNode, int index = 0)
        {

            return GetDataStructString<EnumDeclarationSyntax>(namespaceNode, index);

        }



        private static string GetDataStructString<T>(SyntaxNode namespaceNode, int index = 0) where T : BaseTypeDeclarationSyntax
        {

            var nodes = GetNodes<T>(namespaceNode);
            var node = nodes.ElementAtOrDefault(index);
            if (node != null)
            {
                return node.Identifier.Text;
            }
            return string.Empty;

        }


		private void PopulateTypes()
		{
			foreach (Type type in assembly.GetTypes()) {
				if (!type.IsVisible) continue;
				string name = type.Namespace ?? "-";
				NamespaceNode node = GetNamespace(name);
				if (node == null) {
					node = new NamespaceNode(name);
					namespaces.Add(node);
				}
				node.Types.Add(new TypeNode(type));
			}
			namespaces.Sort(Compare);
		}

		private int Compare(NamespaceNode a, NamespaceNode b)
		{
			return a.Name.CompareTo(b.Name);
		}

		private NamespaceNode GetNamespace(string name)
		{
			foreach (NamespaceNode space in namespaces) {
				if (space.Name == name) {
					return space;
				}
			}
			return null;
		}

using System.Collections.Generic;
using System.Threading;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindSymbols
{
    internal partial class SymbolTreeInfo
    {
        public struct SearchResult
        {
            public LinkedList<NamespaceNode> NamespaceNodes { get; private set; }
            public LinkedList<TypeNode> TypeNodes { get; private set; }
            public string MemberName { get; private set; }

            public SearchResult(NamespaceNode namespaceNode = null, TypeNode typeNode = null, string memberName = null)
                : this()
            {
                this.NamespaceNodes = new LinkedList<NamespaceNode>();
                this.TypeNodes = new LinkedList<TypeNode>();

                if (namespaceNode != null)
                {
                    this.NamespaceNodes.AddFirst(namespaceNode);
                }

                if (typeNode != null)
                {
                    this.TypeNodes.AddFirst(typeNode);
                }

                this.MemberName = memberName;
            }
        }
    }
}


        public override string Emit()
        {
            StringBuilder imports = new();

            foreach (Import import in Imports) imports.Append(import.Emit()).Append('\n');

            return $"{imports}\n{NamespaceNode.Emit()}";
        }

        public override string ToString() 
        {
            StringBuilder importsString = new();

            foreach (Import import in Imports) importsString.Append(import.ToString());

            return $"Program(Imports({importsString});{NamespaceNode});";
        }


    private bool TryAdd(NamespaceNode node, out NamespaceNode existing)
    {
      if (!m_nodes.TryAdd(node.DisplayName, node) && m_nodes[node.DisplayName] is NamespaceNode namespaceNode)
      {
        existing = namespaceNode;
        return false;
      }

      existing = node;

      return true;
    }

using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindSymbols
{
    internal partial class SymbolTreeInfo
    {
        public sealed class NamespaceNode
        {
            public string Name { get; private set; }
            internal List<NamespaceNode> Namespaces { get; private set; }
            internal List<TypeNode> Types { get; private set; }

            internal NamespaceNode(string name, List<NamespaceNode> namespaces, List<TypeNode> types)
            {
                if (name == null)
                {
                    throw new ArgumentNullException("name");
                }

                this.Name = name;
                this.Namespaces = namespaces;
                this.Types = types;
            }
        }
    }
}


		static bool CanExecute(DocumentTreeNodeData[] nodes) =>
			nodes is not null &&
			nodes.Length > 0 &&
			nodes.All(a => a is NamespaceNode);

		static void Execute(Lazy<IUndoCommandService> undoCommandService, DocumentTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var nsNodes = nodes.Cast<NamespaceNode>().ToArray();
			undoCommandService.Value.Add(new DeleteNamespaceCommand(nsNodes));
		}

		static bool CanExecute(DocumentTreeNodeData[] nodes) =>
			nodes is not null &&
			nodes.Length > 0 &&
			nodes.All(a => a is NamespaceNode) &&
			nodes.Any(a => ((NamespaceNode)a).Name != string.Empty) &&
			IsInSameModule(nodes) &&
			nodes[0].TreeNode.Parent is not null &&
			nodes[0].TreeNode.Parent!.DataChildren.Any(a => a is NamespaceNode && ((NamespaceNode)a).Name == string.Empty);

		NamespaceNode? GetTarget() => nodes.Nodes.Length == 0 ? null : (NamespaceNode)nodes.Nodes[0].TreeNode.Parent!.DataChildren.First(a => a is NamespaceNode && ((NamespaceNode)a).Name == string.Empty);

		static bool CanExecute(DocumentTreeNodeData[] nodes) =>
			nodes is not null &&
			nodes.Length == 1 &&
			nodes[0] is NamespaceNode;

		internal static TypeRefInfo[] GetTypeRefInfos(ModuleDef module, IEnumerable<NamespaceNode> nsNodes) {
			var types = new HashSet<ITypeDefOrRef>(RefFinder.TypeEqualityComparerInstance);
			foreach (var nsNode in nsNodes) {
				foreach (TypeNode typeNode in nsNode.TreeNode.DataChildren)
					types.Add(typeNode.TypeDef);
			}
			var typeRefs = RefFinder.FindTypeRefsToThisModule(module);
			return typeRefs.Where(a => types.Contains(a)).Select(a => new TypeRefInfo(a)).ToArray();
		}


		private void LoadNamespace(ElementNode elementNode)
		{

			foreach (Node childNode in elementNode)
				if (childNode is NamespaceNode)
				{
					NamespaceNode namespaceNode = childNode as NamespaceNode;
					string namespacePrefix = namespaceNode.localName == "xmlns" ? string.Empty : namespaceNode.localName;
					this.xmlNamespaceManager.AddNamespace(namespacePrefix, namespaceNode.Value);
				}

			this.xmlNamespaceManager.PushScope();

		}


		private void LoadNamespace(ElementNode elementNode)
		{

			foreach (Node childNode in elementNode)
				if (childNode is NamespaceNode)
				{
					NamespaceNode namespaceNode = childNode as NamespaceNode;
					string namespacePrefix = namespaceNode.localName == "xmlns" ? string.Empty : namespaceNode.localName;
					this.xmlNamespaceManager.AddNamespace(namespacePrefix, namespaceNode.Value);
				}

			this.xmlNamespaceManager.PushScope();

		}

WebGrease.Css.Ast.NamespaceNode : AstNode

Constructors :

public NamespaceNode(String prefix = , String value = )

Methods :

public String get_Prefix()
public String get_Value()
public AstNode Accept(NodeVisitor nodeVisitor = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()