Exemple #1
0
        // We have to make sure we never return
        // the boxed types to .NET callers.
        // TODO: check if this still holds true.
        public Type GetElementType()
        {
            var type = JavaGetComponentType();

            if (type == null)
            {
                return(null);
            }
            if (type == TypeHelper.BooleanType())
            {
                return(typeof(bool));
            }
            if (type == TypeHelper.CharacterType())
            {
                return(typeof(char));
            }
            if (type == TypeHelper.ByteType())
            {
                return(typeof(byte));
            }
            if (type == TypeHelper.ShortType())
            {
                return(typeof(short));
            }
            if (type == TypeHelper.IntegerType())
            {
                return(typeof(int));
            }
            if (type == TypeHelper.LongType())
            {
                return(typeof(long));
            }
            if (type == TypeHelper.FloatType())
            {
                return(typeof(float));
            }
            if (type == TypeHelper.DoubleType())
            {
                return(typeof(double));
            }
            return(type);
        }
Exemple #2
0
        /// <summary>
        /// In contrast to GetType(), which returns the Java-Runtime type, this method
        /// returns a type tht can properly be used in reflection: Boxed types return their
        /// primitive counterparts, and generic instances have their proper generic
        /// information.
        /// </summary>
        public Type GetTypeReflectionSafe()
        {
            // We have to make sure we return the correct primitive type
            // if the object was boxed.
            var type = JavaGetClass();

            if (type == TypeHelper.BooleanType())
            {
                return(typeof(bool));
            }
            if (type == TypeHelper.CharacterType())
            {
                return(typeof(char));
            }
            if (type == TypeHelper.ByteType())
            {
                return(typeof(byte));
            }
            if (type == TypeHelper.ShortType())
            {
                return(typeof(short));
            }
            if (type == TypeHelper.IntegerType())
            {
                return(typeof(int));
            }
            if (type == TypeHelper.LongType())
            {
                return(typeof(long));
            }
            if (type == TypeHelper.FloatType())
            {
                return(typeof(float));
            }
            if (type == TypeHelper.DoubleType())
            {
                return(typeof(double));
            }

            return(GenericsReflection.GetReflectionSafeType(type, this));
        }