示例#1
0
        private static void ProcessMethods(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            foreach (var method in asmDataItem.cecilType.Methods)
            {
                if (!method.IsPublic)
                {
                    continue;
                }
                // we'll ignore property getter/setter
                if (method.Name.StartsWith("set") || method.Name.StartsWith("get"))
                {
                    continue;
                }
                var methodAsm = new AssemblyDataItem(AssemblyType.Method, asmDataItem.cecilType, asmDataItem)
                {
                    MInfo = method
                };
                var parentName = methodAsm.Parent.ItemName();
                var memberName = MemberNameFromMethodDefinition(method);

                methodAsm.UniqueName = string.Format("{0}.{1}", parentName, memberName);

                AddAssemblyDataItem(a, methodAsm);
            }
        }
示例#2
0
        private static void ProcessNestedTypes(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            foreach (var nested in asmDataItem.cecilType.NestedTypes)
            {
                if (!nested.IsNestedPublic)
                {
                    continue;
                }
                if (nested.IsClass)
                {
                    var nestedClassAsm = new AssemblyDataItem(AssemblyType.Class, nested, asmDataItem);

                    var memberName = nested.ToString().SimplifyTypesAndArrays();
                    memberName = StringConvertUtils.LowerCaseNeedsUnderscore(memberName);

                    nestedClassAsm.UniqueName = memberName;
                    AddAssemblyDataItem(a, nestedClassAsm);
                    BuildAsmChildOfClass(nestedClassAsm, a);
                }
                else
                {
                    int k = 0;
                }
            }
        }
 public AssemblyDataItem(AssemblyType at, TypeDefinition td, AssemblyDataItem p)
     : this()
 {
     assemblyType = at;
     cecilType = td;
     Parent = p;
 }
 internal static void BuildAsmChildOfClass(AssemblyDataItem asmDataItem, ICollection<AssemblyDataItem> a)
 {
     ProcessNestedTypes(asmDataItem, a);
     ProcessMethods(asmDataItem, a);
     ProcessProperties(asmDataItem, a);
     ProcessFields(asmDataItem, a);
 }
示例#5
0
 internal static void BuildAsmChildOfClass(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
 {
     ProcessNestedTypes(asmDataItem, a);
     ProcessMethods(asmDataItem, a);
     ProcessProperties(asmDataItem, a);
     ProcessFields(asmDataItem, a);
 }
示例#6
0
        private static List <AssemblyDataItem> LoadAssemblyDataItemsMonoCecil(ModuleDefinition asm)
        {
            Collection <TypeDefinition> types = null;
            var a = new List <AssemblyDataItem>();

            try
            {
                types = asm.Types;
            }
            catch (Exception rte)
            {
                Console.Out.WriteLine("ReflectionTypeLoadException:{0}", rte.Message);
            }

            if (types == null)
            {
                return(a);
            }

            // Display all the types contained in the specified assembly.
            foreach (TypeDefinition objType in types)
            {
                if (!objType.IsPublic)
                {
                    continue;
                }

                if (objType.IsPrimitive)
                {
                    var asmDataItem = new AssemblyDataItem(AssemblyType.Primitive, objType, objType.Name);
                    a.Add(asmDataItem);
                }
                else if (objType.IsEnum)
                {
                    var asmDataItem = new AssemblyDataItem(AssemblyType.Enum, objType, objType.Name);
                    a.Add(asmDataItem);
                    AssemblyDataBuilderUtil.BuildAsmChildOfEnum(asmDataItem, a);
                }

                else if (objType.IsClass || objType.IsValueType && !objType.IsPrimitive)
                {
                    var classOrStruct = objType.IsClass ? AssemblyType.Class : AssemblyType.Struct;
                    var asmDataItem   = new AssemblyDataItem(classOrStruct, objType, objType.Name);
                    a.Add(asmDataItem);
                    AssemblyDataBuilderUtil.BuildAsmChildOfClass(asmDataItem, a);
                }

                else
                {
                    Console.Out.WriteLine("Unknown Item: {0}", objType);
                }
            }

            return(a);
        }
        private static List<AssemblyDataItem> LoadAssemblyDataItemsMonoCecil(ModuleDefinition asm)
        {
            Collection<TypeDefinition> types = null;
            var a = new List<AssemblyDataItem>();

            try
            {
                types = asm.Types;
            }
            catch (Exception rte)
            {
                Console.Out.WriteLine("ReflectionTypeLoadException:{0}", rte.Message);
            }

            if (types == null)
            {
                return a;
            }

            // Display all the types contained in the specified assembly.
            foreach (TypeDefinition objType in types)
            {
                if (!objType.IsPublic)
                    continue;

                if (objType.IsPrimitive)
                {
                    var asmDataItem = new AssemblyDataItem(AssemblyType.Primitive, objType, objType.Name);
                    a.Add(asmDataItem);
                }
                else if (objType.IsEnum)
                {
                    var asmDataItem = new AssemblyDataItem(AssemblyType.Enum, objType, objType.Name);
                    a.Add(asmDataItem);
                    AssemblyDataBuilderUtil.BuildAsmChildOfEnum(asmDataItem, a);
                }

                else if (objType.IsClass || objType.IsValueType && !objType.IsPrimitive)
                {
                    var classOrStruct = objType.IsClass ? AssemblyType.Class : AssemblyType.Struct;
                    var asmDataItem = new AssemblyDataItem(classOrStruct, objType, objType.Name);
                    a.Add(asmDataItem);
                    AssemblyDataBuilderUtil.BuildAsmChildOfClass(asmDataItem, a);
                }

                else
                {
                    Console.Out.WriteLine("Unknown Item: {0}", objType);
                }
            }

            return a;
        }
示例#8
0
        private void Init(AssemblyDataItem asmData, string memberDoc)
        {
            InitBasics();

            if (asmData != null)
            {
                ProcessAsm(asmData);
            }
            if (memberDoc != null)
            {
                ProcessDoc(memberDoc);
            }
        }
        internal static void BuildAsmChildOfEnum(AssemblyDataItem asmDataItem, ICollection<AssemblyDataItem> a)
        {
            foreach (FieldDefinition field in asmDataItem.cecilType.Fields)
            {
                if (field.Name == "value__")
                    continue;
                var enumAsm = new AssemblyDataItem(AssemblyType.EnumValue, field.DeclaringType, asmDataItem);

                var parentName = field.DeclaringType.ToString().SimplifyTypesAndArrays();
                var memberName = StringConvertUtils.LowerCaseNeedsUnderscore(field.Name);
                enumAsm.SimplifiedName = string.Format("{0}.{1}", parentName, memberName);
                AddAssemblyDataItem(a, enumAsm);
            }
        }
        /// <summary>
        /// Create DocumentDataItem for corresponding AssemblyDataItem and add it to DocumentDataItemSet
        /// </summary>
        /// <param name="asm"></param>
        public DocumentDataItem CreateDocumentDataItemFor(AssemblyDataItem asm)
        {
            var docItem = new DocumentDataItem
            {
                signature      = asm.SimplifiedName,
                baseDocDirPath = baseDocDirPath
            };

            _hashtable.Add(docItem.signature, docItem);
            _documentList.Add(docItem);
            asm.DocDataItem = docItem;

            return(docItem);
        }
示例#11
0
        private void ProcessAsm(AssemblyDataItem data)
        {
            Collection <ParameterDefinition> parameters = null;
            TypeDefinition returnType = null;

            switch (data.assemblyType)
            {
            case AssemblyType.Method:
            {
                parameters = data.MInfo.Parameters;
                if (data.MInfo.ReturnType.ToString() != "System.Void")
                {
                    try
                    {
                        returnType = (TypeDefinition)data.MInfo.ReturnType;
                    }
                    catch (InvalidCastException ice)
                    {
                        Console.WriteLine("RHS returntype = {0}", data.MInfo.ReturnType);
                    }
                }

                break;
            }

            case AssemblyType.Constructor:
            {
                parameters = data.MInfo.Parameters;
                break;
            }
            }

            // Handle parameters
            if (parameters != null)
            {
                foreach (var pInfo in parameters)
                {
                    GetOrCreateParameter(pInfo.Name).Info = pInfo;
                }
            }

            // Handle return type
            if (returnType != null)
            {
                GetOrCreateReturnDoc().ReturnType = returnType;
            }
            Console.WriteLine("Full signature = {0}", this.ToString());
        }
示例#12
0
        internal static void BuildAsmChildOfEnum(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            foreach (FieldDefinition field in asmDataItem.cecilType.Fields)
            {
                if (field.Name == "value__")
                {
                    continue;
                }
                var enumAsm = new AssemblyDataItem(AssemblyType.EnumValue, field.DeclaringType, asmDataItem);

                var parentName = field.DeclaringType.ToString().SimplifyTypesAndArrays();
                var memberName = StringConvertUtils.LowerCaseNeedsUnderscore(field.Name);
                enumAsm.UniqueName = string.Format("{0}.{1}", parentName, memberName);
                AddAssemblyDataItem(a, enumAsm);
            }
        }
示例#13
0
        private static void ProcessProperties(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            foreach (PropertyDefinition prop in asmDataItem.cecilType.Properties)
            {
                var propAsm = new AssemblyDataItem(AssemblyType.Property, asmDataItem.cecilType, asmDataItem)
                {
                    PInfo = prop
                };
                var parentName = propAsm.Parent.ItemName();
                var memberName = MemberNameFromPropertyDefinition(prop);

                propAsm.UniqueName = string.Format("{0}.{1}", parentName, memberName);

                AddAssemblyDataItem(a, propAsm);
            }
        }
示例#14
0
        private static void ProcessProperties(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            foreach (PropertyDefinition prop in asmDataItem.cecilType.Properties)
            {
                if (prop.GetMethod == null == !prop.GetMethod.IsPublic)
                {
                    continue;
                }
                var propAsm = new AssemblyDataItem(AssemblyType.Property, asmDataItem.cecilType, asmDataItem)
                {
                    PInfo = prop
                };
                var parentName = propAsm.Parent.ItemName();
                var memberName = MemberNameFromPropertyDefinition(prop);

                propAsm.SimplifiedName = string.Format("{0}.{1}", parentName, memberName);

                AddAssemblyDataItem(a, propAsm);
            }
        }
示例#15
0
        private static void ProcessFields(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            foreach (var field in asmDataItem.cecilType.Fields)
            {
                if (field.Attributes != FieldAttributes.Public)
                {
                    continue;
                }
                var fieldAsm = new AssemblyDataItem(AssemblyType.Field, asmDataItem.cecilType, asmDataItem)
                {
                    FInfo = field
                };

                var parentName = fieldAsm.Parent.ItemName();
                var memberName = MemberNameFromFieldDefinition(field);

                fieldAsm.UniqueName = string.Format("{0}.{1}", parentName, memberName);

                AddAssemblyDataItem(a, fieldAsm);
            }
        }
示例#16
0
        private static void ProcessMethods(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            var simpleToFullName = new MultiDict <string, string>();

            foreach (var method in asmDataItem.cecilType.Methods)
            {
                if (!method.IsPublic)
                {
                    continue;
                }
                // we'll ignore property getter/setter
                if (method.Name.StartsWith("set") || method.Name.StartsWith("get"))
                {
                    continue;
                }

                var simplifiedMemberName = MemberNameFromMethodDefinition(method, true);
                simplifiedMemberName = string.Format("{0}.{1}", asmDataItem.ItemName(), simplifiedMemberName);

                var fullMemberName = MemberNameFromMethodDefinition(method, false);

                if (!simpleToFullName.Contains(simplifiedMemberName))
                {
                    simpleToFullName.Add(simplifiedMemberName, fullMemberName);
                }
            }

            foreach (var simplifiedMemberName in simpleToFullName.Keys)
            {
                var methodAsm = new AssemblyDataItem(AssemblyType.Method, asmDataItem.cecilType, asmDataItem);
                //{MInfo = method};
                methodAsm.SimplifiedName = simplifiedMemberName;

                AddAssemblyDataItem(a, methodAsm);
            }
        }
示例#17
0
 //used in MemberSession
 public MemDocModel(AssemblyDataItem memberData, string Text)
 {
     var block = new MeaningfulBlock(memberData, Text);
     MeaningfulBlocks.Add(block);
 }
示例#18
0
 public MeaningfulBlock(AssemblyDataItem asmData, string memberDoc)
 {
     Init(asmData, memberDoc);
 }
示例#19
0
        //used in MemberSession
        public MemDocModel(AssemblyDataItem memberData, string Text)
        {
            var block = new MeaningfulBlock(memberData, Text);

            MeaningfulBlocks.Add(block);
        }
        private static void ProcessFields(AssemblyDataItem asmDataItem, ICollection<AssemblyDataItem> a)
        {
            foreach (var field in asmDataItem.cecilType.Fields)
            {
                if (field.Attributes != FieldAttributes.Public)
                    continue;
                var fieldAsm = new AssemblyDataItem(AssemblyType.Field, asmDataItem.cecilType, asmDataItem) {FInfo = field};

                var parentName = fieldAsm.Parent.ItemName();
                var memberName = MemberNameFromFieldDefinition(field);

                fieldAsm.SimplifiedName = string.Format("{0}.{1}", parentName, memberName);

                AddAssemblyDataItem(a, fieldAsm);
            }
        }
        /// <summary>
        /// Create DocumentDataItem for corresponding AssemblyDataItem and add it to DocumentDataItemSet
        /// </summary>
        /// <param name="asm"></param>
        public DocumentDataItem CreateDocumentDataItemFor(AssemblyDataItem asm)
        {
            var docItem = new DocumentDataItem
                          	{
                          		signature = asm.SimplifiedName,
                                baseDocDirPath = baseDocDirPath
                          	};
            _hashtable.Add(docItem.signature, docItem);
            _documentList.Add(docItem);
            asm.DocDataItem = docItem;

            return docItem;
        }
 public void AddChild(AssemblyDataItem child)
 {
     _children.Add(child);
 }
 private static void AddAssemblyDataItem(ICollection<AssemblyDataItem> a, AssemblyDataItem item)
 {
     item.Parent.AddChild(item);
     a.Add(item);
 }
示例#24
0
 private static void AddAssemblyDataItem(ICollection <AssemblyDataItem> a, AssemblyDataItem item)
 {
     item.Parent.AddChild(item);
     a.Add(item);
 }
        private static void ProcessProperties(AssemblyDataItem asmDataItem, ICollection<AssemblyDataItem> a)
        {
            foreach (PropertyDefinition prop in asmDataItem.cecilType.Properties)
            {
                if (prop.GetMethod == null == !prop.GetMethod.IsPublic)
                    continue;
                var propAsm = new AssemblyDataItem(AssemblyType.Property, asmDataItem.cecilType, asmDataItem) {PInfo = prop};
                var parentName = propAsm.Parent.ItemName();
                var memberName = MemberNameFromPropertyDefinition(prop);

                propAsm.SimplifiedName = string.Format("{0}.{1}", parentName, memberName);

                AddAssemblyDataItem(a, propAsm);
            }
        }
        private static void ProcessNestedTypes(AssemblyDataItem asmDataItem, ICollection<AssemblyDataItem> a)
        {
            foreach (var nested in asmDataItem.cecilType.NestedTypes)
            {
                if (!nested.IsNestedPublic)
                    continue;
                if (nested.IsClass)
                {
                    var nestedClassAsm = new AssemblyDataItem(AssemblyType.Class, nested, asmDataItem);

                    var memberName = nested.ToString().SimplifyTypesAndArrays();
                    memberName = StringConvertUtils.LowerCaseNeedsUnderscore(memberName);

                    nestedClassAsm.SimplifiedName = memberName;
                    AddAssemblyDataItem(a, nestedClassAsm);
                    BuildAsmChildOfClass(nestedClassAsm, a);
                }
            }
        }
        private static void ProcessMethods(AssemblyDataItem asmDataItem, ICollection<AssemblyDataItem> a)
        {
            var simpleToFullName = new MultiDict<string, string>();
            foreach (var method in asmDataItem.cecilType.Methods)
            {
                if (!method.IsPublic)
                    continue;
                // we'll ignore property getter/setter
                if (method.Name.StartsWith("set") || method.Name.StartsWith("get"))
                    continue;

                var simplifiedMemberName = MemberNameFromMethodDefinition(method, true);
                simplifiedMemberName = string.Format("{0}.{1}", asmDataItem.ItemName(), simplifiedMemberName);

                var fullMemberName = MemberNameFromMethodDefinition(method, false);

                if (!simpleToFullName.Contains(simplifiedMemberName))
                    simpleToFullName.Add(simplifiedMemberName, fullMemberName);
            }

            foreach (var simplifiedMemberName in simpleToFullName.Keys)
            {
                var methodAsm = new AssemblyDataItem(AssemblyType.Method, asmDataItem.cecilType, asmDataItem);
                //{MInfo = method};
                methodAsm.SimplifiedName = simplifiedMemberName;

                AddAssemblyDataItem(a, methodAsm);
            }
        }
 public MeaningfulBlock(AssemblyDataItem asmData, string memberDoc)
 {
     Init(asmData, memberDoc);
 }
        private void ProcessAsm(AssemblyDataItem data)
        {
            Collection<ParameterDefinition> parameters = null;
            TypeDefinition returnType = null;
            switch (data.assemblyType)
            {
                case AssemblyType.Method:
                    {
                        parameters = data.MInfo.Parameters;
                        if (data.MInfo.ReturnType.ToString() != "System.Void")
                        {
                            try
                            {
                                returnType = (TypeDefinition)data.MInfo.ReturnType;
                            }
                            catch(InvalidCastException)
                            {
                                Console.WriteLine("RHS returntype = {0}", data.MInfo.ReturnType);
                            }
                        }

                        break;
                    }
                case AssemblyType.Constructor:
                    {
                        parameters = data.MInfo.Parameters;
                        break;
                    }
            }

            // Handle parameters
            if (parameters != null)
            {
                foreach (var pInfo in parameters)
                    GetOrCreateParameter(pInfo.Name).Info = pInfo;
            }

            // Handle return type
            if (returnType != null)
                GetOrCreateReturnDoc().ReturnType = returnType;
            Console.WriteLine("Full signature = {0}", this.ToString());
        }
示例#30
0
 public AssemblyDataItem(AssemblyType at, TypeDefinition td, AssemblyDataItem p) : this()
 {
     assemblyType = at;
     cecilType    = td;
     Parent       = p;
 }
示例#31
0
 public void AddChild(AssemblyDataItem child)
 {
     _children.Add(child);
 }
        private void Init(AssemblyDataItem asmData, string memberDoc)
        {
            InitBasics();

            if (asmData != null)
                ProcessAsm(asmData);
            if (memberDoc != null)
                ProcessDoc(memberDoc);
        }