예제 #1
0
        public static ConstructorDef FromConstructorInfo(ClassDef parentClass, ConstructorInfo info, XMLDocs doc = null)
        {
            var def = new ConstructorDef(parentClass);

            def.ConstructorInfo = info;

            // Określanie poziomu dostępu
            if (info.IsPublic)
            {
                def.AccessType = AccessType.PUBLIC;
            }
            else if (info.IsFamily)
            {
                def.AccessType = AccessType.PROTECTED;
            }
            else if (info.IsPrivate)
            {
                def.AccessType = AccessType.PRIVATE;
            }
            else
            {
                def.AccessType = AccessType.INNER;
            }


            // Parametry
            var parameters = info.GetParameters();

            foreach (var param in parameters)
            {
                def.AddParam(ParamDef.FromParamInfo(param));
            }

            // Dopisywanie dokumentacji
            if (doc != null)
            {
                XmlNode docsNode = doc.GetDocumentation(def);

                if (docsNode != null)
                {
                    XmlNode current;
                    for (int i = 0; i < docsNode.ChildNodes.Count; i++)
                    {
                        current = docsNode.ChildNodes[i];

                        switch (current.Name)
                        {
                        case "summary":
                            def.Summary = current.InnerText.Replace("\n\r            ", "\n").Replace("\r\n            ", "\n").Replace("\n            ", "\n");
                            def.Summary = def.Summary.Substring(1, def.Summary.Length - 2);
                            def.Summary.Replace("\n", "\n\t");
                            break;

                        case "remarks":
                            def.Remarks = current.InnerText;
                            break;

                        case "param":
                            string name  = current.Attributes["name"].InnerText;
                            var    param = def.GetParam(name);
                            if (param != null)
                            {
                                param.Description = current.InnerText;
                            }
                            else
                            {
                                Console.WriteLine("Parameter not found: " + name);
                            }
                            break;

                        default:
                            Console.WriteLine("Unrecognized tag " + current.Name + " in class definition of " + def.ParentClass.TypeDef.FullName + ", method name " + def.Name);
                            break;
                        }
                    }
                }
            }

            return(def);
        }
예제 #2
0
 public ConstructorDef(ClassDef parent)
 {
     ParentClass = parent;
 }
예제 #3
0
        public static EventDef FromEventInfo(ClassDef parentClass, EventInfo info, XMLDocs doc = null)
        {
            var def = new EventDef();

            def.ParentClass         = parentClass;
            def.EventHandlerTypeDef = new TypeDef(info.EventHandlerType);
            def.Name = info.Name;
            var addMethod = info.GetAddMethod(true);

            def.IsStatic = addMethod.IsStatic;

            // Określanie poziomu dostępu
            if (addMethod.IsPublic)
            {
                def.AccessType = AccessType.PUBLIC;
            }
            else if (addMethod.IsFamily)
            {
                def.AccessType = AccessType.PROTECTED;
            }
            else if (addMethod.IsPrivate)
            {
                def.AccessType = AccessType.PRIVATE;
            }
            else
            {
                def.AccessType = AccessType.INNER;
            }

            if (doc != null)
            {
                XmlNode docsNode = doc.GetDocumentation(info);

                if (docsNode != null)
                {
                    XmlNode current;
                    for (int i = 0; i < docsNode.ChildNodes.Count; i++)
                    {
                        current = docsNode.ChildNodes[i];

                        switch (current.Name)
                        {
                        case "summary":
                            def.Summary = current.InnerText.Replace("\n\r            ", "\n").Replace("\r\n            ", "\n").Replace("\n            ", "\n");
                            def.Summary = def.Summary.Substring(1, def.Summary.Length - 2);
                            def.Summary.Replace("\n", "\n\t");
                            break;

                        case "remarks":
                            def.Remarks = current.InnerText;
                            break;

                        default:
                            Console.WriteLine("Unrecognized tag " + current.Name + " in class definition of " + def.ParentClass.TypeDef.FullName + ", event name " + def.Name);
                            break;
                        }
                    }
                }
            }

            return(def);
        }
예제 #4
0
        public static ClassDef FromType(Type type, XMLDocs doc = null)
        {
            if (type == typeof(ActionsManager))
            {
                Console.WriteLine("OK");
            }

            var def = new ClassDef();

            def.TypeDef = new TypeDef(type);

            if (type.BaseType != null)
            {
                def.BaseClass = new TypeDef(type.BaseType);
            }

            // Określenie typu dostępu
            if (type.IsPublic)
            {
                def.AccessType = AccessType.PUBLIC;
            }
            else if (type.IsNestedPublic)
            {
                def.AccessType = AccessType.PUBLIC;
                def.Nested     = true;
            }
            else if (type.IsNestedFamily)
            {
                def.AccessType = AccessType.PROTECTED;
                def.Nested     = true;
            }
            else if (type.IsNestedPrivate)
            {
                def.AccessType = AccessType.PRIVATE;
                def.Nested     = true;
            }
            else
            {
                def.AccessType = AccessType.INNER;
            }

            // Sczytywanie metod klasy
            var methods      = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Static);
            var constructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            var properties   = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            var events       = type.GetEvents(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            var fields       = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

            MethodDef mdef;

            foreach (var method in methods)
            {
                mdef = MethodDef.FromMethodInfo(def, method, doc);
                def.Methods.Add(method, mdef);
            }
            ConstructorDef cdef;

            foreach (var constr in constructors)
            {
                cdef = ConstructorDef.FromConstructorInfo(def, constr, doc);
                def.Constructors.Add(constr, cdef);
            }
            PropertyDef pdef;

            foreach (var prpt in properties)
            {
                pdef = PropertyDef.FromPropertyInfo(def, prpt, doc);
                def.Properties.Add(prpt, pdef);
            }
            EventDef edef;

            foreach (var evt in events)
            {
                edef = EventDef.FromEventInfo(def, evt, doc);
                def.Events.Add(evt, edef);
            }
            FieldDef fdef;

            foreach (var fld in fields)
            {
                if (!fld.Name.Contains("k__BackingField"))
                {
                    fdef = FieldDef.FromFieldInfo(def, fld, doc);
                    def.Fields.Add(fld, fdef);
                }
            }

            if (doc != null)
            {
                XmlNode docsNode = doc.GetDocumentation(type);

                if (docsNode != null)
                {
                    XmlNode current;
                    for (int i = 0; i < docsNode.ChildNodes.Count; i++)
                    {
                        current = docsNode.ChildNodes[i];

                        switch (current.Name)
                        {
                        case "summary":
                            def.Summary = current.InnerText.Replace("\n\r            ", "\n").Replace("\r\n            ", "\n").Replace("\n            ", "\n");
                            def.Summary = def.Summary.Substring(1, def.Summary.Length - 2);
                            def.Summary.Replace("\n", "\n\t");
                            break;

                        case "remarks":
                            def.Remarks = current.InnerText;
                            break;

                        default:
                            Console.WriteLine("Unrecognized tag " + current.Name + " in class definition of " + def.TypeDef.FullName);
                            break;
                        }
                    }
                }
            }

            return(def);
        }
예제 #5
0
 public MethodDef(ClassDef parent)
 {
     ParentClass = parent;
 }