예제 #1
0
        public static jlClass getFriendlyClassFromType(Type type)
        {
            int rank = 0;

            while (ReflectUtil.IsVector(type))
            {
                type = type.GetElementType();
                rank++;
            }
            if (type.DeclaringType != null &&
                AttributeHelper.IsGhostInterface(type.DeclaringType))
            {
                type = type.DeclaringType;
            }
            if (!IsVisibleAsClass(type))
            {
                return(null);
            }
            TypeWrapper wrapper = ClassLoaderWrapper.GetWrapperFromType(type);

            if (wrapper == null)
            {
                return(null);
            }
            if (rank > 0)
            {
                wrapper = wrapper.MakeArrayType(rank);
            }
            return(wrapper.ClassObject);
        }
예제 #2
0
 private static string TypeToString(Type type)
 {
     if (type.IsGenericType &&
         type.Namespace == "IKVM.Runtime" &&
         (type.Name.StartsWith("MH`") || type.Name.StartsWith("MHV`")))
     {
         return(type.Name.Substring(0, type.Name.IndexOf('`')) + "<" + TypesToString(type.GetGenericArguments()) + ">");
     }
     else if (type.DeclaringType == typeof(DynamicMethodBuilder))
     {
         return("C<" + TypesToString(type.GetGenericArguments()) + ">");
     }
     else if (ReflectUtil.IsVector(type))
     {
         return(TypeToString(type.GetElementType()) + "[]");
     }
     else if (type == typeof(object))
     {
         return("object");
     }
     else if (type == typeof(string))
     {
         return("string");
     }
     else if (type.IsPrimitive)
     {
         return(type.Name.ToLowerInvariant());
     }
     else
     {
         return(type.ToString());
     }
 }
예제 #3
0
		public static object multianewarray_ghost(RuntimeTypeHandle typeHandle, int[] lengths)
		{
			Type type = Type.GetTypeFromHandle(typeHandle);
			int rank = 0;
			while(ReflectUtil.IsVector(type))
			{
				rank++;
				type = type.GetElementType();
			}
			object obj = multianewarray(ArrayTypeWrapper.MakeArrayType(typeof(object), rank).TypeHandle, lengths);
			GhostTag.SetTag(obj, typeHandle);
			return obj;
		}
예제 #4
0
    public static void set(object arrayObj, int index, object value)
    {
        if (arrayObj == null)
        {
            throw new java.lang.NullPointerException();
        }
        Type type = arrayObj.GetType();

        if (ReflectUtil.IsVector(type) && ClassLoaderWrapper.GetWrapperFromType(type.GetElementType()).IsPrimitive)
        {
            java.lang.Boolean booleanValue = value as java.lang.Boolean;
            if (booleanValue != null)
            {
                setBoolean(arrayObj, index, booleanValue.booleanValue());
                return;
            }
            java.lang.Byte byteValue = value as java.lang.Byte;
            if (byteValue != null)
            {
                setByte(arrayObj, index, byteValue.byteValue());
                return;
            }
            java.lang.Character charValue = value as java.lang.Character;
            if (charValue != null)
            {
                setChar(arrayObj, index, charValue.charValue());
                return;
            }
            java.lang.Short shortValue = value as java.lang.Short;
            if (shortValue != null)
            {
                setShort(arrayObj, index, shortValue.shortValue());
                return;
            }
            java.lang.Integer intValue = value as java.lang.Integer;
            if (intValue != null)
            {
                setInt(arrayObj, index, intValue.intValue());
                return;
            }
            java.lang.Float floatValue = value as java.lang.Float;
            if (floatValue != null)
            {
                setFloat(arrayObj, index, floatValue.floatValue());
                return;
            }
            java.lang.Long longValue = value as java.lang.Long;
            if (longValue != null)
            {
                setLong(arrayObj, index, longValue.longValue());
                return;
            }
            java.lang.Double doubleValue = value as java.lang.Double;
            if (doubleValue != null)
            {
                setDouble(arrayObj, index, doubleValue.doubleValue());
                return;
            }
        }
        try
        {
            CheckArray(arrayObj).SetValue(value, index);
        }
        catch (InvalidCastException)
        {
            throw new java.lang.IllegalArgumentException("argument type mismatch");
        }
        catch (IndexOutOfRangeException)
        {
            throw new java.lang.ArrayIndexOutOfBoundsException();
        }
    }