Note that there are some explanatory texts on larger screens.

plurals
  1. POT4 method.Attributes empty on Inherited Base Class
    primarykey
    data
    text
    <p>I'm trying to get all of the attributes on a base class. I was able to get the base class (cls.Parent) and get all of the methods on the base class, however when iterating over the methods and getting method.Attributes, it's always empty.</p> <p>How do I get the attributes on a method in the base class?</p> <p>Thanks!</p> <p>Edit: Here's the relevent code:</p> <pre><code> void LoadAPICalls() { IEnumerable&lt;CodeElement&gt; allClasses = VisualStudioHelper.CodeModel.GetAllCodeElementsOfType(VisualStudioHelper.CurrentProject.CodeModel.CodeElements, vsCMElement.vsCMElementClass, false); foreach(CodeClass item in allClasses) { if (!VisualStudioHelper.CodeModel.GetAllBaseClasses(item).Any(c =&gt; c.FullName == "System.Web.Http.ApiController")) continue; //Write out the class here. System.Text.StringBuilder sb = new System.Text.StringBuilder(); var className = item.FullName.Substring(item.FullName.LastIndexOf(".") + 1).Replace("Controller", ""); #&gt;export class &lt;#=className#&gt; {&lt;#+ var curItem = item; while (true) { var allMethods = VisualStudioHelper.CodeModel.GetAllMethods(curItem); foreach(CodeFunction method in allMethods) { IEnumerable&lt;CodeElement&gt; allAttributes = VisualStudioHelper.CodeModel.GetAllCodeElementsOfType(method.Attributes, vsCMElement.vsCMElementAttribute, true); foreach (CodeElement attribute in allAttributes) { if (attribute.Kind != vsCMElement.vsCMElementAttribute) continue; switch(attribute.FullName) { case "System.Web.Http.HttpPostAttribute": WriteHttpPost(className, method, sb); break; case "System.Web.Http.HttpGetAttribute": WriteHttpGet(className, method, sb); break; case "System.Web.Http.HttpPutAttribute": WriteHttpPut(className, method, sb); break; case "System.Web.Http.HttpDeleteAttribute": WriteHttpDelete(className, method, sb); break; } } } curItem = VisualStudioHelper.CodeModel.GetBaseClass(curItem); if (curItem == null) break; } #&gt; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload