Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:11:23+00:00 2026-06-17T13:11:23+00:00

Is there a way to do reflection pre-compile – at design time? My intent

  • 0

Is there a way to do reflection pre-compile – at design time?

My intent is to use T4 to spit out custom codes based on classes that implement certain interfaces. I know I can call upon reflection, but I want the T4 script to spit out the additional code before compile, otherwise I will need to compile the code twice, once to generate dlls, twice to let T4 reflect on the previously generated dll and add additional scaffolding.

Is there a way to do reflection at design time?

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:11:24+00:00Added an answer on June 17, 2026 at 1:11 pm

    There actually is a way of generating code pre-build based on the CodeModel provided by Visual Studio Automation: The Project Interface provides a Property “CodeModel” that contains a graph of all model artifacts in that project. You might want to traverse it in order to find classes, interfaces, properties, … based on which you generate your output code.

    dandrejw already mentioned the Tangible T4-Editor. It has got a free template gallery. There is a reusable template “tangible Visual Studio Automation Helper” which should be extremely helpful in your case. Using this template you could solve your issue like this:

    This is code within a t4 template detecting all classes that implement INotifyPropertyChanged.

    <#
        // get a reference to the project of this t4 template
        var project = VisualStudioHelper.CurrentProject;
        // get all class items from the code model
        var allClasses = VisualStudioHelper.GetAllCodeElementsOfType(project.CodeModel.CodeElements, EnvDTE.vsCMElement.vsCMElementClass, false);
    
        // iterate all classes
        foreach(EnvDTE.CodeClass codeClass in allClasses)
        {
            // get all interfaces implemented by this class
            var allInterfaces = VisualStudioHelper.GetAllCodeElementsOfType(codeClass.ImplementedInterfaces, EnvDTE.vsCMElement.vsCMElementInterface, true);
            if (allInterfaces.OfType<EnvDTE.CodeInterface>()
                             .Any(i => i.Name == "INotifyPropertyChanged"))
            {
                #>Render your code here<#
            }
        }
    #>
    

    Put your output code where the code snippet says “Render your code here”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there way to better identify design pattern in source codes, esp. if you
I imagine that there has to be some way to use reflection to do
Is there any way to use a custom format for assembly versions, when building
Is there any way (utilizing Reflection I hope) that I can make an instantiated
Is there a way to execute internal code via reflection? Here is an example
is there a way to retrieve type T from IEnumerable<T> through reflection? e.g. i
Possible Duplicate: Get variable name. javascript “reflection” Is there a way to know the
Is there any way using reflection in C# 3.5 to determine if type of
Is there any way to using reflection in .net to get a property's value
Through reflection, is there some way for me to look at a generic List's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.