当前位置: 首页>>代码示例>>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;未经允许,请勿转载。