コード例 #1
0
ファイル: import.cs プロジェクト: furesoft/NRefactory
		protected void ImportTypes (MetaType[] types, Namespace targetNamespace, bool importExtensionTypes)
		{
			Namespace ns = targetNamespace;
			string prev_namespace = null;
			foreach (var t in types) {
				if (t == null)
					continue;

				// Be careful not to trigger full parent type loading
				if (t.MemberType == MemberTypes.NestedType)
					continue;

				if (t.Name[0] == '<')
					continue;

				var it = CreateType (t, null, new DynamicTypeReader (t), true);
				if (it == null)
					continue;

				if (prev_namespace != t.Namespace) {
					ns = t.Namespace == null ? targetNamespace : targetNamespace.GetNamespace (t.Namespace, true);
					prev_namespace = t.Namespace;
				}

				// Cannot rely on assembly level Extension attribute or static modifier because they
				// are not followed by other compilers (e.g. F#).
				if (it.IsClass && it.Arity == 0 && importExtensionTypes &&
					HasAttribute (CustomAttributeData.GetCustomAttributes (t), "ExtensionAttribute", CompilerServicesNamespace)) {
					it.SetExtensionMethodContainer ();
				}

				ns.AddType (module, it);
			}
		}
コード例 #2
0
ファイル: namespace.cs プロジェクト: furesoft/NRefactory
		protected NamespaceContainer (ModuleContainer parent)
			: base (parent, null, null, MemberKind.Namespace)
		{
			ns = parent.GlobalRootNamespace;
			containers = new List<TypeContainer> (2);
		}
コード例 #3
0
ファイル: namespace.cs プロジェクト: furesoft/NRefactory
		public void RegisterNamespace (Namespace child)
		{
			if (child != this)
				all_namespaces.Add (child.Name, child);
		}
コード例 #4
0
ファイル: namespace.cs プロジェクト: furesoft/NRefactory
		public NamespaceContainer (MemberName name, NamespaceContainer parent)
			: base (parent, name, null, MemberKind.Namespace)
		{
			this.RealMemberName = name;
			this.Parent = parent;
			this.ns = parent.NS.AddNamespace (name);

			containers = new List<TypeContainer> ();
		}
コード例 #5
0
ファイル: namespace.cs プロジェクト: furesoft/NRefactory
		// TODO: Replace with CreateNamespace where MemberName is created for the method call
		public Namespace GetNamespace (string name, bool create)
		{
			int pos = name.IndexOf ('.');

			Namespace ns;
			string first;
			if (pos >= 0)
				first = name.Substring (0, pos);
			else
				first = name;

			if (!namespaces.TryGetValue (first, out ns)) {
				if (!create)
					return null;

				ns = new Namespace (this, first);
				namespaces.Add (first, ns);
			}

			if (pos >= 0)
				ns = ns.GetNamespace (name.Substring (pos + 1), create);

			return ns;
		}
コード例 #6
0
ファイル: namespace.cs プロジェクト: furesoft/NRefactory
		public bool TryGetNamespace (string name, out Namespace ns)
		{
			return namespaces.TryGetValue (name, out ns);
		}
コード例 #7
0
ファイル: namespace.cs プロジェクト: furesoft/NRefactory
		Namespace TryAddNamespace (string name)
		{
			Namespace ns;

			if (!namespaces.TryGetValue (name, out ns)) {
				ns = new Namespace (this, name);
				namespaces.Add (name, ns);
			}

			return ns;
		}
コード例 #8
0
ファイル: namespace.cs プロジェクト: furesoft/NRefactory
		/// <summary>
		///   Constructor Takes the current namespace and the
		///   name.  This is bootstrapped with parent == null
		///   and name = ""
		/// </summary>
		public Namespace (Namespace parent, string name)
			: this ()
		{
			if (name == null)
				throw new ArgumentNullException ("name");

			this.parent = parent;

			string pname = parent != null ? parent.fullname : null;
				
			if (pname == null)
				fullname = name;
			else
				fullname = pname + "." + name;

			while (parent.parent != null)
				parent = parent.parent;

			var root = parent as RootNamespace;
			if (root == null)
				throw new InternalErrorException ("Root namespaces must be created using RootNamespace");

			root.RegisterNamespace (this);
		}