mono.cecil

Replace references to a type/namespace using Mono.Cecil

梦想与她 提交于 2019-12-09 12:31:27
问题 Background (unnecessary, confusing, only for the curious) I'm using the free version of Unity3D for Mobile and it doesn't allow me to use the System.Net.Sockets namespace on mobile devices. The problem is that I'm using a compiled .dll library (namely, IKVM) that references the System.Net.Sockets . I'm not actually using the classes in IKVM that references that references System.Net.Sockets , so instead of buying the $3000 Unity Pro mobile licenses, I made a stub library of the Sockets

CCI vs. Mono.Cecil — advantages and disadvantages

℡╲_俬逩灬. 提交于 2019-12-08 23:13:00
问题 I have seen articles discussing these two similar frameworks, but most of them are two years old or so. I assume both projects are much more mature now than they were two years ago, and the situation is a more complex one. So given the current states of each of the libraries, I was hoping someone could provide a detailed explanation of the advantages and disadvantages of each, and which should be preferred at present time. 回答1: CCI Pros: Can give you finer-grained control on your performance

Maintaining context of type arguments with Mono.Cecil

半世苍凉 提交于 2019-12-08 13:31:31
问题 After learning how to properly access the fields and properties of a List with Mono.Cecil , it was pointed out that you need to make sure that the context of the type arguments is maintained on the List object that you're working with (which makes sense). What's the proper way to do this? Edit (based on @Simon's request) Given you have a TypeReference for a list, for example System.Collections.Generic.List`1<MyNamespace.MyObject> and you want to access it's fields, you'll actually need a

How do i change the BaseType (define in other assembly) of a TypeDefinition?

倖福魔咒の 提交于 2019-12-08 02:56:40
问题 I have been struggling to change the BaseType of a TypeDefinition in specific scenario. Let's say we have below assemblies. Assembly1: Class MyAssembly1Class: Test1Class{} Assembly2: Class MyAssembly2Class: Test2Class{} Now I want to change the Base class of "MyAssembly1Class" defined in "Assembly1" to "MyAssembly2Class" defined in assembly2. i.e. Class MyAssembly1Class: MyAssembly2Class{} How can this be achieved? I tried code below: public static void UpdateDerviedTextBoxTypes

Injecting GeneratedCodeAttribute with Mono.Cecil

╄→гoц情女王★ 提交于 2019-12-08 02:51:40
问题 I'm manupulating my .net 2.0 assemblies with Mono.Cecil. After manipulation I want to mark assembly as processed by injecting a module attribute var stringType = _module.Import(typeof(string)); var baseCtor = _module.Import(typeof(GeneratedCodeAttribute).GetConstructor(new[] { typeof(string), typeof(string) })); var result = new CustomAttribute(baseCtor); result.ConstructorArguments.Add(new CustomAttributeArgument(stringType, "ProcessedBySomething")); result.ConstructorArguments.Add(new

Detect Silverlight version required by an assembly

心不动则不痛 提交于 2019-12-08 02:43:37
问题 How can I tell whether Silverlight 2 is sufficient for an assembly or Silverlight 3 is required? I have all information that is available through reflection (Mono.Cecil). Same question for SL 3 versus 4. Thanks in advance. 回答1: You cannot tell from just the class library and its metadata - this can only be reliably determined from a Silverlight application's embedded manifest file in the .Xap. 回答2: This might be exactly what you are looking for: Assembly asm = Assembly.GetExecutingAssembly();

.NET CIL manipulation of evaluation stack

假如想象 提交于 2019-12-07 04:07:10
问题 I have this sequence of CIL codes which I injected through the use of Mono.Cecil . However, the modified .NET C# application will not run. Objective: Manually load and pop values from stack to display in Console.WriteLine for (int i = 0; i < 3; i++) { int z = some value popped manually from stack; Console.WriteLine(z); } This is the simple main() program I modified: .method private hidebysig static void Main(string[] args) cil managed { .entrypoint .maxstack 5 .locals init ( [0] int32 num, [1

Accessing properties on System.Collections.Generic.List

北战南征 提交于 2019-12-07 03:41:53
问题 Using Mono.Cecil I can iterate over the fields on System.Collections.Generic.List ( _items , _size , _version , etc.), however if I try to use them I always get the exception Member 'T[] System.Collections.Generic.List`1::_items' is declared in another module and needs to be imported I have two questions regarding this: Is it not possible to access the underlying fields of the generics? If it is possible, what would the import statement look like for this? I've successfully accessed private

Detect Silverlight version required by an assembly

痞子三分冷 提交于 2019-12-06 09:42:45
How can I tell whether Silverlight 2 is sufficient for an assembly or Silverlight 3 is required? I have all information that is available through reflection (Mono.Cecil). Same question for SL 3 versus 4. Thanks in advance. You cannot tell from just the class library and its metadata - this can only be reliably determined from a Silverlight application's embedded manifest file in the .Xap. James Campbell This might be exactly what you are looking for: Assembly asm = Assembly.GetExecutingAssembly(); string[] parts = asm.FullName.Split(','); string version = parts[1]; http://forums.silverlight

Injecting GeneratedCodeAttribute with Mono.Cecil

99封情书 提交于 2019-12-06 07:39:06
I'm manupulating my .net 2.0 assemblies with Mono.Cecil. After manipulation I want to mark assembly as processed by injecting a module attribute var stringType = _module.Import(typeof(string)); var baseCtor = _module.Import(typeof(GeneratedCodeAttribute).GetConstructor(new[] { typeof(string), typeof(string) })); var result = new CustomAttribute(baseCtor); result.ConstructorArguments.Add(new CustomAttributeArgument(stringType, "ProcessedBySomething")); result.ConstructorArguments.Add(new CustomAttributeArgument(stringType, "1.0")); After saving the assembly it become dependent on .net 4.0,