Ejemplo n.º 1
0
            private static T GetTypedValueDefault(DbDataReader reader, int ordinal)
            {
                Type underlyingType = Nullable.GetUnderlyingType(typeof(T));

                if (underlyingType != (Type)null && underlyingType.IsEnum())
                {
                    return((T)Shaper.ErrorHandlingValueReader <T> .GetGenericTypedValueDefaultMethod(underlyingType).Invoke((object)null, new object[2]
                    {
                        (object)reader,
                        (object)ordinal
                    }));
                }
                bool isNullable;

                return((T)CodeGenEmitter.GetReaderMethod(typeof(T), out isNullable).Invoke((object)reader, new object[1]
                {
                    (object)ordinal
                }));
            }
Ejemplo n.º 2
0
            private static T GetTypedValueDefault(DbDataReader reader, int ordinal)
            {
                var underlyingType = Nullable.GetUnderlyingType(typeof(T));

                // The value read from the reader is of a primitive type. Such a value cannot be cast to a nullable enum type directly
                // but first needs to be cast to the non-nullable enum type. Therefore we will call this method for non-nullable
                // underlying enum type and cast to the target type.
                if (underlyingType != null &&
                    underlyingType.IsEnum())
                {
                    var methodInfo = GetGenericTypedValueDefaultMethod(underlyingType);
                    return((T)methodInfo.Invoke(null, new object[] { reader, ordinal }));
                }

                // use the specific reader.GetXXX method
                bool isNullable;
                var  readerMethod = CodeGenEmitter.GetReaderMethod(typeof(T), out isNullable);
                var  result       = (T)readerMethod.Invoke(reader, new object[] { ordinal });

                return(result);
            }
Ejemplo n.º 3
0
            private static T GetTypedValueDefault(DbDataReader reader, int ordinal)
            {
                var underlyingType = Nullable.GetUnderlyingType(typeof(T));

                // The value read from the reader is of a primitive type. Such a value cannot be cast to a nullable enum type directly
                // but first needs to be cast to the non-nullable enum type. Therefore we will call this method for non-nullable
                // underlying enum type and cast to the target type.
                if (underlyingType != null &&
                    underlyingType.IsEnum)
                {
                    var type = typeof(ErrorHandlingValueReader <>).MakeGenericType(underlyingType);
                    return((T)type.GetMethod(
                               MethodBase.GetCurrentMethod().Name, BindingFlags.NonPublic | BindingFlags.Static).Invoke(
                               null, new object[] { reader, ordinal }));
                }

                // use the specific reader.GetXXX method
                bool isNullable;
                var  readerMethod = CodeGenEmitter.GetReaderMethod(typeof(T), out isNullable);
                var  result       = (T)readerMethod.Invoke(reader, new object[] { ordinal });

                return(result);
            }