예제 #1
0
        private static TypeInfo CreateTypeInfo(Type type)
        {
            TypeInfo result;

            if (type == typeof(void))
            {
                result = new VoidTypeInfo();
            }
            else if (type.GetMethod("Parse", new[] { typeof(string) }) != null && type.GetMethod("Parse", new[] { typeof(string) }).ReturnType == type)
            {
                result = new ParseableTypeInfo(type);
            }
            else if (type.IsArray)
            {
                result = new ArrayTypeInfo(type);
            }
            else if (type.IsEnum)
            {
                result = new EnumTypeInfo(type);
            }
            else if (type.ContainsGenericParameters)
            {
                result = new ReflectedTypeInfo(type);
            }
            else if (OPTIMIZED_TYPES.Contains(type))
            {
                result = new OptimizedTypeInfo(type);
            }
            else
            {
                result = new ReflectedTypeInfo(type);
            }

            return(result);
        }
예제 #2
0
파일: Scope.cs 프로젝트: frankcs/tiger
        /// <summary>
        /// Defines an array type in the current scope.
        /// </summary>
        /// <param name="typeName">The name of the type.</param>
        /// <param name="targetArrayTypeName">The name of the target type for the array.</param>
        /// <returns>TODO</returns>
        public ArrayTypeInfo DefineArray(string typeName, string targetArrayTypeName)
        {
            var arInfo = new ArrayTypeInfo(targetArrayTypeName);

            TypeTable.Add(typeName, arInfo);
            return(arInfo);
        }
예제 #3
0
        static void PopulateTypeInfo(ref ArrayTypeInfo info, MapItemInfo itemInfo, Type type)
        {
            int rank = type.GetArrayRank();

            info.ElementType = itemInfo.GetItemType();
            info.PerItem     = itemInfo;

            if (type.IsSZArray)
            {
                info.FastConversion = GetFastType(info.ElementType);
                info.Type           = ArrayType.SZArrayManual;

                //info.Type = info.FastConversion == FastConversionType.None ? ArrayType.SZArrayManual : ArrayType.SZArrayFast;
            }
            else if (rank == 1)
            {
                info.Rank = 1;
                info.Type = ArrayType.SNZArray;
            }
            else
            {
                if (rank == 32)
                {
                    throw new Exception("ABSave does not support arrays with exactly 32 dimensions, only below.");
                }
                info.Rank = (byte)rank;
                info.Type = ArrayType.MultiDimensional;
            }
        }
예제 #4
0
        public void ArrayTypeInfoNewInstance()
        {
            var typeinfo = new ArrayTypeInfo(TypeInfo.String, new ConstantNode(100));

            var instance = typeinfo.NewInstance();

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, typeof(string[]));
            Assert.AreEqual(100, instance.Length);
        }
예제 #5
0
        /// <inheritdoc />
        protected internal override async ValueTask <TRequestedArray> Read <TRequestedArray>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription?fieldDescription = null, CancellationToken cancellationToken = default)
        {
            if (ArrayTypeInfo <TRequestedArray> .IsArray)
            {
                return((TRequestedArray)(object)await ArrayTypeInfo <TRequestedArray> .ReadArrayFunc(this, buf, async, cancellationToken));
            }

            if (ArrayTypeInfo <TRequestedArray> .IsList)
            {
                return(await ArrayTypeInfo <TRequestedArray> .ReadListFunc(this, buf, async, cancellationToken));
            }

            throw new InvalidCastException(fieldDescription == null
                ? $"Can't cast database type to {typeof(TRequestedArray).Name}"
                : $"Can't cast database type {fieldDescription.Handler.PgDisplayName} to {typeof(TRequestedArray).Name}"
                                           );
        }
예제 #6
0
        private object CreateMultiArray(ArrayTypeInfo arrayTypeInfo, int[] sizes, int index)
        {
            if (index == sizes.Length)
            {
                switch (arrayTypeInfo.ElementType.Type)
                {
                case JVMType.Boolean:
                case JVMType.Char:
                case JVMType.Byte:
                case JVMType.Short:
                case JVMType.Int:
                    return((int)0);

                case JVMType.Float:
                    return((float)0.0);

                case JVMType.Double:
                    return((double)0.0);

                case JVMType.Long:
                    return((long)0);

                case JVMType.Object:
                    return(null);

                default:
                    throw new InvalidOperationException("Illegal element type in multianewarray instruction!");
                }
            }

            int size = sizes[index];

            object[] array = new object[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = CreateMultiArray(arrayTypeInfo, sizes, index + 1);
            }
            return(array);
        }
예제 #7
0
파일: Statics.cs 프로젝트: KotovN/coreclr
        public static TraceLoggingTypeInfo CreateDefaultTypeInfo(
            Type dataType,
            List <Type> recursionCheck)
        {
            TraceLoggingTypeInfo result;

            if (recursionCheck.Contains(dataType))
            {
                throw new NotSupportedException(SR.EventSource_RecursiveTypeDefinition);
            }

            recursionCheck.Add(dataType);

            var eventAttrib = Statics.GetCustomAttribute <EventDataAttribute>(dataType);

            if (eventAttrib != null ||
                Statics.GetCustomAttribute <CompilerGeneratedAttribute>(dataType) != null ||
                IsGenericMatch(dataType, typeof(KeyValuePair <,>)))
            {
                var analysis = new TypeAnalysis(dataType, eventAttrib, recursionCheck);
                result = new InvokeTypeInfo(dataType, analysis);
            }
            else if (dataType.IsArray)
            {
                var elementType = dataType.GetElementType();
                if (elementType == typeof(bool))
                {
                    result = ScalarArrayTypeInfo.Boolean();
                }
                else if (elementType == typeof(byte))
                {
                    result = ScalarArrayTypeInfo.Byte();
                }
                else if (elementType == typeof(sbyte))
                {
                    result = ScalarArrayTypeInfo.SByte();
                }
                else if (elementType == typeof(short))
                {
                    result = ScalarArrayTypeInfo.Int16();
                }
                else if (elementType == typeof(ushort))
                {
                    result = ScalarArrayTypeInfo.UInt16();
                }
                else if (elementType == typeof(int))
                {
                    result = ScalarArrayTypeInfo.Int32();
                }
                else if (elementType == typeof(uint))
                {
                    result = ScalarArrayTypeInfo.UInt32();
                }
                else if (elementType == typeof(long))
                {
                    result = ScalarArrayTypeInfo.Int64();
                }
                else if (elementType == typeof(ulong))
                {
                    result = ScalarArrayTypeInfo.UInt64();
                }
                else if (elementType == typeof(char))
                {
                    result = ScalarArrayTypeInfo.Char();
                }
                else if (elementType == typeof(double))
                {
                    result = ScalarArrayTypeInfo.Double();
                }
                else if (elementType == typeof(float))
                {
                    result = ScalarArrayTypeInfo.Single();
                }
                else if (elementType == typeof(IntPtr))
                {
                    result = ScalarArrayTypeInfo.IntPtr();
                }
                else if (elementType == typeof(UIntPtr))
                {
                    result = ScalarArrayTypeInfo.UIntPtr();
                }
                else if (elementType == typeof(Guid))
                {
                    result = ScalarArrayTypeInfo.Guid();
                }
                else
                {
                    result = new ArrayTypeInfo(dataType, TraceLoggingTypeInfo.GetInstance(elementType, recursionCheck));
                }
            }
            else
            {
                if (Statics.IsEnum(dataType))
                {
                    dataType = Enum.GetUnderlyingType(dataType);
                }

                if (dataType == typeof(string))
                {
                    result = new StringTypeInfo();
                }
                else if (dataType == typeof(bool))
                {
                    result = ScalarTypeInfo.Boolean();
                }
                else if (dataType == typeof(byte))
                {
                    result = ScalarTypeInfo.Byte();
                }
                else if (dataType == typeof(sbyte))
                {
                    result = ScalarTypeInfo.SByte();
                }
                else if (dataType == typeof(short))
                {
                    result = ScalarTypeInfo.Int16();
                }
                else if (dataType == typeof(ushort))
                {
                    result = ScalarTypeInfo.UInt16();
                }
                else if (dataType == typeof(int))
                {
                    result = ScalarTypeInfo.Int32();
                }
                else if (dataType == typeof(uint))
                {
                    result = ScalarTypeInfo.UInt32();
                }
                else if (dataType == typeof(long))
                {
                    result = ScalarTypeInfo.Int64();
                }
                else if (dataType == typeof(ulong))
                {
                    result = ScalarTypeInfo.UInt64();
                }
                else if (dataType == typeof(char))
                {
                    result = ScalarTypeInfo.Char();
                }
                else if (dataType == typeof(double))
                {
                    result = ScalarTypeInfo.Double();
                }
                else if (dataType == typeof(float))
                {
                    result = ScalarTypeInfo.Single();
                }
                else if (dataType == typeof(DateTime))
                {
                    result = new DateTimeTypeInfo();
                }
                else if (dataType == typeof(decimal))
                {
                    result = new DecimalTypeInfo();
                }
                else if (dataType == typeof(IntPtr))
                {
                    result = ScalarTypeInfo.IntPtr();
                }
                else if (dataType == typeof(UIntPtr))
                {
                    result = ScalarTypeInfo.UIntPtr();
                }
                else if (dataType == typeof(Guid))
                {
                    result = ScalarTypeInfo.Guid();
                }
                else if (dataType == typeof(TimeSpan))
                {
                    result = new TimeSpanTypeInfo();
                }
                else if (dataType == typeof(DateTimeOffset))
                {
                    result = new DateTimeOffsetTypeInfo();
                }
                else if (dataType == typeof(EmptyStruct))
                {
                    result = new NullTypeInfo();
                }
                else if (IsGenericMatch(dataType, typeof(Nullable <>)))
                {
                    result = new NullableTypeInfo(dataType, recursionCheck);
                }
                else
                {
                    var elementType = FindEnumerableElementType(dataType);
                    if (elementType != null)
                    {
                        result = new EnumerableTypeInfo(dataType, TraceLoggingTypeInfo.GetInstance(elementType, recursionCheck));
                    }
                    else
                    {
                        throw new ArgumentException(SR.Format(SR.EventSource_NonCompliantTypeError, dataType.Name));
                    }
                }
            }

            return(result);
        }