title: c# attribute to validate method parameters
body: <p>I have a windows service and I am passing in a userId to each of the service calls that is validated against the database. Right now I have to call that validation method in each of the  methods internally. I was trying to make a c# attribute that I could prefix each method with and have it do the validation for me but I'm not sure how to read the methods userId argument from the attribute. </p>
  
  <p>This is what I have:</p>
  
  <pre><code>public int GetANumber(Guid userId){
  
  ValidateUserId(userId);
  
  return 1;
  
  }
  </code></pre>
  
  <p>This is what I want:</p>
  
  <pre><code>[ValidateUserId]
  public int GetANumber(Guid userId){
  
      return 1;
  
      }
  </code></pre>
  
  <p>This is what I have so far for my attribute:</p>
  
  <pre><code>[AttributeUsage(AttributeTargets.Method)]
      public sealed class ValidateUserId : Attribute
      {
          public ValidateUserId()
          {
              //need to get userId from method here and check against db
          }
      }
  </code></pre>
  
  <p>Any ideas?</p>