예제 #1
0
        private static string GetCSharpCode(object source)
        {
            var output         = new ICSharpCode.Decompiler.PlainTextOutput();
            var language       = Model.Languages.GetLanguage("C#");
            var shortDecompile = new Model.DecompilationOptions {
                FullDecompilation = false
            };
            var fullDecompile = new Model.DecompilationOptions {
                FullDecompilation = true
            };

            var assembly = source as AssemblyDefinition;

            if (assembly != null)
            {
                language.DecompileAssembly(assembly, "", output, shortDecompile);
                return(output.ToString());
            }

            var ns = source as NamespaceDefinition;

            if (ns != null)
            {
                //writer.WriteNamespace(ns, output, null);
                //return output.ToString();
                return("NOT IMPLEMENTED YET");
            }

            var module = source as ModuleDefinition;

            if (module != null)
            {
                //writer.WriteModule(module, output, null);
                //return output.ToString();
                return("NOT IMPLEMENTED YET");
            }

            var type = source as TypeDefinition;

            if (type != null)
            {
                language.DecompileType(type, output, fullDecompile);
                return(output.ToString());
            }

            var method = source as MethodDefinition;

            if (method != null)
            {
                language.DecompileMethod(method, output, fullDecompile);
                return(output.ToString());
            }

            var property = source as PropertyDefinition;

            if (property != null)
            {
                language.DecompileProperty(property, output, fullDecompile);
                return(output.ToString());
            }

            var field = source as FieldDefinition;

            if (field != null)
            {
                language.DecompileField(field, output, fullDecompile);
                return(output.ToString());
            }

            var @event = source as EventDefinition;

            if (@event != null)
            {
                language.DecompileEvent(@event, output, fullDecompile);
                return(output.ToString());
            }

            return("NOT IMPLEMENTED YET");
        }