-
-
Notifications
You must be signed in to change notification settings - Fork 648
Migration
Peter Mortensen edited this page Sep 18, 2013
·
8 revisions
Between the versions 0.6 and 0.9 of Mono.Cecil, the API evolved in a few directions:
- Make the API easier to use.
- Reflect better the content of an assembly.
- Use .NET features of .NET 2.0 such as generics.
Porting applications to the new Mono.Cecil is easy. We suggest you branch your project using Cecil in time to stabilize it on the new version of Mono.Cecil. For most projects I’ve personally ported, half a day was enough to get it running and enjoy the speed of the new version of Cecil.
Changes to take care of:
-
AssemblyFactoryis no more. You can use theModuleDefinition.ReadModuleandAssemblyDefinition.ReadAssemblystatic methods, and callWriteon them to write them back.
-
ModuleDefinition.Typesnow only returns top level (not nested) types. If you want to iterate over all the types defined in an assembly, you can use the methodModuleDefinition.GetTypes().
-
TypeDefinition.Constructorsis merged insideTypeDefinition.Methods. It was a Cecil thing, and it was breaking the order in which methods are defined in the type.
-
ParameterDefinition.Sequencewas a one-based index of the parameter. It has been replaced byParameterDefinition.Indexwhich is zero-based. To help porting your application, you can replace your usage of theSequenceproperty to use the extension methodMono.Cecil.Rocks.ParameterReferenceRocks.GetSequence (this ParameterReference self).
-
IMethodSignature.ReturnType(which impacts types such asMethodReferenceorMethodDefinitionnow directly returns aTypeReference. It avoids the recurring pattern:method.ReturnType.ReturnTypethat was often found in previous Cecil code. If you still want to have access to the custom attributes or the marshal informations specified on the return type, you can usemethod.MethodReturnType. Actually,method.ReturnTypeis just a fast path formethod.MethodReturnType.ReturnType.
- There was an string indexer property on the
TypeDefinitionCollectionthat was used to retrieve aTypeDefinitionbased on its full name. It has been replaced by theModuleDefinition.GetTypemethod.
- The custom attribute API changed quite a bit. The old model was somewhat more direct, but it didn’t provide enough information for all cases. Most of the code using the old Cecil looks like
(string) attribute.ConstructorParameters [0]. It has to be replaced with(string) attribute.ConstructorArguments [0].Value..ConstructorArgument [0]returns aCustomAttributeArgumentthat has both aTypeReference Typeproperty and aobject Valueproperty.
-
CilWorkeris no more, it has been renamed toILProcessor, and you get one by callingGetILProcessoron aMethodBody.
- You now have to call
TypeReference.GetElementTypeandMethodReference.GetElementMethodinstead ofTypeReference.GetOriginalTypeandMethodReference.GetOriginalMethod.