Note that there are some explanatory texts on larger screens.

plurals
  1. POiterate over a class for properties
    primarykey
    data
    text
    <p>I'm trying to write a T4 template to iterate over a project folder (specified) and generate a js file based on those properties. </p> <p>I'm able to return my first class file as a ProjectItem (returns as a System.__ComObject)</p> <p>i see name is returning correctly ("MyReadModel.cs")</p> <pre><code>Public Class MyReadModel{ Public string MyName { get; set; } public int MyAge { get; set;} } </code></pre> <p>now I'm struggling to return the properties out of it. the file has a FileCodeModel as System.__ComObject. i can't find any properties.</p> <p>i tried doing the following:</p> <pre><code>projectItem.GetType().GetProperties() </code></pre> <p>but returns System.Reflection.PropertyInfo[0]</p> <p>any tips on where I'm going wrong? it appears its being cast as a com object... maybe this is wrong?</p> <p>EDIT:</p> <p><strong>references:</strong> </p> <p><a href="http://www.olegsych.com/2008/07/t4-template-for-generating-sql-view-from-csharp-enumeration/" rel="nofollow noreferrer">http://www.olegsych.com/2008/07/t4-template-for-generating-sql-view-from-csharp-enumeration/</a></p> <p><a href="https://stackoverflow.com/questions/3248078/how-to-get-t4-in-vs2010-to-iterate-over-class-properties/">How to get T4 in VS2010 to iterate over class&#39; properties</a></p> <p>Code:</p> <pre><code>&lt;# Prepare(this); #&gt; &lt;# foreach(ProjectItem pi in FindProjectItemsIn(CurrentProject.ProjectItems.Item("Commands"))) { #&gt; &lt;# WriteLine("found " + pi); #&gt; &lt;# } #&gt; &lt;#+ static DTE Dte; static Dictionary&lt;string, ResultTypeInfo&gt; ResultTypes; static TextTransformation TT; static Microsoft.CSharp.CSharpCodeProvider codeProvider = new Microsoft.CSharp.CSharpCodeProvider(); static Project CurrentProject; IList&lt;ProjectItem&gt; FindProjectItemsIn(ProjectItem start) { var list = new List&lt;ProjectItem&gt;(); FindProjectItemsIn(start, list); return list; } static bool IsFolder1(ProjectItem item) { return (item.Kind == Constants.vsProjectItemKindPhysicalFolder); } void FindProjectItemsIn(ProjectItem start, IList&lt;ProjectItem&gt; list) { foreach(ProjectItem item in start.ProjectItems) { if(IsFolder1(item)) { FindProjectItemsIn(item, list); continue; } list.Add(item); } } void Prepare(TextTransformation tt) { TT = tt; // Get the DTE service from the host var serviceProvider = Host as IServiceProvider; if (serviceProvider != null) { Dte = serviceProvider.GetService(typeof(SDTE)) as DTE; } var projectItem = Dte.Solution.FindProjectItem(Host.TemplateFile); CurrentProject = projectItem.ContainingProject; } </code></pre>
    singulars
    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.
 

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