2023年11月23日发(作者:)

说明⽂档翻译

⽂章原⽂来⾃:

翻译:Jeffrey Chou

说明⽂档翻译

⽬录

主页

欢迎来到Cecil的维基!

Cecil是⼀个⽤来⽣成和检查“ECMA CIL”格式的程序和类库的⼀个类库。它全⾯地⽀持泛型,⽀持“pdb和mdb调试符号

如果你需要调整编译过程和⽅式去适应你的需要,下⾯的符号需要依赖你⽬标的.net得版本来被定义:

● NET_3_5

● NET_4_0

● SILVERLIGHT

● CF

是Mono的⼀部分,那么我可以在.net上使⽤它吗?

是的,确实可以使⽤。

⽀持.net 4.0吗?

⽆条件的⽀持。

4.我可以⽤Cecil的.net 4.0版本来操纵在⼀个.net 2.0的程序集中吗?

public static bool TryGetCustomAttribute (TypeDefinition type,

string attributeType, out CustomAttribute result)

{

result = null;

if (!tomAttributes)

return false;

foreach (CustomAttribute attribute in Attributes) {

if (me != attributeType)

通过每⼀个ModuleDefinition类型的定义,引⽤对象的范围被定义。因此,所有的输⼊的⽅法被定义在ModuleDefinition类型的对

象中,并且可以在.net运⾏时的类型系统(,Base,nfo),和Cecil的

类型系统(TypeReferenc,MethodReference,FieldReference),这两个系统中进⾏⼯作。

下⾯的例⼦展⽰了如何在⼀个ModuleDefinition类型的对象的顶部,去注⼊的⼀个ine函数的调⽤。

Copyright (c) 2008 - 2011, Jb Evain

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

●例如MethodReference或者 MethodDefinition这些实现Type⽅法的这些类型,现在这个⽅法

(MethodReference. ReturnType和Type)将会直接返回⼀个TypeReference。它避免了出现重复的模式:

Type经常在先前的Cecil代码中被使⽤。如果你仍然想要去访问⽤户⾃定义的特性或者排列⼀个返回类型上的

制定的信息,你可以使⽤ReturnType。事实上,Type现在是⼀个对于

Type的快速访问的通道。

ModuleDefinition module = dule ("");

TypeDefinition foo_bar = (t => me == "");

MethodDefinition baz = foo_ (m => == "Baz");

TypeReference string_reference = Type;

var assembly = ...;

var name = ;