Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's pretty easy to do with Mono.Cecil:</p> <pre><code>using Mono.Cecil; using Mono.Cecil.Cil; class Demo { static void Main() { var winphoneAssemblies = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone"; var assemblyResolver = new DefaultAssemblyResolver(); assemblyResolver.AddSearchDirectory(winphoneAssemblies); var winphoneCorlib = assemblyResolver.Resolve("mscorlib"); var module = ModuleDefinition.CreateModule("Test", new ModuleParameters { AssemblyResolver = assemblyResolver, Runtime = TargetRuntime.Net_2_0, Kind = ModuleKind.Dll, }); // trick to force the module to pick the winphone corlib module.Import(winphoneCorlib.MainModule.GetType("System.Object")); var type = new TypeDefinition("Test", "Type", TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract, module.TypeSystem.Object); module.Types.Add(type); var method = new MethodDefinition("Identity", MethodAttributes.Public | MethodAttributes.Static, module.TypeSystem.Int32); method.Parameters.Add(new ParameterDefinition("i", ParameterAttributes.None, module.TypeSystem.Int32)); type.Methods.Add(method); var il = method.Body.GetILProcessor(); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ret); module.Write("Test.dll"); } } </code></pre> <p>A few things to note:</p> <ul> <li>The need to create the module with an assembly resolver targeting the winphone assemblies.</li> <li>A little trick to make sure the module picks up the proper winphone mscorlib (will be fixed in the next version of Cecil).</li> <li>Silverlight assemblies have the metadata version of the .net 2.0 framework.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload