add monotouch sources files
[mcs.git] / tools / cil-strip / cilstrip.cs
blob2c092650c284588ba1b95edba8085022c03e3d06
1 //
2 // mono-cil-strip
3 //
4 // Author(s):
5 // Jb Evain (jbevain@novell.com)
6 //
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
8 //
10 using System;
11 using System.IO;
12 using System.Reflection;
14 using Mono.Cecil;
16 namespace Mono.CilStripper {
18 class Program {
20 static void Main (string [] args)
22 Header ();
24 if (args.Length == 0)
25 Usage ();
27 string file = args [0];
28 string output = args.Length > 1 ? args [1] : file;
30 try {
31 AssemblyDefinition assembly = AssemblyFactory.GetAssembly (file);
32 StripAssembly (assembly, output);
34 if (file != output)
35 Console.WriteLine ("Assembly {0} stripped out into {1}", file, output);
36 else
37 Console.WriteLine ("Assembly {0} stripped", file);
38 } catch (TargetInvocationException tie) {
39 Console.WriteLine ("Error: {0}", tie.InnerException);
40 } catch (Exception e) {
41 Console.WriteLine ("Error: {0}", e);
45 static void StripAssembly (AssemblyDefinition assembly, string output)
47 Type stripper = typeof (AssemblyDefinition).Assembly.GetType ("Mono.Cecil.AssemblyStripper");
48 if (stripper == null)
49 throw new NotSupportedException ("Cecil doesn't have support for mono-cil-strip");
51 stripper.GetMethod ("StripAssembly").Invoke (null, new object [] { assembly, output });
54 static void Header ()
56 Console.WriteLine ("Mono CIL Stripper");
57 Console.WriteLine ();
60 static void Usage ()
62 Console.WriteLine ("Usage: mono-cil-strip file [output]");
63 Environment.Exit (1);