예제 #1
0
        void ImportClass(TypeReference fromType, bool isValue)
        {
            int numGeneric = ImportGenericParameters(fromType);

            var defType = AsDefinition(fromType);

            if (defType.HasCustomAttribute(
                    "System.Runtime.Remoting.Contexts.SynchronizationAttribute", true))
            {
                throw CilMain.Where.Exception($"attribute [Synchronization] is not supported");
            }

            if (defType.HasCustomAttribute("RetainName"))
            {
                Flags |= RETAIN_NAME;
            }

            if (isValue)
            {
                Flags |= VALUE;
                if (defType.IsEnum)
                {
                    if (defType.HasFields && numGeneric == 0)
                    {
                        var type = From(defType.Fields[0].FieldType);
                        if ((!type.IsReference) && type.PrimitiveType >= TypeCode.Boolean &&
                            type.PrimitiveType <= TypeCode.UInt64)
                        {
                            JavaName = ImportName(defType, 0);
                            CopyFrom(type);
                            Flags |= ENUM;
                            return;
                        }
                    }
                    throw CilMain.Where.Exception("bad enum");
                }
                if (fromType.Namespace == "System")
                {
                    if (fromType.Name == "RuntimeTypeHandle")
                    {
                        CopyFrom(JavaType.ClassType);
                        Flags &= ~VALUE;
                        return;
                    }

                    /*
                     * if (fromType.Name == "RuntimeFieldHandle")
                     * {
                     *  CopyFrom(ReflectFieldType);
                     *  JavaName = ClassName;
                     *  Flags &= ~VALUE;
                     *  return;
                     * }
                     * if (fromType.Name == "RuntimeMethodHandle")
                     * {
                     *  CopyFrom(ReflectMethodType);
                     *  JavaName = ClassName;
                     *  Flags &= ~VALUE;
                     *  return;
                     * }
                     */
                }
            }
            else
            {
                if (fromType.Namespace == "System")
                {
                    if (fromType.Name == "Exception")
                    {
                        CopyFrom(JavaType.ThrowableType);
                        JavaName = "system.Exception";
                        return;
                    }
                    if (fromType.Name == "MarshalByRefObject")
                    {
                        CopyFrom(JavaType.ObjectType);
                        JavaName = "system.MarshalByRefObject";
                        return;
                    }
                }

                if (defType.IsInterface)
                {
                    Flags |= INTERFACE;
                }

                else if (defType.IsAbstract && defType.HasCustomAttribute("AsInterface"))
                {
                    Flags |= INTERFACE;
                }

                else if (IsDelegateClass(defType))
                {
                    Flags |= DELEGATE;
                }
            }

            PrimitiveType = TypeCode.Empty;
            ArrayRank     = 0;
            ClassName     = ImportName(fromType, numGeneric);
            JavaName      = ClassName;

            LinkSuperTypes(defType);

            if (IsDelegate && defType.HasCustomAttribute("AsInterface") &&
                ClassName.EndsWith("$Delegate"))
            {
                // check for an artificial delegate, generated to represent a
                // java functional interface: (BuildDelegate in DotNetImporter),
                // and change to our baselib type -- FunctionalInterfaceDelegate.
                // see also:  LoadFunction in Delegate module.
                JavaName = ClassName = "system.FunctionalInterfaceDelegate";
            }
        }