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


C# Type.GetArrayRank方法代码示例

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


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

示例1: CodeTypeReference

		public CodeTypeReference (Type baseType)
		{
			if (baseType == null) {
				throw new ArgumentNullException ("baseType");
			}

			if (baseType.IsGenericParameter) {
				this.baseType = baseType.Name;
				this.referenceOptions = CodeTypeReferenceOptions.GenericTypeParameter;
			}
			else if (baseType.IsGenericTypeDefinition)
				this.baseType = baseType.FullName;
			else if (baseType.IsGenericType) {
				this.baseType = baseType.GetGenericTypeDefinition ().FullName;
				foreach (Type arg in baseType.GetGenericArguments ()) {
					if (arg.IsGenericParameter)
						TypeArguments.Add (new CodeTypeReference (new CodeTypeParameter (arg.Name)));
					else
						TypeArguments.Add (new CodeTypeReference (arg));
				}
			}
			else if (baseType.IsArray) {
				this.arrayRank = baseType.GetArrayRank ();
				this.arrayElementType = new CodeTypeReference (baseType.GetElementType ());
				this.baseType = arrayElementType.BaseType;
			} else {
				Parse (baseType.FullName);
			}
			this.isInterface = baseType.IsInterface;
		}
开发者ID:NelsonSantos,项目名称:fyiReporting-Android,代码行数:30,代码来源:CodeTypeReference.cs

示例2: CodeTypeReference

	public CodeTypeReference(Type type)
			{
				if(!(type.IsArray))
				{
					baseType = type.FullName;
					arrayElementType = null;
					arrayRank = 0;
				}
				else
				{
					baseType = null;
					arrayElementType =
						new CodeTypeReference(type.GetElementType());
					arrayRank = type.GetArrayRank();
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:16,代码来源:CodeTypeReference.cs

示例3: AreAssignable

 //CONFORMING
 internal static bool AreAssignable(Type dest, Type src) {
     if (dest == src) {
         return true;
     }
     if (dest.IsAssignableFrom(src)) {
         return true;
     }
     if (dest.IsArray && src.IsArray && dest.GetArrayRank() == src.GetArrayRank() && AreReferenceAssignable(dest.GetElementType(), src.GetElementType())) {
         return true;
     }
     if (src.IsArray && dest.IsGenericType &&
         (dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IEnumerable<>)
         || dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IList<>)
         || dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.ICollection<>))
         && dest.GetGenericArguments()[0] == src.GetElementType()) {
         return true;
     }
     return false;
 }
开发者ID:joshholmes,项目名称:ironruby,代码行数:20,代码来源:TypeUtils.cs

示例4: GetItemType

 Type GetItemType(Type type)
 {
     if (type.IsArray)
     {
         if (type.GetArrayRank() != 1)
         {
             throw new NotSupportedException("Multi-dimension arrays are supported");
         }
         Type itemType = type.GetElementType();
         if (itemType == typeof(byte))
         {
             return null;    // byte[] 不作为数组处理
         }
         else
         {
             return itemType;
         }
     }
     return TypeModel.GetListItemType(RuntimeTypeModel.Default, type); ;
 }
开发者ID:wpszz,项目名称:CSLightForUnity,代码行数:20,代码来源:CSLightMng_ProtoBuf.cs

示例5: CodeTypeReference

        public CodeTypeReference(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (type.IsArray)
            {
                ArrayRank = type.GetArrayRank();
                ArrayElementType = new CodeTypeReference(type.GetElementType());
                _baseType = null;
            }
            else
            {
                InitializeFromType(type);
                ArrayRank = 0;
                ArrayElementType = null;
            }

            _isInterface = type.IsInterface;
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:22,代码来源:CodeTypeReference.cs

示例6: GenerateConvertToType


//.........这里部分代码省略.........
				else if(genExpectedType == typeof(EntitySet<>) && actualIsSequence)
				{
					if(elemType != genExpectedTypeArgs[0])
					{
						seqType = typeof(IEnumerable<>).MakeGenericType(genExpectedTypeArgs);
						this.GenerateConvertToType(actualType, seqType);
						actualType = seqType;
						elemType = genExpectedTypeArgs[0];
					}
					// loc = new EntitySet<E>(); loc.Assign(seq); loc
					LocalBuilder locSeq = gen.DeclareLocal(actualType);
					gen.Emit(OpCodes.Stloc, locSeq);

					ConstructorInfo ci = expectedType.GetConstructor(System.Type.EmptyTypes);
					Diagnostics.Debug.Assert(ci != null);
					gen.Emit(OpCodes.Newobj, ci);
					LocalBuilder locEs = gen.DeclareLocal(expectedType);
					gen.Emit(OpCodes.Stloc, locEs);

					gen.Emit(OpCodes.Ldloc, locEs);
					gen.Emit(OpCodes.Ldloc, locSeq);
					MethodInfo miAssign = expectedType.GetMethod("Assign", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { seqType }, null);
					Diagnostics.Debug.Assert(miAssign != null);
					gen.Emit(GetMethodCallOpCode(miAssign), miAssign);

					gen.Emit(OpCodes.Ldloc, locEs);
				}
				// do we have a sequence when we want something assignable from List<T>?
				else if(typeof(IEnumerable).IsAssignableFrom(expectedType) &&
						actualIsSequence &&
						expectedType.IsAssignableFrom(typeof(List<>).MakeGenericType(elemType))
					)
				{
					// new List<E>(seq)
					Type listType = typeof(List<>).MakeGenericType(elemType);
					ConstructorInfo ci = listType.GetConstructor(new Type[] { seqType });
					Diagnostics.Debug.Assert(ci != null);
					gen.Emit(OpCodes.Newobj, ci);
				}
				// do we have a sequence when we want T[]?
				else if(expectedType.IsArray && expectedType.GetArrayRank() == 1 &&
						!actualType.IsArray && seqType.IsAssignableFrom(actualType) &&
						expectedType.GetElementType().IsAssignableFrom(elemType)
					)
				{
					// seq.ToArray()
					MethodInfo miToArray = TypeSystem.FindSequenceMethod("ToArray", new Type[] { seqType }, elemType);
					Diagnostics.Debug.Assert(miToArray != null);
					gen.Emit(OpCodes.Call, miToArray);
				}
				// do we have a sequence when we want some other collection type?
				else if(expectedType.IsClass &&
						typeof(ICollection<>).MakeGenericType(elemType).IsAssignableFrom(expectedType) &&
						expectedType.GetConstructor(System.Type.EmptyTypes) != null &&
						seqType.IsAssignableFrom(actualType)
					)
				{
					throw Error.GeneralCollectionMaterializationNotSupported();
				}
				// do we have an int when we want a bool?
				else if(expectedType == typeof(bool) && actualType == typeof(int))
				{
					// expr != 0
					Label labZero = gen.DefineLabel();
					Label labExit = gen.DefineLabel();
					gen.Emit(OpCodes.Ldc_I4_0);
					gen.Emit(OpCodes.Ceq);
					gen.Emit(OpCodes.Brtrue_S, labZero);
					gen.Emit(OpCodes.Ldc_I4_1);
					gen.Emit(OpCodes.Br_S, labExit);
					gen.MarkLabel(labZero);
					gen.Emit(OpCodes.Ldc_I4_0);
					gen.MarkLabel(labExit);
				}
				else
				{
					// last-ditch attempt: convert at runtime using DBConvert
					// DBConvert.ChangeType(type, expr)
					if(actualType.IsValueType)
					{
						gen.Emit(OpCodes.Box, actualType);
					}
					gen.Emit(OpCodes.Ldtoken, expectedType);
					MethodInfo miGetTypeFromHandle = typeof(Type).GetMethod("GetTypeFromHandle", BindingFlags.Static | BindingFlags.Public);
					Diagnostics.Debug.Assert(miGetTypeFromHandle != null);
					gen.Emit(OpCodes.Call, miGetTypeFromHandle);
					MethodInfo miChangeType = typeof(DBConvert).GetMethod("ChangeType", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(object), typeof(Type) }, null);
					Diagnostics.Debug.Assert(miChangeType != null);
					gen.Emit(OpCodes.Call, miChangeType);
					if(expectedType.IsValueType)
					{
						gen.Emit(OpCodes.Unbox_Any, expectedType);
					}
					else if(expectedType != typeof(object))
					{
						gen.Emit(OpCodes.Castclass, expectedType);
					}
				}
			}
		}
开发者ID:modulexcite,项目名称:LinqToSQL2,代码行数:101,代码来源:DynamicTypeGenerator.cs

示例7: GetXmlType

		string GetXmlType (Type type)
		{
			if (type.IsArray)
			{
				string itemType = GetXmlType (type.GetElementType ());
				itemType = "ArrayOf" + char.ToUpper (itemType[0]) + itemType.Substring (1);
				if (type.GetArrayRank () > 1) itemType += type.GetArrayRank ();
				return itemType;
			}
			else
			{
				string name = null, ns;
				
				name = GetXsdType (type);
				if (name != null) return name;
				
				if (SoapServices.GetXmlTypeForInteropType (type, out name, out ns))
					return name;
					
				SoapTypeAttribute att = (SoapTypeAttribute) InternalRemotingServices.GetCachedSoapAttribute (type);
				return att.XmlTypeName;
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:MetaDataExporter.cs

示例8: InflateType

		internal static Type InflateType (Type type, Type[] type_args, Type[] method_args)
		{
			if (type == null)
				return null;
			if (!type.IsGenericParameter && !type.ContainsGenericParameters)
				return type;
			if (type.IsGenericParameter) {
				if (type.DeclaringMethod == null)
					return type_args == null ? type : type_args [type.GenericParameterPosition];
				return method_args == null ? type : method_args [type.GenericParameterPosition];
			}
			if (type.IsPointer)
				return InflateType (type.GetElementType (), type_args, method_args).MakePointerType ();
			if (type.IsByRef)
				return InflateType (type.GetElementType (), type_args, method_args).MakeByRefType ();
			if (type.IsArray) {
				if (type.GetArrayRank () > 1)
					return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (type.GetArrayRank ());
				
				if (type.ToString ().EndsWith ("[*]", StringComparison.Ordinal)) /*FIXME, the reflection API doesn't offer a way around this*/
					return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (1);
				return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType ();
			}

			Type[] args = type.GetGenericArguments ();
			for (int i = 0; i < args.Length; ++i)
				args [i] = InflateType (args [i], type_args, method_args);

			Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
			return gtd.MakeGenericType (args);
		}
开发者ID:carrie901,项目名称:mono,代码行数:31,代码来源:MonoGenericClass.cs

示例9: ChangeType

    public static object ChangeType(object obj, Type destType)
    {
        if (obj == null)
        {
            return null;
        }

        Type sourceType = obj.GetType();

        if (sourceType == destType)
        {
            return obj;
        }

        if (obj is ArrayList && destType.IsArray)
        {
            return ArrayListToArray(obj as ArrayList, destType.GetArrayRank(), destType.GetElementType());
        }
        else if (obj is ArrayList && destType == typeof(Hashtable))
        {
            return ArrayListToHashtable(obj as ArrayList);
        }
        else if ((!sourceType.IsByRef && destType.IsByRef) || (!sourceType.IsPointer && destType.IsPointer))
        {
            return Convert.ChangeType(obj, destType.GetElementType());
        }
        else
        {
            return Convert.ChangeType(obj, destType);
        }
    }
开发者ID:wenysky,项目名称:deepinsummer,代码行数:31,代码来源:PHPSerializer.cs

示例10: StripExpression

 private static Type StripExpression(Type type)
 {
     bool isArray = type.IsArray;
     Type tmp = isArray ? type.GetElementType() : type;
     Type eType = TypeHelper.FindGenericType(typeof(Expression<>), tmp);
     if (eType != null)
         tmp = eType.GetGenericArguments()[0];
     if (isArray)
     {
         int rank = type.GetArrayRank();
         return (rank == 1) ? tmp.MakeArrayType() : tmp.MakeArrayType(rank);
     }
     return type;
 }
开发者ID:rainersigwald,项目名称:corefx,代码行数:14,代码来源:EnumerableRewriter.cs

示例11: WriteObjectHeader

		// Write the object header information for a type.
		public override void WriteObjectHeader(BinaryValueContext context,
											   Object value, Type type,
											   long objectID, long prevObject)
				{
					BinaryPrimitiveTypeCode prim;
					BinaryArrayType atype;
					prim = GetPrimitiveTypeCode(type.GetElementType());
					atype = GetArrayType((Array)value, type);
					if(type == typeof(Object[]))
					{
						context.writer.Write
							((byte)(BinaryElementType.ArrayOfObject));
						context.writer.Write((int)objectID);
						context.writer.Write(((Array)value).GetLength(0));
					}
					else if(type == typeof(String[]))
					{
						context.writer.Write
							((byte)(BinaryElementType.ArrayOfString));
						context.writer.Write((int)objectID);
						context.writer.Write(((Array)value).GetLength(0));
					}
					else if(prim != (BinaryPrimitiveTypeCode)0 &&
							atype == BinaryArrayType.Single)
					{
						context.writer.Write
							((byte)(BinaryElementType.ArrayOfPrimitiveType));
						context.writer.Write((int)objectID);
						context.writer.Write(((Array)value).GetLength(0));
						context.writer.Write((byte)prim);
					}
					else
					{
						int rank = type.GetArrayRank();
						int dim;
						context.writer.Write
							((byte)(BinaryElementType.GenericArray));
						context.writer.Write((int)objectID);
						context.writer.Write((byte)atype);
						context.writer.Write(rank);
						for(dim = 0; dim < rank; ++dim)
						{
							context.writer.Write
								(((Array)value).GetLength(dim));
						}
						if(((int)atype) >= 3)
						{
							for(dim = 0; dim < rank; ++dim)
							{
								context.writer.Write
									(((Array)value).GetLowerBound(dim));
							}
						}
						BinaryValueWriter vw;
						type = type.GetElementType();
						vw = GetWriter(context, type);
						vw.WriteTypeTag(context, type);
						vw.WriteTypeSpec(context, type);
					}
				}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:61,代码来源:BinaryValueWriter.cs

示例12: GetPrimitiveTypeCode

		// Write the type specification for a type.
		public override void WriteTypeSpec
					(BinaryValueContext context, Type type)
				{
					if(type == typeof(Object[]) || type == typeof(String[]))
					{
						return;
					}
					else
					{
						BinaryPrimitiveTypeCode prim;
						prim = GetPrimitiveTypeCode(type.GetElementType());
						if(prim != (BinaryPrimitiveTypeCode)0 &&
						   type.GetArrayRank() == 1)
						{
							context.writer.Write((byte)prim);
						}
						else
						{
							bool firstTime;
							long assemblyId;
							assemblyId = context.gen.GetId
							(type.GetElementType().Assembly, out firstTime);
							context.writer.Write(type.FullName);
							context.writer.Write((int)assemblyId);
							if(firstTime)
							{
								// We need to output the assembly later.
								context.assemblyQueue.Enqueue(type.GetElementType().Assembly);
							}
						}
					}
				}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:33,代码来源:BinaryValueWriter.cs

示例13: if

		// Write the type tag for a type.
		public override void WriteTypeTag
					(BinaryValueContext context, Type type)
				{
					if(type == typeof(Object[]))
					{
						context.writer.Write
							((byte)(BinaryTypeTag.ArrayOfObject));
					}
					else if(type == typeof(String[]))
					{
						context.writer.Write
							((byte)(BinaryTypeTag.ArrayOfString));
					}
					else
					{
						BinaryPrimitiveTypeCode prim;
						prim = GetPrimitiveTypeCode(type.GetElementType());
						if(prim != (BinaryPrimitiveTypeCode)0 &&
						   type.GetArrayRank() == 1)
						{
							context.writer.Write
								((byte)(BinaryTypeTag.ArrayOfPrimitiveType));
						}
						else
						{
							context.writer.Write
								((byte)(BinaryTypeTag.GenericType));
						}
					}
				}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:31,代码来源:BinaryValueWriter.cs

示例14: GetArrayType

		// Get the type of an array.
		private BinaryArrayType GetArrayType(Array value, Type type)
				{
					int rank = type.GetArrayRank();
					bool hasLowerBounds = false;
					int dim;
					for(dim = 0; dim < rank; ++dim)
					{
						if(value.GetLowerBound(dim) != 0)
						{
							hasLowerBounds = true;
							break;
						}
					}
					if(type.GetElementType().IsArray)
					{
						if(rank == 1)
						{
							if(hasLowerBounds)
							{
								return BinaryArrayType.JaggedWithLowerBounds;
							}
							else
							{
								return BinaryArrayType.Jagged;
							}
						}
						else
						{
							if(hasLowerBounds)
							{
								return BinaryArrayType.
									MultidimensionalWithLowerBounds;
							}
							else
							{
								return BinaryArrayType.Multidimensional;
							}
						}
					}
					else if(rank == 1)
					{
						if(hasLowerBounds)
						{
							return BinaryArrayType.SingleWithLowerBounds;
						}
						else
						{
							return BinaryArrayType.Single;
						}
					}
					else
					{
						if(hasLowerBounds)
						{
							return BinaryArrayType.
								MultidimensionalWithLowerBounds;
						}
						else
						{
							return BinaryArrayType.Multidimensional;
						}
					}
				}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:64,代码来源:BinaryValueWriter.cs

示例15: ProcessArg


//.........这里部分代码省略.........
        }
        else if (varType == typeof(Vector4))
        {
            sb.AppendFormat("{0}UnityEngine.Vector4 {1} = ToLua.ToVector4(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Quaternion))
        {
            sb.AppendFormat("{0}UnityEngine.Quaternion {1} = ToLua.ToQuaternion(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Color))
        {
            sb.AppendFormat("{0}UnityEngine.Color {1} = ToLua.ToColor(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Ray))
        {
            sb.AppendFormat("{0}UnityEngine.Ray {1} = ToLua.ToRay(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Bounds))
        {
            sb.AppendFormat("{0}UnityEngine.Bounds {1} = ToLua.ToBounds(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(LayerMask))
        {
            sb.AppendFormat("{0}UnityEngine.LayerMask {1} = ToLua.ToLayerMask(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(object))
        {
            sb.AppendFormat("{0}object {1} = ToLua.ToVarObject(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(LuaByteBuffer))
        {
            sb.AppendFormat("{0}LuaByteBuffer {1} = new LuaByteBuffer(ToLua.CheckByteBuffer(L, {2}));\r\n", head, arg, stackPos);
        }
        else if (varType.IsArray && varType.GetArrayRank() == 1)
        {
            Type et = varType.GetElementType();
            string atstr = GetTypeStr(et);
            string fname;
            bool flag = false;                          //是否模版函数
            bool isObject = false;

            if (et.IsPrimitive)
            {
                if (beParams)
                {
                    if (et == typeof(bool))
                    {
                        fname = beCheckTypes ? "ToParamsBool" : "CheckParamsBool";
                    }
                    else if (et == typeof(char))
                    {
                        //char用的多些,特殊处理一下减少gcalloc
                        fname = beCheckTypes ? "ToParamsChar" : "CheckParamsChar";
                    }
                    else
                    {
                        flag = true;
                        fname = beCheckTypes ? "ToParamsNumber" : "CheckParamsNumber";
                    }
                }
                else if(et == typeof(char))
                {
                    fname = "CheckCharBuffer";      //使用Table传数组,CheckType只是简单匹配。需要读取函数继续匹配
                }
                else if (et == typeof(byte))
                {
开发者ID:woshihuo12,项目名称:UnityHello,代码行数:67,代码来源:ToLuaExport.cs


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