Mono.CSharp.Namespace.GetNamespace C# (CSharp) Method

GetNamespace() public method

public GetNamespace ( string name, bool create ) : Namespace
name string
create bool
return Namespace
		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;
		}

Usage Example

Example #1
0
		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);
			}
		}
All Usage Examples Of Mono.CSharp.Namespace::GetNamespace