title: If type has StructLayoutAttribute then return in fxcop
body: <p>I am writing a custom FxCop (Code Analysis) rule using the FxCop API.</p>
  
  <p>What I want to achieve is the following:</p>
  
  <ol>
  <li>Find fields which have as declaringtype a Struct.</li>
  <li>If the struct has a "StructLayoutAttribute", ignore the field.</li>
  <li>If the field is not read-only, add a new problem.</li>
  </ol>
  
  <p>The basics are working correctly, I just can't seem to figure out how to check if the declaringtype has the StructLayoutAttribute or not.</p>
  
  <p>It so happens that the StructLayoutAttribute is not defined in the FxCop API. How would I go about finding it then?</p>
  
  
  
  <p>Some sample(C#)-code:</p>
  
  <pre><code>public override ProblemCollection Check(Member member)
  {
      Field field = member as Field;
      if (field == null)
          return null;
      if (field.DeclaringType.NodeType != NodeType.Struct)
          return null;        
      //Possibly something like: if(field.DeclaringType.Attributes .....
      // return null;
      if (!field.IsInitOnly)
      {
          Resolution resolution = GetResolution(field, field.DeclaringType);
          Problems.Add(new Problem(resolution));
      }
      return Problems;
  }
  </code></pre>
  
  <p>Addition: This should get ignored.</p>
  
  <pre><code>[StructLayout(LayoutKind.Sequential)]
  private struct MXRecord
  {
      public IntPtr Next;
      public string Name;
      public short Type;
      public short DataLength;
      public int Flags;
      public int Ttl;
      public int Reserved;
      public IntPtr NameExchange;
      public short Preference;
      public short Pad;
  }
  </code></pre>
  
  <p>And this should NOT.</p>
  
  <pre><code>private struct MXRecord
  {
      public IntPtr Next;
      public string Name;
      public short Type;
      public short DataLength;
      public int Flags;
      public int Ttl;
      public int Reserved;
      public IntPtr NameExchange;
      public short Preference;
      public short Pad;
  }
  </code></pre>
  
  <p>What I tried (as suggested) is the following:</p>
  
  <pre><code>StructLayoutAttributeType = FrameworkAssemblies.Mscorlib.GetType(Identifier.For("System.Runtime.InteropServices"),Identifier.For("StructLayoutAttribute"));
  
  Field field = member as Field;
  if (field == null)
      return null;
  if (field.DeclaringType.NodeType != NodeType.Struct)
      return null;
  AttributeNode structLayoutAttrib = field.DeclaringType.GetAttribute(StructLayoutAttributeType);
  
  if (structLayoutAttrib != null)
      return null;
  if (!field.IsInitOnly)
  {
      Resolution resolution = GetResolution(field, field.DeclaringType);
      Problems.Add(new Problem(resolution));
  }
  return Problems;
  </code></pre>