Mono.CSharp.MetadataImporter.ImportType C# (CSharp) Method

ImportType() private method

private ImportType ( Type type, DynamicTypeReader dtype ) : System.TypeSpec
type IKVM.Reflection.Type
dtype DynamicTypeReader
return System.TypeSpec
        TypeSpec ImportType(MetaType type, DynamicTypeReader dtype)
        {
            if (type.HasElementType) {
                var element = type.GetElementType ();
                ++dtype.Position;
                var spec = ImportType (element, dtype);

                if (type.IsArray)
                    return ArrayContainer.MakeType (module, spec, type.GetArrayRank ());
                if (type.IsByRef)
                    return ReferenceContainer.MakeType (spec);
                if (type.IsPointer)
                    return PointerContainer.MakeType (spec);

                throw new NotImplementedException ("Unknown element type " + type.ToString ());
            }

            return CreateType (type, dtype, true);
        }

Same methods

MetadataImporter::ImportType ( Type type ) : System.TypeSpec

Usage Example

Ejemplo n.º 1
0
			public static AttributesBag Read (MemberInfo mi, MetadataImporter importer)
			{
				AttributesBag bag = null;
				List<string> conditionals = null;

				// It should not throw any loading exception
				IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (mi);

				foreach (var a in attrs) {
					var dt = a.Constructor.DeclaringType;
					string name = dt.Name;
					if (name == "ObsoleteAttribute") {
						if (dt.Namespace != "System")
							continue;

						if (bag == null)
							bag = new AttributesBag ();

						var args = a.ConstructorArguments;

						if (args.Count == 1) {
							bag.Obsolete = new ObsoleteAttribute ((string) args[0].Value);
						} else if (args.Count == 2) {
							bag.Obsolete = new ObsoleteAttribute ((string) args[0].Value, (bool) args[1].Value);
						} else {
							bag.Obsolete = new ObsoleteAttribute ();
						}

						continue;
					}

					if (name == "ConditionalAttribute") {
						if (dt.Namespace != "System.Diagnostics")
							continue;

						if (bag == null)
							bag = new AttributesBag ();

						if (conditionals == null)
							conditionals = new List<string> (2);

						conditionals.Add ((string) a.ConstructorArguments[0].Value);
						continue;
					}

					if (name == "CLSCompliantAttribute") {
						if (dt.Namespace != "System")
							continue;

						if (bag == null)
							bag = new AttributesBag ();

						bag.CLSAttributeValue = (bool) a.ConstructorArguments[0].Value;
						continue;
					}

					// Type only attributes
					if (mi.MemberType == MemberTypes.TypeInfo || mi.MemberType == MemberTypes.NestedType) {
						if (name == "DefaultMemberAttribute") {
							if (dt.Namespace != "System.Reflection")
								continue;

							if (bag == null)
								bag = new AttributesBag ();

							bag.DefaultIndexerName = (string) a.ConstructorArguments[0].Value;
							continue;
						}

						if (name == "AttributeUsageAttribute") {
							if (dt.Namespace != "System")
								continue;

							if (bag == null)
								bag = new AttributesBag ();

							bag.AttributeUsage = new AttributeUsageAttribute ((AttributeTargets) a.ConstructorArguments[0].Value);
							foreach (var named in a.NamedArguments) {
								if (named.MemberInfo.Name == "AllowMultiple")
									bag.AttributeUsage.AllowMultiple = (bool) named.TypedValue.Value;
								else if (named.MemberInfo.Name == "Inherited")
									bag.AttributeUsage.Inherited = (bool) named.TypedValue.Value;
							}
							continue;
						}

						// Interface only attribute
						if (name == "CoClassAttribute") {
							if (dt.Namespace != "System.Runtime.InteropServices")
								continue;

							if (bag == null)
								bag = new AttributesBag ();

							bag.CoClass = importer.ImportType ((MetaType) a.ConstructorArguments[0].Value);
							continue;
						}
					}
				}

				if (bag == null)
					return Default;

				if (conditionals != null)
					bag.Conditionals = conditionals.ToArray ();
				
				return bag;
			}