Пример #1
0
 public static void MakeCreator(Type type, Dictionary <Type, CreatorBase> typeCreators, string as3apidocpath, string csharpnativecodepath, string linkcodenamespace)
 {
     if (type.IsInterface)
     {
         if (!typeCreators.ContainsKey(type) && !IsSkipCreator(type))
         {
             typeCreators.Add(type, null); typeCreators[type] = new InterfaceCreator(type, as3apidocpath, csharpnativecodepath, typeCreators, linkcodenamespace);
         }
     }
     else if (type.IsEnum)
     {
         if (!typeCreators.ContainsKey(type) && !IsSkipCreator(type))
         {
             typeCreators.Add(type, null); typeCreators[type] = new EnumCreator(type, as3apidocpath, csharpnativecodepath, linkcodenamespace);
         }
     }
     else if (type.IsArray)
     {
         var elementtype = type.GetElementType();
         if (elementtype != null)
         {
             MakeCreator(elementtype, typeCreators, as3apidocpath, csharpnativecodepath, linkcodenamespace);
         }
     }
     else if (type.IsClass || type.IsValueType)
     {
         if (!typeCreators.ContainsKey(type) && !IsSkipCreator(type))
         {
             typeCreators.Add(type, null); typeCreators[type] = new ClassCreator(type, as3apidocpath, csharpnativecodepath, typeCreators, linkcodenamespace);
         }
     }
 }
Пример #2
0
        protected static string GetMethodName(string dotName, System.Reflection.MethodInfo method, Type methodAtType, Dictionary <string, object> staticusenames, Dictionary <string, object> usenames)
        {
            if (method.IsSpecialName && method.Name.StartsWith("add_") && method.GetParameters().Length == 1 && IsDelegate(method.GetParameters()[0].ParameterType))
            {
                string eventname = method.Name.Substring(4);

                return(eventname + "_addEventListener");
            }
            else if (method.IsSpecialName && method.Name.StartsWith("remove_") && method.GetParameters().Length == 1 && IsDelegate(method.GetParameters()[0].ParameterType))
            {
                string eventname = method.Name.Substring(7);

                return(eventname + "_removeEventListener");
            }


            var members = methodAtType.GetMember(dotName);
            //***加上受保护的方法***
            var pmem = methodAtType.GetMember(dotName, BindingFlags.Instance | BindingFlags.NonPublic);
            List <MemberInfo> _tempmembers = new List <MemberInfo>();

            _tempmembers.AddRange(members);
            foreach (var item in pmem)
            {
                if (item is FieldInfo)
                {
                    if (((FieldInfo)item).IsFamily)
                    {
                        if (IsSkipMember(item))
                        {
                            continue;
                        }
                        if (IsSkipType(((FieldInfo)item).FieldType))
                        {
                            continue;
                        }

                        _tempmembers.Add(item);
                    }
                }
                else if (item is MethodInfo)
                {
                    if (((MethodInfo)item).IsFamily)
                    {
                        if (IsSkipMember(item))
                        {
                            continue;
                        }
                        if (InterfaceCreator.isMethodSkip((MethodInfo)item))
                        {
                            continue;
                        }
                        _tempmembers.Add(item);
                    }
                }
            }
            members = _tempmembers.ToArray();

            //var props = methodAtType.GetProperties();
            //bool isprop = false;
            //foreach (var item in props)
            //{
            //	if (Equals(method, item.GetGetMethod()))
            //	{
            //		isprop = true;
            //	}
            //	if (Equals(method, item.GetSetMethod()))
            //	{
            //		isprop = true;
            //	}
            //}

            //if (!isprop)
            {
                if (Char.IsLower(dotName[0]))
                {
                    List <System.Reflection.MemberInfo> temp = new List <System.Reflection.MemberInfo>();

                    var ms = methodAtType.GetMember(Char.ToUpper(dotName[0]) + dotName.Substring(1));
                    foreach (var item in ms)
                    {
                        if (item.MemberType != MemberTypes.NestedType)
                        {
                            temp.Add(item);
                        }
                    }

                    if (temp.Count > 0)
                    {
                        dotName = dotName + "".PadLeft(temp.Count, '_');
                    }
                }
            }

            if (methodAtType.IsInterface)
            {
                var extinterface = methodAtType.GetInterfaces();

                List <System.Reflection.MemberInfo> inheritmember = new List <System.Reflection.MemberInfo>();
                foreach (var item in extinterface)
                {
                    inheritmember.AddRange(item.GetMember(dotName));
                }

                if (inheritmember.Count > 0)
                {
                    inheritmember.AddRange(members);

                    members = inheritmember.ToArray();
                }
            }
            else
            {
                var basetype = methodAtType.BaseType;
                List <System.Reflection.MemberInfo> inheritmember = new List <System.Reflection.MemberInfo>();
                if (basetype != null)
                {
                    var inherit = basetype.GetMember(dotName);
                    inheritmember.AddRange(inherit);

                    //***继承的受保护的对象***
                    var pinherit = basetype.GetMember(dotName, BindingFlags.Instance | BindingFlags.NonPublic);
                    foreach (var item in pinherit)
                    {
                        if (item is FieldInfo)
                        {
                            if (((FieldInfo)item).IsFamily)
                            {
                                if (IsSkipMember(item))
                                {
                                    continue;
                                }
                                if (IsSkipType(((FieldInfo)item).FieldType))
                                {
                                    continue;
                                }

                                inheritmember.Add(item);
                            }
                        }
                        else if (item is MethodInfo)
                        {
                            if (((MethodInfo)item).IsFamily)
                            {
                                if (IsSkipMember(item))
                                {
                                    continue;
                                }
                                if (InterfaceCreator.isMethodSkip((MethodInfo)item))
                                {
                                    continue;
                                }
                                inheritmember.Add(item);
                            }
                        }
                    }

                    //***********************
                    basetype = basetype.BaseType;
                }

                if (inheritmember.Count > 0)
                {
                    inheritmember.AddRange(members);
                    members = inheritmember.ToArray();
                }
            }


            string ext = string.Empty;

            for (int i = 0; i < members.Length; i++)
            {
                var m = members[i];

                if (IsSkipMember(m))
                {
                    continue;
                }


                if (m is MethodBase)
                {
                    if (((MethodBase)m).IsStatic != method.IsStatic)
                    {
                        continue;
                    }
                }
                else if (m is PropertyInfo)
                {
                    PropertyInfo p = (PropertyInfo)m;
                    if (Equals(p.GetGetMethod(), method))
                    {
                        break;
                    }
                    if (Equals(p.GetSetMethod(), method))
                    {
                        break;
                    }
                }

                if (members[i].Equals(method))
                {
                    break;
                }
                else
                {
                    ext = ext + "_";
                }
            }



            string v = dotName.Substring(0, 1).ToLower() + dotName.Substring(1) + ext;

            if (dotName.Length > 1)
            {
                if (Char.IsUpper(dotName.Substring(1, 1)[0]))
                {
                    v = dotName + ext;
                }
            }



            while (as3keywords.ContainsKey(v))
            {
                v = v + "_";
            }

            if (method.IsStatic)
            {
                if (staticusenames != null)
                {
                    while (staticusenames.ContainsKey(v))
                    {
                        v = v + "_";
                    }
                }
            }
            else
            {
                if (usenames != null)
                {
                    while (usenames.ContainsKey(v))
                    {
                        v = v + "_";
                    }
                }
            }
            return(v);
        }
Пример #3
0
        public InterfaceCreator(Type interfacetype, string as3apidocpath, string csharpnativecodepath,
                                Dictionary <TypeKey, CreatorBase> typeCreators,
                                string linkcodenamespace
                                ) : base(interfacetype, as3apidocpath, csharpnativecodepath, linkcodenamespace)
        {
            if (!interfacetype.IsInterface)
            {
                throw new ArgumentException("类型不是接口");
            }

            if (interfacetype.IsGenericType)
            {
                throw new ArgumentException("不支持泛型接口");
            }
            if (IsSkipCreator(interfacetype)
                )
            {
                throw new ArgumentException("接口已配置为跳过");
            }

            if (IsSkipType(interfacetype))
            {
                throw new ArgumentException("接口已配置为不生成");
            }

            name = GetAS3ClassOrInterfaceName(interfacetype);

            var exts = GetExtendInterfaces(interfacetype);

            foreach (var item in exts)
            {
                if (!typeCreators.ContainsKey(new TypeKey(item)) && !IsSkipCreator(item) && !IsSkipType(item))
                {
                    typeCreators.Add(new TypeKey(item), null); typeCreators[new TypeKey(item)] = new InterfaceCreator(item, as3apidocpath, csharpnativecodepath, typeCreators, linkcodenamespace);
                }
            }

            if (exts.Count > 1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(interfacetype + "检查到接口多继承,这里使用第一个");
                Console.ResetColor();
                super = exts[0];
            }
            else if (exts.Count == 1)
            {
                super = exts[0];
            }

            //****分析引用到的类型****
            var methods = interfacetype.GetMethods();

            foreach (var item in methods)
            {
                if (IsObsolete(item, type))
                {
                    continue;
                }

                if (item.IsGenericMethod)
                {
                    continue;
                }

                if (item.ReturnType.IsGenericTypeDefinition)
                {
                    continue;
                }

                if (IsSkipMember(item))
                {
                    continue;
                }

                var rt = MethodNativeCodeCreator.GetAS3Runtimetype(item.ReturnType);
                if (rt > ASBinCode.RunTimeDataType.unknown)
                {
                    if (IsSkipType(item.ReturnType))
                    {
                        continue;
                    }

                    MakeCreator(item.ReturnType, typeCreators);
                }
                bool hasoptional = false;
                bool parapass    = true;
                var  paras       = item.GetParameters();
                foreach (var p in paras)
                {
                    if (p.IsOut)
                    {
                        parapass = false;
                        break;
                    }
                    if (p.ParameterType.IsByRef)
                    {
                        parapass = false;
                        break;
                    }

                    if (p.ParameterType.IsGenericTypeDefinition)
                    {
                        parapass = false;
                        break;
                    }

                    if (p.IsOptional)
                    {
                        hasoptional = true;
                        if (p.RawDefaultValue != null)
                        {
                            var rrt = MethodNativeCodeCreator.GetAS3Runtimetype(p.ParameterType);
                            if (rrt > ASBinCode.RunTimeDataType.unknown)
                            {
                                parapass = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (hasoptional)
                        {
                            parapass = false;
                            break;
                        }
                    }

                    if (IsSkipType(p.ParameterType, true))
                    {
                        parapass = false;
                        break;
                    }

                    var pt = MethodNativeCodeCreator.GetAS3Runtimetype(p.ParameterType);
                    if (pt > ASBinCode.RunTimeDataType.unknown)
                    {
                        var mt = p.ParameterType;
                        if (p.ParameterType.IsByRef)
                        {
                            mt = p.ParameterType.GetElementType();
                        }
                        MakeCreator(mt, typeCreators);
                    }
                }

                if (parapass)
                {
                    methodlist.Add(item);
                }
            }
        }