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


C# IType.GetElementType方法代码示例

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


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

示例1: SynthesizedSingleDimArrayIListSetItemMethod

        /// <summary>
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="typeResolver">
        /// </param>
        public SynthesizedSingleDimArrayIListSetItemMethod(IType arrayType, ITypeResolver typeResolver)
            : base("set_Item", arrayType, typeResolver.System.System_Void)
        {
            var codeList = new IlCodeBuilder();
            codeList.LoadArgument(0);
            codeList.LoadArgument(1);
            codeList.LoadArgument(2);
            codeList.Add(Code.Stelem, 1);
            codeList.Add(Code.Ret);

            var locals = new List<IType>();

            this._methodBody =
                new SynthesizedMethodBodyDecorator(
                    null,
                    locals,
                    codeList.GetCode());

            this._parameters = new List<IParameter>();
            this._parameters.Add(typeResolver.System.System_Int32.ToParameter());
            this._parameters.Add(arrayType.GetElementType().ToParameter());

            this._tokenResolutions = new List<object>();
            this._tokenResolutions.Add(arrayType.GetElementType());
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:31,代码来源:SynthesizedSingleDimArrayIListSetItemMethod.cs

示例2: SynthesizedSingleDimArrayIListGetEnumeratorMethod

        /// <summary>
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="typeResolver">
        /// </param>
        public SynthesizedSingleDimArrayIListGetEnumeratorMethod(IType arrayType, ITypeResolver typeResolver)
            : base("GetEnumerator", arrayType, typeResolver.System.System_Collections_Generic_IEnumerator_T.Construct(arrayType.GetElementType()))
        {
            var codeList = new IlCodeBuilder();
            codeList.LoadArgument(0);
            codeList.Add(Code.Newobj, 1);
            codeList.Add(Code.Newobj, 2);
            codeList.Add(Code.Ret);

            var locals = new List<IType>();

            this._methodBody =
                new SynthesizedMethodBodyDecorator(
                    null,
                    locals,
                    codeList.GetCode());

            this._parameters = new List<IParameter>();

            this._tokenResolutions = new List<object>();

            var arraySegmentType = typeResolver.System.System_ArraySegment_T1.Construct(arrayType.GetElementType());
            this._tokenResolutions.Add(
                IlReader.Constructors(arraySegmentType, typeResolver).First(c => c.GetParameters().Count() == 1));
            this._tokenResolutions.Add(
                IlReader.Constructors(arraySegmentType.GetNestedTypes().First(), typeResolver).First(c => c.GetParameters().Count() == 1));
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:33,代码来源:SynthesizedSingleDimArrayIListGetEnumeratorMethod.cs

示例3: GetFields

        public static IEnumerable<IField> GetFields(IType arrayType, ITypeResolver typeResolver)
        {
            Debug.Assert(arrayType.IsMultiArray, "This is for multi arrays only");

            var shortType = typeResolver.System.System_Int16;
            var intType = typeResolver.System.System_Int32;
            var pointerType = typeResolver.System.System_Byte.ToPointerType();

            // return dummy fields to compensate interfaces for SingleDim array
            foreach (var dummyField in arrayType.GetElementType().ToArrayType(1).GetInterfaces())
            {
                yield return pointerType.ToField(arrayType, dummyField.Name);
            }

            yield return shortType.ToField(arrayType, "rank");
            yield return shortType.ToField(arrayType, "typeCode");
            yield return intType.ToField(arrayType, "elementSize");
            yield return intType.ToArrayType(1).ToField(arrayType, "lowerBounds");
            yield return intType.ToArrayType(1).ToField(arrayType, "lengths");
            yield return arrayType.GetElementType().ToField(arrayType, "data", isFixed: true);
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:21,代码来源:ArrayMultiDimensionGen.cs

示例4: ArraySingleDimensionGen_Ctor

        /*
        public ArraySingleDimensionGen_Ctor()
        {
            this.rank = 0; //?
            this.typeCode = type.GetElementType().TypeCode;
            this.elementSize = type.GetSize();
            this.length = dim1;
        }
         */

        public static IEnumerable<IField> GetFields(IType arrayType, ITypeResolver typeResolver)
        {
            Debug.Assert(arrayType.IsArray && !arrayType.IsMultiArray, "This is for multi arrays only");

            var shortType = typeResolver.System.System_Int16;
            var intType = typeResolver.System.System_Int32;

            yield return shortType.ToField(arrayType, "rank");
            yield return shortType.ToField(arrayType, "typeCode");
            yield return intType.ToField(arrayType, "elementSize");
            yield return intType.ToField(arrayType, "length");
            yield return arrayType.GetElementType().ToField(arrayType, "data", isFixed: true);
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:23,代码来源:ArraySingleDimensionGen.cs

示例5: IsValidByRefArg

 public bool IsValidByRefArg(IParameter param, IType parameterType, IType argType, Node arg)
 {
     if ((parameterType.IsByRef &&
         argType == parameterType.GetElementType()))
     {
         return CanLoadAddress(arg);
     }
     else if (param.IsByRef &&
         argType == parameterType)
     {
         return CanLoadAddress(arg);
     }
     return false;
 }
开发者ID:w4x,项目名称:boolangstudio,代码行数:14,代码来源:CallableResolutionService.cs

示例6: SynthesizedMultiDimArrayGetMethod

        /// <summary>
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="typeResolver">
        /// </param>
        public SynthesizedMultiDimArrayGetMethod(IType type, ITypeResolver typeResolver)
            : base("Get", type, type.GetElementType())
        {
            object[] code;
            IList<object> tokenResolutions;
            IList<IType> locals;
            IList<IParameter> parameters;
            ArrayMultiDimensionGen.GetMultiDimensionArrayGet(type, typeResolver, out code, out tokenResolutions, out locals, out parameters);

            this._methodBody = new SynthesizedMethodBodyDecorator(
                null,
                locals,
                MethodBodyBank.Transform(code).ToArray());

            this._parameters = parameters;
            this._tokenResolutions = tokenResolutions;
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:23,代码来源:SynthesizedMultiDimArrayGetMethod.cs

示例7: GetMultiDimensionArrayCtor

        public static void GetMultiDimensionArrayCtor(
            IType arrayType,
            ITypeResolver typeResolver,
            out object[] code,
            out IList<object> tokenResolutions,
            out IList<IType> locals,
            out IList<IParameter> parameters)
        {
            Debug.Assert(arrayType.IsMultiArray, "This is for multi arrays only");

            var codeList = new List<object>();

            var arrayRank = arrayType.ArrayRank;
            var elementType = arrayType.GetElementType();
            var typeCode = elementType.GetTypeCode();
            var elementSize = elementType.GetTypeSize(typeResolver, true);

            codeList.AddRange(
                new object[]
                    {
                        Code.Ldarg_0,
                        Code.Dup,
                        Code.Dup,
                    });

            codeList.AppendLoadInt(arrayRank);
            codeList.AppendInt(Code.Stfld, 1);
            codeList.AppendLoadInt(typeCode);
            codeList.AppendInt(Code.Stfld, 2);
            codeList.AppendLoadInt(elementSize);
            codeList.AppendInt(Code.Stfld, 3);

            // init lowerBounds
            // set all 0
            codeList.AppendLoadInt(arrayRank);
            codeList.AppendInt(Code.Newarr, 4);
            codeList.Add(Code.Stloc_0);

            // init each item in lowerBounds
            foreach (var i in Enumerable.Range(0, arrayRank))
            {
                codeList.Add(Code.Ldloc_0);
                codeList.AppendLoadInt(i);
                codeList.AddRange(
                    new object[]
                    {
                        Code.Ldc_I4_0,
                        Code.Stelem_I4
                });
            }

            // save new array into field lowerBounds
            codeList.AddRange(
                new object[]
                {
                        Code.Ldarg_0,
                        Code.Ldloc_0,
                });
            codeList.AppendInt(Code.Stfld, 5);

            // init Bounds
            codeList.AppendLoadInt(arrayRank);
            codeList.AppendInt(Code.Newarr, 6);
            codeList.Add(Code.Stloc_1);

            // init each item in lowerBounds
            foreach (var i in Enumerable.Range(0, arrayRank))
            {
                codeList.Add(Code.Ldloc_1);
                codeList.AppendLoadInt(i);
                //codeList.AppendLoadArgument(i + 1);
                codeList.AppendLoadArgument(arrayRank - i);
                codeList.AddRange(
                    new object[]
                    {
                        Code.Stelem_I4
                    });
            }

            // save new array into field lowerBounds
            codeList.AddRange(
                new object[]
                {
                        Code.Ldarg_0,
                        Code.Ldloc_1,
                });
            codeList.AppendInt(Code.Stfld, 7);

            // return
            codeList.AddRange(
                new object[]
                {
                        Code.Ret
                });

            // locals
            locals = new List<IType>();
            locals.Add(typeResolver.System.System_Int32.ToArrayType(1));
            locals.Add(typeResolver.System.System_Int32.ToArrayType(1));

//.........这里部分代码省略.........
开发者ID:afrog33k,项目名称:csnative,代码行数:101,代码来源:ArrayMultiDimensionGen.cs

示例8: MapType

        /// <summary>
        /// Maps a type involving generic parameters to the corresponding type after substituting concrete
        /// arguments for generic parameters.
        /// </summary>
        /// <remarks>
        /// If the source type is a generic parameter, it is mapped to the corresponding argument.
        /// If the source type is an open generic type using any of the specified generic parameters, it 
        /// is mapped to a closed constructed type based on the specified arguments.
        /// </remarks>
        protected virtual IType MapType(IType sourceType)
        {
            if (sourceType == null)
            {
                return null;
            }

            // Strip reference types
            if (sourceType.IsByRef)
            {
                return MapType(sourceType.GetElementType());
            }

            // Map generic parameter to corresponding argument
            IGenericParameter gp = sourceType as IGenericParameter;
            if (null != gp && _map.ContainsKey(gp))
            {
                return _map[gp];
            }

            // Map open constructed type using generic parameters to closed constructed type
            // using corresponding arguments
            if (null != sourceType.ConstructedInfo)
            {
                IType[] mappedArguments = Array.ConvertAll<IType, IType>(
                    sourceType.ConstructedInfo.GenericArguments,
                    MapType);

                IType mapped = sourceType.ConstructedInfo.
                    GenericDefinition.GenericInfo.
                    ConstructType(mappedArguments);

                return mapped;
            }

            // TODO: Map nested types
            // GenericType[of T].NestedType => GenericType[of int].NestedType

            // Map array types
            IArrayType array = (sourceType as IArrayType);
            if (array != null)
            {
                IType elementType = array.GetElementType();
                IType mappedElementType = MapType(elementType);
                if (mappedElementType != elementType)
                {
                    return _tss.GetArrayType(mappedElementType, array.GetArrayRank());
                }
            }

            // Map callable types
            ICallableType callable = sourceType as ICallableType;
            if (callable != null && EntityNeedsMapping(callable))
            {
                CallableSignature signature = callable.GetSignature();

                IType returnType = MapType(signature.ReturnType);
                IParameter[] parameters = Map(signature.Parameters);

                CallableSignature mappedSignature = new CallableSignature(
                    parameters, returnType, signature.AcceptVarArgs);

                return _tss.GetCallableType(mappedSignature);
            }

            // If source type doesn't require mapping, return it as is
            return sourceType;
        }
开发者ID:boo,项目名称:boo-lang,代码行数:77,代码来源:GenericMapping.cs

示例9: GetTypeGenerity

        /// <summary>
        /// Determines the number of open generic parameters in the specified type.
        /// </summary>
        public static int GetTypeGenerity(IType type)
        {
            // Dive into arrays and refs
            if (type.IsByRef || type.IsArray)
            {
                return GetTypeGenerity(type.GetElementType());
            }

            // A generic parameter has a generity of one
            if (type is IGenericParameter)
            {
                return 1;
            }

            // Generic parameters and generic arguments both contribute
            // to a types genrity
            int generity = 0;

            // A generic type gets a generity equals to the number its type parameters
            if (type.GenericInfo != null)
            {
                generity += type.GenericInfo.GenericParameters.Length;
            }

            // A constructed type gets the accumulated generity of its type arguments
            if (type.ConstructedInfo != null)
            {
                foreach (IType typeArg in type.ConstructedInfo.GenericArguments)
                {
                    generity += GetTypeGenerity(typeArg);
                }
            }

            return generity;
        }
开发者ID:boo,项目名称:boo-lang,代码行数:38,代码来源:GenericsServices.cs

示例10: IsAssignableFrom

        /// <summary>
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <returns>
        /// </returns>
        public bool IsAssignableFrom(IType type)
        {
            if (type.IsDerivedFrom(this))
            {
                return true;
            }

            if (type.GetAllInterfaces().Contains(this))
            {
                return true;
            }

            if (this.IsArray && type.IsArray && type.GetElementType().IsDerivedFrom(this.GetElementType()))
            {
                return true;
            }

            if (this.IsPointer && type.IsPointer && type.GetElementType().IsDerivedFrom(this.GetElementType()))
            {
                return true;
            }

            return false;
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:30,代码来源:MetadataTypeAdapter.cs

示例11: IterateAllRequiredTypes

        private static IEnumerable<IType> IterateAllRequiredTypes(IType type, ReadingTypesContext readingTypesContext)
        {
            Debug.Assert(type != null, "Type is null");

            if (type.BaseType != null)
            {
                DicoverGenericSpecializedTypesAndAdditionalTypes(type.BaseType, readingTypesContext);
                yield return type.BaseType;
            }

            if (type.HasElementType)
            {
                DicoverGenericSpecializedTypesAndAdditionalTypes(type.GetElementType(), readingTypesContext);
                yield return type.GetElementType();
            }

            var interfaces = type.GetInterfaces();
            if (interfaces != null)
            {
                foreach (var @interface in interfaces)
                {
                    DicoverGenericSpecializedTypesAndAdditionalTypes(@interface, readingTypesContext);
                    yield return @interface;
                }
            }

            if (!type.IsInterface)
            {
                var fields = IlReader.Fields(
                    type, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, _codeWriter);
                foreach (var field in fields)
                {
                    ////#if DEBUG
                    ////    Debug.WriteLine("Processing field: {0}, Type: {1}", field.FullName, field.FieldType);
                    ////#endif

                    DicoverGenericSpecializedTypesAndAdditionalTypes(field.FieldType, readingTypesContext);
                    if (field.FieldType.IsStructureType() && !field.FieldType.IsPointer)
                    {
                        yield return field.FieldType;
                    }
                }

                var ctors = IlReader.Constructors(
                    type, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, _codeWriter);
                foreach (var requiredType in ctors.SelectMany(ctor => GetAllRequiredTypesForMethod(ctor, readingTypesContext)))
                {
                    yield return requiredType;
                }
            }

            var methods = IlReader.Methods(
                type, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, _codeWriter);
            foreach (var requiredType in methods.SelectMany(method => GetAllRequiredTypesForMethod(method, readingTypesContext)))
            {
                yield return requiredType;
            }
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:58,代码来源:Il2Converter.cs

示例12: GetSingleDimensionArrayCtor

        public static void GetSingleDimensionArrayCtor(
            IType arrayType,
            ITypeResolver typeResolver,
            out object[] code,
            out IList<object> tokenResolutions,
            out IList<IType> locals,
            out IList<IParameter> parameters)
        {
            Debug.Assert(arrayType.IsArray && !arrayType.IsMultiArray, "This is for single dim arrays only");

            var codeList = new List<object>();

            var arrayRank = arrayType.ArrayRank;
            var elementType = arrayType.GetElementType();
            var typeCode = elementType.GetTypeCode();
            var elementSize = elementType.GetTypeSize(typeResolver, true);

            codeList.AddRange(
                new object[]
                    {
                        Code.Ldarg_0,
                        Code.Dup,
                        Code.Dup,
                        Code.Dup,
                    });

            codeList.AppendLoadInt(arrayRank);
            codeList.AppendInt(Code.Stfld, 1);
            codeList.AppendLoadInt(typeCode);
            codeList.AppendInt(Code.Stfld, 2);
            codeList.AppendLoadInt(elementSize);
            codeList.AppendInt(Code.Stfld, 3);
            codeList.AppendLoadArgument(1);
            codeList.AppendInt(Code.Stfld, 4);

            // return
            codeList.AddRange(
                new object[]
                {
                        Code.Ret
                });

            // locals
            locals = new List<IType>();
            locals.Add(typeResolver.System.System_Int32.ToArrayType(1));
            locals.Add(typeResolver.System.System_Int32.ToArrayType(1));

            // tokens
            tokenResolutions = new List<object>();
            tokenResolutions.Add(arrayType.GetFieldByName("rank", typeResolver));
            tokenResolutions.Add(arrayType.GetFieldByName("typeCode", typeResolver));
            tokenResolutions.Add(arrayType.GetFieldByName("elementSize", typeResolver));
            tokenResolutions.Add(arrayType.GetFieldByName("length", typeResolver));

            // code
            code = codeList.ToArray();

            // parameters
            parameters = ArrayMultiDimensionGen.GetParameters(arrayType, typeResolver);
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:60,代码来源:ArraySingleDimensionGen.cs

示例13: FindGenericParameters

        private IEnumerable<IGenericParameter> FindGenericParameters(IType type)
        {
            IGenericParameter genericParameter = type as IGenericParameter;
            if (genericParameter != null && _inferredTypes.ContainsKey(genericParameter))
            {
                yield return genericParameter;
            }

            if (type is IArrayType)
            {
                foreach (IGenericParameter gp in FindGenericParameters(type.GetElementType())) yield return gp;
                yield break;
            }

            if (type.ConstructedInfo != null)
            {
                foreach (IType typeArgument in type.ConstructedInfo.GenericArguments)
                {
                    foreach (IGenericParameter gp in FindGenericParameters(typeArgument)) yield return gp;
                }
                yield break;
            }

            ICallableType callableType = type as ICallableType;
            if (callableType != null)
            {
                CallableSignature signature = callableType.GetSignature();
                foreach (IGenericParameter gp in FindGenericParameters(signature.ReturnType)) yield return gp;
                foreach (IParameter parameter in signature.Parameters)
                {
                    foreach (IGenericParameter gp in FindGenericParameters(parameter.Type)) yield return gp;
                }
                yield break;
            }
        }
开发者ID:boo,项目名称:boo-lang,代码行数:35,代码来源:GenericParameterInferrer.cs

示例14: InferArrayType

 private bool InferArrayType(IArrayType formalType, IType actualType, Inference inference)
 {
     IArrayType actualArrayType = actualType as IArrayType;
     return
         (actualArrayType != null) &&
         (actualArrayType.GetArrayRank() == formalType.GetArrayRank()) &&
         (Infer(formalType.GetElementType(), actualType.GetElementType(), inference));
 }
开发者ID:boo,项目名称:boo-lang,代码行数:8,代码来源:GenericParameterInferrer.cs

示例15: GetCalculationPartOfSingleDimArrayAllocationSizeMethodBody

        private static void GetCalculationPartOfSingleDimArrayAllocationSizeMethodBody(
            ITypeResolver typeResolver,
            IType arrayType,
            out object[] code,
            out IList<object> tokenResolutions,
            out IList<IType> locals,
            out IList<IParameter> parameters)
        {
            var codeList = new List<object>();

            // add element size
            var elementType = arrayType.GetElementType();
            var elementSize = elementType.GetTypeSize(typeResolver, true);
            codeList.AppendLoadInt(elementSize);

            // load length
            codeList.AppendLoadArgument(0);
            codeList.Add(Code.Mul);

            var arrayTypeSizeWithoutArrayData = arrayType.GetTypeSize(typeResolver);
            codeList.AppendLoadInt(arrayTypeSizeWithoutArrayData);
            codeList.Add(Code.Add);

            // calculate alignment
            codeList.Add(Code.Dup);

            var alignForType = Math.Max(LlvmWriter.PointerSize, !elementType.IsStructureType() ? elementSize : LlvmWriter.PointerSize);
            codeList.AppendLoadInt(alignForType - 1);
            codeList.Add(Code.Add);

            codeList.AppendLoadInt(~(alignForType - 1));
            codeList.Add(Code.And);

            // locals
            locals = new List<IType>();

            // tokens
            tokenResolutions = new List<object>();

            // parameters
            parameters = ArrayMultiDimensionGen.GetParameters(arrayType, typeResolver);

            code = codeList.ToArray();
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:44,代码来源:ArraySingleDimensionGen.cs


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