Ejemplo n.º 1
0
        /// <summary>
        /// Traverses the interface inheritance tree and collects all found interfaces.
        /// </summary>
        /// <param name="Interface">The starting innterface.</param>
        /// <param name="AllInterfaces">A list of all interfaces found.</param>
        public static IEnumerable <Type> GetRecursiveInterfaces(this Type Interface, List <Type> AllInterfaces = null)
        {
            if (AllInterfaces == null)
            {
                AllInterfaces = new List <Type>();
            }

            AllInterfaces.Add(Interface);

            var BaseInterfaces = Interface.GetInterfaces();

            if (BaseInterfaces != null && BaseInterfaces.Count() > 0)
            {
                foreach (var BaseInterface in BaseInterfaces)
                {
                    GetRecursiveInterfaces(BaseInterface, AllInterfaces);
                }
            }

            return(AllInterfaces);
        }
Ejemplo n.º 2
0
        public void UpdateNames()
        {
            foreach (GType ifc in Interfaces)
            {
                foreach (GType inIfc in ifc.AllInterfaces)
                {
                    if (!AllInterfaces.Contains(inIfc))
                    {
                        AllInterfaces.Add(inIfc);
                    }
                }
            }
            if (IsCLRType)
            {
                CLRNamespace = CLRType.Namespace;
                Name         = CLRType.Name;
                if (!IsJVMType && JVMFullName == null)
                {
                    JVMNamespace = CLRNamespace.ToLowerInvariant();

                    if (CLRType.IsGenericType)
                    {
                        bool rref = typeof(Ref <>).IsAssignableFrom(CLRType.GetGenericTypeDefinition());
                        bool oout = typeof(Out <>).IsAssignableFrom(CLRType.GetGenericTypeDefinition());
                        if (rref || oout)
                        {
                            JVMFullName = JVMNamespace + (rref ? ".Ref<" : ".Out<");
                            Type[] genericArguments = CLRType.GetGenericArguments();
                            for (int i = 0; i < genericArguments.Length; i++)
                            {
                                Type argument = genericArguments[i];

                                if (argument.IsPrimitive)
                                {
                                    String objName = Repository.jvmPrimitives[argument].getName();
                                    JVMFullName += objName;
                                }
                                else
                                {
                                    GType real = Repository.RegisterType(argument);
                                    real.UpdateNames();
                                    JVMFullName += real.JVMResolved;
                                }
                                if (i + 1 < genericArguments.Length)
                                {
                                    JVMFullName += ",";
                                }
                            }
                            JVMFullName += ">";
                        }
                    }
                    else
                    {
                        JVMFullName = JVMNamespace + "." + CLRType.Name;
                    }
                }
            }
            if (IsJVMType)
            {
                JVMNamespace = JVMType.PackageName;
                Name         = JVMType.ShortName;
                if (!IsCLRType)
                {
                    CLRNamespace = JVMNamespace;

                    if (IsArray)
                    {
                        CLRFullName = JVMType.getComponentType().getName() + "[]";
                    }
                    else
                    {
                        CLRFullName = JVMType.FullName;
                    }
                }
            }
            JVMNamespaceExt = JVMNamespace;
            CLRNamespaceExt = CLRNamespace;
            if (JVMNamespace.StartsWith("java."))
            {
                JVMNamespaceExt = "java_." + JVMNamespace.Substring(5);
            }

            /* TODO
             * if (IsJVMGenerate)
             * {
             *  if (Base!=null && !Base.IsJVMType && !Base.IsJVMGenerate)
             *  {
             *      Console.WriteLine("you should add " + Base.Name);
             *  }
             *  foreach (GType ifc in Interfaces)
             *  {
             *      if (!ifc.IsJVMType && !ifc.IsJVMGenerate)
             *      {
             *          Console.WriteLine("you should add " + ifc.Name);
             *      }
             *  }
             * }
             *
             * if (IsCLRGenerate && CLRType!=typeof(IClrProxy))
             * {
             *  if (Base != null && !Base.IsCLRType && !Base.IsCLRGenerate)
             *  {
             *      Console.WriteLine("you should add " + Base.Name);
             *  }
             *  foreach (GType ifc in Interfaces)
             *  {
             *      if (!ifc.IsCLRType && !ifc.IsCLRGenerate)
             *      {
             *          Console.WriteLine("you should add " + ifc.Name);
             *      }
             *  }
             * }*/
        }