문제

나는 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);
  }

예를 들어 메인에 적용되는 속성에 메소드 메이지가 true 또는 false로 설정 될 때 마다이 마지막 코드 블록이 확인하기를 원합니다. 내가 본 것에서, 그것은 두 속성 모두처럼 보입니다 .fields.count 및 attributes.properties.count는 0으로 설정되어 있습니까?

감사

도움이 되었습니까?

해결책

인덱서별로 속성 수집에 액세스하여 잘 작동해야합니다.

if (attribute.Constructor.DeclaringType.FullName == typeof(TraceMethodAttribute).FullName) {         
  if ((bool)attribute.Properties["MethodMessages"] == true) {
        EditMethodStart(assembly, method);
  }

방금 편집하고 확인했습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top