当前位置: 首页>>代码示例>>C#>>正文


C# Type.GetElementType方法代码示例

本文整理汇总了C#中IKVM.Reflection.Type.GetElementType方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetElementType方法的具体用法?C# Type.GetElementType怎么用?C# Type.GetElementType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IKVM.Reflection.Type的用法示例。


在下文中一共展示了Type.GetElementType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsReflectionOnly

		internal static bool IsReflectionOnly(Type type)
		{
			while (type.HasElementType)
			{
				type = type.GetElementType();
			}
			Assembly asm = type.Assembly;
			if (asm != null && asm.ReflectionOnly)
			{
				return true;
			}
			if (!type.IsGenericType || type.IsGenericTypeDefinition)
			{
				return false;
			}
			// we have a generic type instantiation, it might have ReflectionOnly type arguments
			foreach (Type arg in type.GetGenericArguments())
			{
				if (IsReflectionOnly(arg))
				{
					return true;
				}
			}
			return false;
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:25,代码来源:ReflectUtil.cs

示例2: ArrayDecorator

        public ArrayDecorator(TypeModel model, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, Type arrayType, bool overwriteList, bool supportNull)
            : base(tail)
        {
            Helpers.DebugAssert(arrayType != null, "arrayType should be non-null");
            Helpers.DebugAssert(arrayType.IsArray && arrayType.GetArrayRank() == 1, "should be single-dimension array; " + arrayType.FullName);
            this.itemType = arrayType.GetElementType();
#if NO_GENERICS
            Type underlyingItemType = itemType;
#else
            Type underlyingItemType = supportNull ? itemType : (Helpers.GetUnderlyingType(itemType) ?? itemType);
#endif

            Helpers.DebugAssert(underlyingItemType == Tail.ExpectedType, "invalid tail");
            Helpers.DebugAssert(Tail.ExpectedType != model.MapType(typeof(byte)), "Should have used BlobSerializer");
            if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
            if (!ListDecorator.CanPack(packedWireType))
            {
                if (writePacked) throw new InvalidOperationException("Only simple data-types can use packed encoding");
                packedWireType = WireType.None;
            }       
            this.fieldNumber = fieldNumber;
            this.packedWireType = packedWireType;
            if (writePacked) options |= OPTIONS_WritePacked;
            if (overwriteList) options |= OPTIONS_OverwriteList;
            if (supportNull) options |= OPTIONS_SupportNull;
            this.arrayType = arrayType;
        }
开发者ID:CragonGame,项目名称:GameCloud.IM,代码行数:27,代码来源:ArrayDecorator.cs

示例3: ContainsTypeBuilder

 internal static bool ContainsTypeBuilder(Type type)
 {
     while (type.HasElementType)
     {
         type = type.GetElementType();
     }
     if (!type.IsGenericType || type.IsGenericTypeDefinition)
     {
         return type is TypeBuilder;
     }
     foreach (Type arg in type.GetGenericArguments())
     {
         if (ContainsTypeBuilder(arg))
         {
             return true;
         }
     }
     return type.GetGenericTypeDefinition() is TypeBuilder;
 }
开发者ID:LogosBible,项目名称:ikvm-fork,代码行数:19,代码来源:ReflectUtil.cs

示例4: AppendCATypeName

 void AppendCATypeName(StringBuilder sb, Type type, string typeName, bool securityCompatHack = false)
 {
     if (type.IsArray)
     {
         AppendCATypeName(sb, type.GetElementType(), null);
         sb.Append("[]");
     }
     else if (type == typeofSystemBoolean)
     {
         sb.Append("bool");
     }
     else if (type == typeofSystemSByte)
     {
         sb.Append("int8");
     }
     else if (type == typeofSystemByte)
     {
         sb.Append("uint8");
     }
     else if (type == typeofSystemChar)
     {
         sb.Append("char");
     }
     else if (type == typeofSystemInt16)
     {
         sb.Append("int16");
     }
     else if (type == typeofSystemUInt16)
     {
         sb.Append("uint16");
     }
     else if (type == typeofSystemInt32)
     {
         sb.Append("int32");
     }
     else if (type == typeofSystemUInt32)
     {
         sb.Append("uint32");
     }
     else if (type == typeofSystemInt64)
     {
         sb.Append("int64");
     }
     else if (type == typeofSystemUInt64)
     {
         sb.Append("uint64");
     }
     else if (type == typeofSystemSingle)
     {
         sb.Append("float32");
     }
     else if (type == typeofSystemDouble)
     {
         sb.Append("float64");
     }
     else if (type == typeofSystemString)
     {
         sb.Append("string");
     }
     else if (type == typeofSystemObject)
     {
         sb.Append("object");
     }
     else if (type.FullName == "System.Type" && type.Assembly.GetName().Name == "mscorlib")
     {
         sb.Append("type");
     }
     else
     {
         sb.Append("enum ");
         AppendTypeName(sb, type, typeName, false, securityCompatHack);
     }
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:73,代码来源:CABlob.cs

示例5: ReadFixedArg

 void ReadFixedArg(StringBuilder sb, ByteReader br, Type type, bool arrayElement = false)
 {
     if (type.IsArray)
     {
         int length = br.ReadInt32();
         if (length == -1 && compat == CompatLevel.None)
         {
             sb.Append("nullref");
         }
         else if (length == 0 && compat != CompatLevel.None)
         {
             throw new IKVM.Reflection.BadImageFormatException();
         }
         else
         {
             Type elementType = type.GetElementType();
             AppendCATypeName(sb, elementType, null);
             sb.AppendFormat("[{0}](", length);
             for (int i = 0; i < length; i++)
             {
                 if (i != 0)
                 {
                     sb.Append(' ');
                 }
                 if (elementType == typeofSystemObject)
                 {
                     string typeName;
                     ReadFixedArg(sb, br, ReadFieldOrPropType(sb, br, out typeName), false);
                 }
                 else
                 {
                     ReadFixedArg(sb, br, elementType, true);
                 }
             }
             sb.Append(')');
         }
     }
     else if (type.FullName == "System.Type" && type.Assembly.GetName().Name == "mscorlib")
     {
         if (!arrayElement)
         {
             AppendCATypeName(sb, type, null);
             sb.Append('(');
         }
         string typeName;
         var type1 = ReadType(br, out typeName);
         if (type1 == null)
         {
             if (typeName == null)
             {
                 sb.Append("nullref");
             }
             else
             {
                 sb.Append("class ").Append(QuoteIdentifier(typeName, true));
             }
         }
         else
         {
             AppendTypeName(sb, type1, typeName, compat != CompatLevel.None && IsNestedTypeWithNamespace(type1));
         }
         if (!arrayElement)
         {
             sb.Append(')');
         }
     }
     else if (type.Assembly == mscorlib)
     {
         if (!arrayElement)
         {
             AppendCATypeName(sb, type, null);
             sb.Append('(');
         }
         if (type == typeofSystemBoolean)
         {
             sb.Append(br.ReadByte() == 0 ? "false" : "true");
         }
         else if (type == typeofSystemByte)
         {
             sb.Append(br.ReadByte());
         }
         else if (type == typeofSystemSByte)
         {
             sb.Append(br.ReadSByte());
         }
         else if (type == typeofSystemChar)
         {
             sb.AppendFormat("0x{0:X4}", (int)br.ReadChar());
         }
         else if (type == typeofSystemInt16)
         {
             sb.Append(br.ReadInt16());
         }
         else if (type == typeofSystemUInt16)
         {
             sb.Append(br.ReadUInt16());
         }
         else if (type == typeofSystemInt32)
         {
             sb.Append(br.ReadInt32());
//.........这里部分代码省略.........
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:101,代码来源:CABlob.cs

示例6: IsTypeBuilder

		private static bool IsTypeBuilder(Type type)
		{
			return type is TypeBuilder || (type.HasElementType && IsTypeBuilder(type.GetElementType()));
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:4,代码来源:RuntimeHelperTypes.cs

示例7: MapType

				private static TypeWrapper MapType(Type type, bool isArray)
				{
					if (type == Types.String)
					{
						return CoreClasses.java.lang.String.Wrapper;
					}
					else if (type == Types.Boolean)
					{
						return PrimitiveTypeWrapper.BOOLEAN;
					}
					else if (type == Types.Byte)
					{
						return PrimitiveTypeWrapper.BYTE;
					}
					else if (type == Types.Char)
					{
						return PrimitiveTypeWrapper.CHAR;
					}
					else if (type == Types.Int16)
					{
						return PrimitiveTypeWrapper.SHORT;
					}
					else if (type == Types.Int32)
					{
						return PrimitiveTypeWrapper.INT;
					}
					else if (type == Types.Single)
					{
						return PrimitiveTypeWrapper.FLOAT;
					}
					else if (type == Types.Int64)
					{
						return PrimitiveTypeWrapper.LONG;
					}
					else if (type == Types.Double)
					{
						return PrimitiveTypeWrapper.DOUBLE;
					}
					else if (type == Types.Type)
					{
						return CoreClasses.java.lang.Class.Wrapper;
					}
					else if (type.IsEnum)
					{
						foreach (TypeWrapper tw in ClassLoaderWrapper.GetWrapperFromType(type).InnerClasses)
						{
							if (tw is EnumEnumTypeWrapper)
							{
								if (!isArray && type.IsDefined(JVM.Import(typeof(FlagsAttribute)), false))
								{
									return tw.MakeArrayType(1);
								}
								return tw;
							}
						}
						throw new InvalidOperationException();
					}
					else if (!isArray && ReflectUtil.IsVector(type))
					{
						return MapType(type.GetElementType(), true).MakeArrayType(1);
					}
					else
					{
						throw new NotImplementedException();
					}
				}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:66,代码来源:DotNetTypeWrapper.cs

示例8: EmitGetHelper

        internal void EmitGetHelper(Operand op, Type desiredType, Conversion conv, Type from = null)
        {
            if (conv == null)
            {
                EmitGetHelper(op, desiredType, false);
                return;
            }

            EmitGetHelper_Conversion(op, desiredType.IsByRef ? desiredType.GetElementType() : desiredType, conv, from);
            if (desiredType.IsByRef)
                EmitGetHelper_Ref(op, desiredType);
        }
开发者ID:AqlaSolutions,项目名称:runsharp,代码行数:12,代码来源:CodeGen.Helpers.cs

示例9: IsPointerType

		private static bool IsPointerType(Type type)
		{
			while (type.HasElementType)
			{
				if (type.IsPointer)
				{
					return true;
				}
				type = type.GetElementType();
			}
			return false;
		}
开发者ID:ikvm,项目名称:IKVM.NET-cvs-clone,代码行数:12,代码来源:DotNetTypeWrapper.cs

示例10: GetImplicit

        // the sections mentioned in comments of this method are from C# specification v1.2
		public static Conversion GetImplicit(Operand op, Type to, bool onlyStandard, ITypeMapper typeMapper)
		{
			Type from = Operand.GetType(op, typeMapper);

            Type toUnderlying = Helpers.GetNullableUnderlyingType(to);
		    if (to.Equals(from))
		        return new Direct(typeMapper);

            Type fromUnderlying = Helpers.GetNullableUnderlyingType(@from);
		    if (toUnderlying != null)
		    {
		        if (fromUnderlying != null)
		        {
		            Conversion c = GetImplicit(new FakeTypedOperand(fromUnderlying), toUnderlying, onlyStandard, typeMapper);
		            if (c.IsValid) return new ConvertNullable(typeMapper, c);
		        }
		        else
		        {
                    Conversion c = GetImplicit(op, toUnderlying, onlyStandard, typeMapper);
                    if (c.IsValid) return new WrapNullable(typeMapper, c);
                }
		    }
            
		    // required for arrays created from TypeBuilder-s
			if (from != null && to.IsArray && from.IsArray)
			{
				if (to.GetArrayRank() == from.GetArrayRank())
				{
					if (to.GetElementType().Equals(from.GetElementType()))
						return new Direct(typeMapper);
				}
			}

			TypeCode tcFrom = Type.GetTypeCode(from);
			TypeCode tcTo = Type.GetTypeCode(to);
			byte ct = _convTable[(int)tcFrom][(int)tcTo];

			// section 6.1.2 - Implicit numeric conversions
			if (from != null && (from.IsPrimitive || Helpers.AreTypesEqual(from, typeof(decimal), typeMapper)) && (to.IsPrimitive || Helpers.AreTypesEqual(to, typeof(decimal), typeMapper)))
			{
				if (ct <= I)
				{
				    if (Helpers.AreTypesEqual(from, typeof(decimal), typeMapper) || Helpers.AreTypesEqual(to, typeof(decimal), typeMapper))
						// decimal is handled as user-defined conversion, but as it is a standard one, always enable UDC processing
						onlyStandard = false;
					else
						return new Primitive(typeMapper);
				}
			}

			IntLiteral intLit = op as IntLiteral;

			// section 6.1.3 - Implicit enumeration conversions
			if (!onlyStandard && to.IsEnum && (object)intLit != null && intLit.Value == 0)
				return new Primitive(typeMapper);

			// section 6.1.4 - Implicit reference conversions
			if ((from == null || !from.IsValueType) && !to.IsValueType)
			{
				if (from == null) // from the null type to any reference type
					return new Direct(typeMapper);

				if (to.IsAssignableFrom(from))	// the rest
					return new Direct(typeMapper);
			}

			if (from == null)	// no other conversion from null type is possible
				return new Invalid(typeMapper);

			// section 6.1.5 - Boxing conversions
			if (from.IsValueType)
			{
				if (to.IsAssignableFrom(from))
					return new Boxing(typeMapper);
			}

			// section 6.1.6 - Implicit constant expression conversions
			if ((object)intLit != null && Helpers.AreTypesEqual(from, typeof(int), typeMapper) && to.IsPrimitive)
			{
				int val = intLit.Value;

				switch (tcTo)
				{
					case TypeCode.SByte:
						if (val >= sbyte.MinValue && val <= sbyte.MaxValue)
							return new Direct(typeMapper);
						break;
					case TypeCode.Byte:
						if (val >= byte.MinValue && val <= byte.MaxValue)
                            return new Direct(typeMapper);
                        break;
					case TypeCode.Int16:
						if (val >= short.MinValue && val <= short.MaxValue)
                            return new Direct(typeMapper);
                        break;
					case TypeCode.UInt16:
						if (val >= ushort.MinValue && val <= ushort.MaxValue)
                            return new Direct(typeMapper);
                        break;
//.........这里部分代码省略.........
开发者ID:AqlaSolutions,项目名称:runsharp,代码行数:101,代码来源:Conversion.cs

示例11: GetMissingType

 internal static Type GetMissingType(Type type)
 {
     while (type.HasElementType)
     {
         type = type.GetElementType();
     }
     if (type.__IsMissing)
     {
         return type;
     }
     else if (type.__ContainsMissingType)
     {
         if (type.IsGenericType)
         {
             foreach (Type arg in type.GetGenericArguments())
             {
                 Type t1 = GetMissingType(arg);
                 if (t1.__IsMissing)
                 {
                     return t1;
                 }
             }
         }
         throw new NotImplementedException(type.FullName);
     }
     else
     {
         return type;
     }
 }
开发者ID:xamidi,项目名称:ikvm,代码行数:30,代码来源:ReflectUtil.cs

示例12: FormatType

	// TODO: fine tune this so that our output is less verbose. We need to figure
	// out a way to do this while not making things confusing.
	string FormatType (Type t)
	{
		if (t == null)
			return "";

		string type = GetFullName (t);
		if (type == null)
			return t.ToString ();
		
		if (!type.StartsWith ("System.")) {
			if (type.IndexOf (".") == -1)
				return type;
			if (t.GetNamespace () == this.t.GetNamespace ())
				return t.Name;
			return type;
		}
		
		if (t.HasElementType) {
			Type et = t.GetElementType ();
			if (t.IsArray)
				return FormatType (et) + " []";
			if (t.IsPointer)
				return FormatType (et) + " *";
			if (t.IsByRef)
				return "ref " + FormatType (et);
		}
	
		switch (type) {
		case "System.Byte": return "byte";
		case "System.SByte": return "sbyte";
		case "System.Int16": return "short";
		case "System.Int32": return "int";
		case "System.Int64": return "long";
			
		case "System.UInt16": return "ushort";
		case "System.UInt32": return "uint";
		case "System.UInt64": return "ulong";
			
		case "System.Single":  return "float";
		case "System.Double":  return "double";
		case "System.Decimal": return "decimal";
		case "System.Boolean": return "bool";
		case "System.Char":    return "char";
		case "System.String":  return "string";
			
		case "System.Object":  return "object";
		case "System.Void":  return "void";
		}
	
		if (type.LastIndexOf(".") == 6)
			return type.Substring(7);

		//
		// If the namespace of the type is the namespace of what
		// we are printing (or is a member of one if its children
		// don't print it. This basically means that in C# we would
		// automatically get the namespace imported by virtue of the
		// namespace {} block.
		//	
		if (this.t.Namespace.StartsWith (t.Namespace + ".") || t.Namespace == this.t.Namespace)
			return type.Substring (t.Namespace.Length + 1);
	
		return type;
	}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:66,代码来源:outline.cs

示例13: EmitGetHelper_Ref

        void EmitGetHelper_Ref(Operand op, Type desiredType)
        {
            if (ReferenceEquals(op, null))
                throw new ArgumentException("Ref argument can't be null, expected " + desiredType.Name);
            if (op.GetReturnType(TypeMapper) != desiredType.GetElementType())
                throw new InvalidOperationException(Properties.Messages.ErrByRefTypeMismatch);

            op.EmitAddressOf(this);
        }
开发者ID:AqlaSolutions,项目名称:runsharp,代码行数:9,代码来源:CodeGen.Helpers.cs

示例14: ResolveListTypes

        internal void ResolveListTypes(Type type, ref Type itemType, ref Type defaultType)
        {
            if (type == null) return;
            if(Helpers.GetTypeCode(type) != ProtoTypeCode.Unknown) return; // don't try this[type] for inbuilts
            if(this[type].IgnoreListHandling) return;

            // handle arrays
            if (type.IsArray)
            {
                if (type.GetArrayRank() != 1)
                {
                    throw new NotSupportedException("Multi-dimension arrays are supported");
                }
                itemType = type.GetElementType();
                if (itemType == MapType(typeof(byte)))
                {
                    defaultType = itemType = null;
                }
                else
                {
                    defaultType = type;
                }
            }
            // handle lists
            if (itemType == null) { itemType = TypeModel.GetListItemType(this, type); }

            // check for nested data (not allowed)
            if (itemType != null)
            {
                Type nestedItemType = null, nestedDefaultType = null;
                ResolveListTypes(itemType, ref nestedItemType, ref nestedDefaultType);
                if (nestedItemType != null)
                {
                    throw TypeModel.CreateNestedListsNotSupported();
                }
            }

            if (itemType != null && defaultType == null)
            {
#if WINRT
                System.Reflection.TypeInfo typeInfo = System.Reflection.IntrospectionExtensions.GetTypeInfo(type);
                if (typeInfo.IsClass && !typeInfo.IsAbstract && Helpers.GetConstructor(typeInfo, Helpers.EmptyTypes, true) != null)
#else
                if (type.IsClass && !type.IsAbstract && Helpers.GetConstructor(type, Helpers.EmptyTypes, true) != null)
#endif
                {
                    defaultType = type;
                }
                if (defaultType == null)
                {
#if WINRT
                    if (typeInfo.IsInterface)
#else
                    if (type.IsInterface)
#endif
                    {
#if NO_GENERICS
                        defaultType = typeof(ArrayList);
#else
                        Type[] genArgs;
#if WINRT
                        if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IDictionary<,>)
                            && itemType == typeof(System.Collections.Generic.KeyValuePair<,>).MakeGenericType(genArgs = typeInfo.GenericTypeArguments))
#else
                        if (type.IsGenericType && type.GetGenericTypeDefinition() == MapType(typeof(System.Collections.Generic.IDictionary<,>))
                            && itemType == MapType(typeof(System.Collections.Generic.KeyValuePair<,>)).MakeGenericType(genArgs = type.GetGenericArguments()))
#endif
                        {
                            defaultType = MapType(typeof(System.Collections.Generic.Dictionary<,>)).MakeGenericType(genArgs);
                        }
                        else
                        {
                            defaultType = MapType(typeof(System.Collections.Generic.List<>)).MakeGenericType(itemType);
                        }
#endif
                    }
                }
                // verify that the default type is appropriate
                if (defaultType != null && !Helpers.IsAssignableFrom(type, defaultType)) { defaultType = null; }
            }
        }
开发者ID:SimonPStevens,项目名称:protobuf-net,代码行数:81,代码来源:RuntimeTypeModel.cs

示例15: IsPointerType

		private static bool IsPointerType(Type type)
		{
			while (type.HasElementType)
			{
				if (type.IsPointer)
				{
					return true;
				}
				type = type.GetElementType();
			}
#if STATIC_COMPILER || STUB_GENERATOR
			return type.__IsFunctionPointer;
#else
			return false;
#endif
		}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:16,代码来源:DotNetTypeWrapper.cs


注:本文中的IKVM.Reflection.Type.GetElementType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。