Example #1
0
        public override void InitialiseFromIL()
        {
            //  Read the first two lines.
            string firstLine  = null;
            string secondLine = null;

            using (var reader = new StringReader(RawIL))
            {
                firstLine = reader.ReadLine();
                if (firstLine != null)
                {
                    secondLine = reader.ReadLine();
                }
            }

            //  From the class declaration, read the full name and tokens.
            try
            {
                string        className, templateSpecification;
                List <string> classModifiers;
                ILParseHelper.GetClassDeclarationParts(firstLine, out classModifiers, out className, out templateSpecification);
                FullName = className;
                TemplateSpecification = templateSpecification;
                ShortName             = className.Split('.').Last();
                modifiers.Clear();
                modifiers.AddRange(classModifiers);
            }
            catch (Exception)
            {
                //  todo
            }

            if (secondLine != null)
            {
                string baseType;
                if (ILParseHelper.ReadExtendsLine(secondLine, out baseType))
                {
                    BaseType = baseType;
                }
            }

            //  Read the fields and methods.
            ReadFields();
            ReadMethods();
            ReadProperties();
            ReadEvents();
        }
        private DisassembledIlClass CreateIlClassFromRawIlClass(RawILClass rawIlClass)
        {
            //  Get the raw IL.
            var rawIL = rawIlClass.ILBuilder.ToString();

            //  Get the first and second line.
            string firstLine  = null;
            string secondLine = null;

            using (var reader = new StringReader(rawIL))
            {
                firstLine = reader.ReadLine();
                if (firstLine != null)
                {
                    secondLine = reader.ReadLine();
                }
            }

            DisassembledIlClass ilClass = new DisassembledClass();

            //  We can immediately identify structures and interfaces.
            if (ILParseHelper.IsLineStructDeclaration(firstLine))
            {
                ilClass = new DisassembledStructure();
            }
            else if (ILParseHelper.IsLineInterfaceDeclaration(firstLine))
            {
                ilClass = new DisassembledInterface();
            }
            else
            {
                //  Now check the second line.
                if (secondLine == null)
                {
                    ilClass = new DisassembledClass();
                }
                else
                {
                    string baseType;
                    if (!ILParseHelper.ReadExtendsLine(secondLine, out baseType))
                    {
                        ilClass = new DisassembledClass();
                    }
                    if (baseType == @"[mscorlib]System.Enum")
                    {
                        ilClass = new DisassembledEnumeration();
                    }
                    else if (baseType == @"[mscorlib]System.MulticastDelegate")
                    {
                        ilClass = new DisassembledDelegate();
                    }
                }
            }

            //  Set the IL.
            ilClass.RawIL = rawIL;
            ilClass.InitialiseFromIL();

            //  Add any children.
            foreach (var rawChild in rawIlClass.Children)
            {
                //  Create the entity type from the entity IL.
                var childIlClass = CreateIlClassFromRawIlClass(rawChild);
                ilClass.AddChild(childIlClass);
            }

            return(ilClass);
        }