我正在使用 Cecil 尝试读取我的属性属性:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class TraceMethodAttribute : Attribute {
public TraceMethodAttribute() {
MethodStart = true;
MethodReturn = true;
MethodMessages = true;
}
public bool MethodStart { get; set; }
public bool MethodReturn { get; set; }
public bool MethodMessages { get; set; }
}
[TraceMethod(MethodMessages = false)]
static void Main(string[] args) {
}
...
if (attribute.Constructor.DeclaringType.FullName == typeof(TraceMethodAttribute).FullName) {
if ((bool)attribute.Fields["MethodMessages"] == true) {
EditMethodStart(assembly, method);
}
也就是说,我希望最后一段代码检查何时应用于 Main 的属性,例如,将 MethodMessages 设置为 true 或 false。从我所见,似乎 attributes.Fields.Count 和 attributes.Properties.Count 都设置为 0。为什么会这样?
谢谢