當前位置: 首頁>>代碼示例>>C#>>正文


C# Type.MakeArrayType方法代碼示例

本文整理匯總了C#中System.Type.MakeArrayType方法的典型用法代碼示例。如果您正苦於以下問題:C# Type.MakeArrayType方法的具體用法?C# Type.MakeArrayType怎麽用?C# Type.MakeArrayType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Type的用法示例。


在下文中一共展示了Type.MakeArrayType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EmitArray

        /// <summary>
        ///   Emits an array.
        /// </summary>
        /// <param name="generator"> The generator. </param>
        /// <param name="arrayType"> Type of the array. </param>
        /// <param name="emitElements"> The emit elements. </param>
        public static void EmitArray(this ILGenerator generator, Type arrayType, IList<Action<ILGenerator>> emitElements)
        {
            var tLocal = generator.DeclareLocal(arrayType.MakeArrayType());
            generator.Emit(OpCodes.Ldc_I4, emitElements.Count);
            generator.Emit(OpCodes.Newarr, arrayType);
            generator.EmitStoreLocation(tLocal.LocalIndex);

            for (var i = 0; i < emitElements.Count; i++) {
                generator.EmitLoadLocation(tLocal.LocalIndex);
                generator.Emit(OpCodes.Ldc_I4, i);
                emitElements[i](generator);
                generator.Emit(OpCodes.Stelem_Ref);
            }
            generator.EmitLoadLocation(tLocal.LocalIndex);
        }
開發者ID:virmitio,項目名稱:coapp,代碼行數:21,代碼來源:EmitExtensions.cs

示例2: MakeElementTypes

		internal Type MakeElementTypes(Type type)
		{
			for (int i = this.m_elementTypes.Length - 1; i >= 0; i--)
			{
				if (this.m_elementTypes[i] == 3)
				{
					type = type.MakeArrayType();
				}
				else
				{
					if (this.m_elementTypes[i] == 2)
					{
						type = type.MakeArrayType(this.m_elementTypes[--i]);
					}
					else
					{
						if (this.m_elementTypes[i] == 1)
						{
							type = type.MakePointerType();
						}
						else
						{
							if (this.m_elementTypes[i] == 4)
							{
								type = type.MakeByRefType();
							}
						}
					}
				}
			}
			return type;
		}
開發者ID:ChristianWulf,項目名稱:CSharpKDMDiscoverer,代碼行數:32,代碼來源:UnitySerializationHolder.cs

示例3: Resolve

		public Type Resolve (Type type)
		{
			if (bound)
				return type.MakeArrayType (1);
			else if (dimensions == 1)
				return type.MakeArrayType ();
			return type.MakeArrayType (dimensions);
		}
開發者ID:razzfazz,項目名稱:mono,代碼行數:8,代碼來源:TypeSpec.cs

示例4: Resolve

 internal Type Resolve(Type type)
 {
     if (_isBound)
         return type.MakeArrayType(1);
     else if (_dimensions == 1)
         return type.MakeArrayType();
     return type.MakeArrayType(_dimensions);
 }
開發者ID:ragnard,項目名稱:clojure-clr,代碼行數:8,代碼來源:ClrTypeSpec.cs

示例5: DeserializeArray

        private static object DeserializeArray(BinaryReader sourceReader, Type elementType, int elementSize, int elementCount)
        {
            var arrayDataAddress = sourceReader.BaseStream.Position;

            var fields = elementType.Fields(
                 Flags.Public |
                 Flags.NonPublic |
                 Flags.Instance);


            List<FieldDelegateInformation> fieldMethods;


            var item = elementType.CreateInstance();
            ProcessFieldTypes(fields, out fieldMethods);


            var array = elementType.MakeArrayType().CreateInstance(elementCount);

            for (var i = 0; i < elementCount; ++i)
            {
                var element = elementType.CreateInstance();
                sourceReader.BaseStream.Position = arrayDataAddress + i * elementSize;
                InvokeFields(sourceReader, element, fields, fieldMethods);
                array.SetElement(i, element);
            }
            return array;
        }
開發者ID:jacksoncougar,項目名稱:Moonfish-Editor,代碼行數:28,代碼來源:Deserializer.cs

示例6: MakeArray

		public static Type MakeArray (Type t, List<int> sizes, List<int> loBounds)
		{
			var mt = t as MetadataType;
			if (mt != null) {
				if (sizes == null) {
					sizes = new List<int> ();
					sizes.Add (1);
				}
				mt.m_arraySizes = sizes;
				mt.m_arrayLoBounds = loBounds;
				return mt;
			}
			if (sizes == null || sizes.Count == 1)
				return t.MakeArrayType ();
			return t.MakeArrayType (sizes.Capacity);
		}
開發者ID:Kalnor,項目名稱:monodevelop,代碼行數:16,代碼來源:MetadataExtensions.cs

示例7: CreateArray

 /// <summary>
 /// Creates an array of the given type and stores it in a returned local.
 /// </summary>
 /// <param name="gen">The generator to inject the code into.</param>
 /// <param name="type">The type of the array.</param>
 /// <param name="size">The size of the array.</param>
 /// <returns>A local builder that now contains the array.</returns>
 public static LocalBuilder CreateArray(this ILGenerator gen, Type type, int size)
 {
     var ret = gen.DeclareLocal(type.MakeArrayType());
     gen.Emit(OpCodes.Ldc_I4, size);
     gen.Emit(OpCodes.Newarr, type);
     gen.Emit(OpCodes.Stloc, ret);
     return ret;
 }
開發者ID:TheModMaker,項目名稱:ModMaker.Lua,代碼行數:15,代碼來源:NetHelpers.cs

示例8: MakeArrayType

        public static Type MakeArrayType(Type elementType)
        {
#if CF
            return Array.CreateInstance(elementType, 0).GetType(); // ouch
#else
            return elementType.MakeArrayType();
#endif
        }
開發者ID:martindevans,項目名稱:DistributedServiceProvider,代碼行數:8,代碼來源:Helpers.cs

示例9: BuildForArrayOf

        /// <summary>
        /// Builds <see cref="IArrayAccessor"/> for arrays with elements of type <paramref name="arrayElementType"/>.
        /// </summary>
        public static IArrayAccessor BuildForArrayOf(Type arrayElementType)
        {
            Guard.AgainstNull(arrayElementType, "arrayElementType");

            Type arrayType = arrayElementType.MakeArrayType();
            return new ArrayAccessor(arrayElementType, BuildGetMethod(arrayType, arrayElementType),
                BuildSetMethod(arrayType, arrayElementType));
        }
開發者ID:saeedallahyari,項目名稱:NClone,代碼行數:11,代碼來源:ArrayAccessorBuilder.cs

示例10: CreateArray

        public static LocalBuilder CreateArray(this ILGenerator body, Type arrayType, int length)
        {
            var array = body.DeclareLocal(arrayType.MakeArrayType());
            body.Emit(OpCodes.Ldc_I4, length);
            body.Emit(OpCodes.Newarr, arrayType);
            body.Emit(OpCodes.Stloc, array);

            return array;
        }
開發者ID:ShaneGH,項目名稱:Dynamox,代碼行數:9,代碼來源:EmitExtensions.cs

示例11: EmitArrayInitializer

 Type EmitArrayInitializer(Type ElementType, CodeExpression Expr, int Index)
 {
     Generator.Emit(OpCodes.Dup);
     Generator.Emit(OpCodes.Ldc_I4, Index);
     Type Generated = EmitExpression(Expr);
     ForceTopStack(Generated, ElementType);
     Generator.Emit(OpCodes.Stelem_Ref);
     return ElementType.MakeArrayType();
 }
開發者ID:pschuegr,項目名稱:IronAHK,代碼行數:9,代碼來源:EmitVars.cs

示例12: StandardParse

        protected virtual object StandardParse(string[] values, Type targetType, Type elementType)
        {
            var parser = StringParsing.GetParser(elementType);

            var arr = Activator.CreateInstance(elementType.MakeArrayType(), values.Count());
            for (var i = 0; i < values.Length; i++)
                ((Array)arr).SetValue(parser.Parse(values[i], elementType), i);

            return arr;
        }
開發者ID:bitpantry,項目名稱:BitPantry.Parsing.Strings,代碼行數:10,代碼來源:ArrayParser.cs

示例13: CheckReturnTypeCanBeSatisfiedByArrayOf

		protected void CheckReturnTypeCanBeSatisfiedByArrayOf(Type type)
		{
			var arrayType = type.MakeArrayType();
			if (ComponentType.IsAssignableFrom(arrayType))
			{
				return;
			}

			ThrowUnsupportedCollectionType();
		}
開發者ID:AGiorgetti,項目名稱:Castle.InversionOfControl,代碼行數:10,代碼來源:TypedFactoryComponentCollection.cs

示例14: MakeElementTypes

        internal Type MakeElementTypes(Type type)
        {
            for (int i = m_elementTypes.Length - 1; i >= 0; i --)
            {
                if (m_elementTypes[i] == SzArray)
                {
                    type = type.MakeArrayType();
                }
                else if (m_elementTypes[i] == Array)
                {
                    type = type.MakeArrayType(m_elementTypes[--i]);
                }
                else if ((m_elementTypes[i] == Pointer))
                {
                    type = type.MakePointerType();
                }
                else if ((m_elementTypes[i] == ByRef))
                {
                    type = type.MakeByRefType();
                }
            }

            return type;
        }
開發者ID:ChuangYang,項目名稱:coreclr,代碼行數:24,代碼來源:UnitySerializationHolder.cs

示例15: CastElement

		public CastElement(ExpressionElement castExpression, string[] destTypeParts, bool isArray, IServiceProvider services)
		{
			MyCastExpression = castExpression;

			MyDestType = GetDestType(destTypeParts, services);

			if (MyDestType == null) {
				base.ThrowCompileException(CompileErrorResourceKeys.CouldNotResolveType, CompileExceptionReason.UndefinedName, GetDestTypeString(destTypeParts, isArray));
			}

			if (isArray == true) {
				MyDestType = MyDestType.MakeArrayType();
			}

			if (this.IsValidCast(MyCastExpression.ResultType, MyDestType) == false) {
				this.ThrowInvalidCastException();
			}
		}
開發者ID:netgrim,項目名稱:FleeSharp,代碼行數:18,代碼來源:Cast.cs


注:本文中的System.Type.MakeArrayType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。