Exemplo n.º 1
0
        public static MainModel LoadAssembly(string exePath, string xmlPath, TransConfig transConfig)
        {
            MainModel mainModel = new MainModel();
            Node      root      = new RootNode {
                Name = "ROOT"
            };

            mainModel.Root = root;

            //Load XML
            var xmlDoc = LoadXml(xmlPath);

            if (xmlDoc != null)
            {
                if (xmlDoc.Members != null && xmlDoc.Members.Length > 0)
                {
                    foreach (var member in xmlDoc.Members)
                    {
                        if (!string.IsNullOrEmpty(member.Summary))
                        {
                            member.Summary = member.Summary.Trim();
                        }
                    }
                }
            }

            //LoadTypes
            var types = LoadTypes(exePath, transConfig.ReflectionOnlyLoad);

            //Process
            if (xmlDoc != null)
            {
                root.Items = Transform(types, xmlDoc.Members, transConfig);
            }
            else
            {
                root.Items = Transform(types, null, transConfig);
            }

            return(mainModel);
        }
Exemplo n.º 2
0
        private static List <FieldNode> LoadFields(FieldInfo[] fields, XmlMember[] xmlMembers, TransConfig transConfig)
        {
            List <FieldNode> returnValue = new List <FieldNode>();

            if (fields != null && fields.Length > 0)
            {
                foreach (var field in fields)
                {
                    var fieldNode = new FieldNode();

                    fieldNode.Name               = field.Name;
                    fieldNode.CSharpTypeName     = field.FieldType.Name;
                    fieldNode.CSharpTypeFullName = field.FieldType.FullName;
                    fieldNode.JavaTypeName       = GetJavaType(field.FieldType);

                    if (!transConfig.ReflectionOnlyLoad && field.IsStatic)
                    {
                        var fieldValue = field.GetValue(null);
                        switch (field.FieldType.FullName)
                        {
                        case "System.Int32":
                            fieldNode.ConstValue = fieldValue.ToString();
                            break;

                        case "System.String":
                            fieldNode.ConstValue = string.Format("\"{0}\"", fieldValue);
                            break;

                        default:
                            break;
                        }
                    }

                    var fieldMember = xmlMembers != null?xmlMembers.FirstOrDefault(v => string.Format("F:{0}.{1}", field.DeclaringType.FullName, field.Name).Equals(v.Name)) : null;

                    if (fieldMember != null)
                    {
                        fieldNode.Summary = fieldMember.Summary;
                    }

                    returnValue.Add(fieldNode);
                }
            }

            return(returnValue);
        }
Exemplo n.º 3
0
        private static List <ClassNode> LoadClasses(Type[] classes, XmlMember[] xmlMembers, TransConfig transConfig)
        {
            List <ClassNode> returnValue = new List <ClassNode>();

            foreach (var item in classes)
            {
                var classNode = new ClassNode();

                classNode.Name       = item.Name;
                classNode.IsAbstract = item.IsAbstract;

                var classMember = xmlMembers != null?xmlMembers.FirstOrDefault(v => string.Format("T:{0}", item.FullName).Equals(v.Name)) : null;

                if (classMember != null)
                {
                    classNode.Summary = classMember.Summary;
                }

                //BaseType
                if (item.BaseType != typeof(object))
                {
                    classNode.BaseTypeName     = item.BaseType.Name;
                    classNode.BaseTypeFullName = item.BaseType.FullName;
                }

                //Properties
                var properties    = item.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                var propertyNodes = LoadProperties(properties, xmlMembers);
                if (propertyNodes != null && propertyNodes.Count > 0)
                {
                    foreach (var propertyNode in propertyNodes)
                    {
                        classNode.Items.Add(propertyNode);
                    }
                }

                //Fields
                var fields     = item.GetMembers().Where(v => v.MemberType == MemberTypes.Field && v.DeclaringType == item).Select(v => (FieldInfo)v).ToArray();
                var fieldNodes = LoadFields(fields, xmlMembers, transConfig);
                if (fieldNodes != null && fieldNodes.Count > 0)
                {
                    foreach (var fieldNode in fieldNodes)
                    {
                        classNode.Items.Add(fieldNode);
                    }
                }

                //Methods
                var methods = item.GetMembers()
                              .Where(v => v.MemberType == MemberTypes.Method)
                              .Where(v => v.DeclaringType == item)
                              .Select(v => (MethodInfo)v)
                              .Where(v => v.IsPublic && !v.IsSpecialName)
                              .ToArray();
                var methodNodes = LoadMethods(methods, xmlMembers);
                if (methodNodes != null && methodNodes.Count > 0)
                {
                    foreach (var methodNode in methodNodes)
                    {
                        classNode.Items.Add(methodNode);
                    }
                }

                returnValue.Add(classNode);
            }

            return(returnValue);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据namespace聚合
        /// </summary>
        /// <param name="types"></param>
        /// <returns></returns>
        private static ObservableCollection <Node> Transform(Type[] types, XmlMember[] xmlMembers, TransConfig transConfig)
        {
            var returnValue = new ObservableCollection <Node>();

            if (types != null && types.Length > 0)
            {
                var groups = types.ToLookup(v => v.Namespace);

                foreach (var group in groups)
                {
                    var ns = new NamespaceNode {
                        Name = group.Key
                    };

                    ns.Items = new ObservableCollection <Node>();

                    //Class
                    var classes    = group.Where(v => v.IsClass).ToArray();
                    var classNodes = LoadClasses(classes, xmlMembers, transConfig);
                    foreach (var item in classNodes)
                    {
                        ns.Items.Add(item);
                    }

                    returnValue.Add(ns);
                }
            }

            return(returnValue);
        }