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

  • SEARCH
  • Home
  • 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 7560781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:59:26+00:00 2026-05-30T12:59:26+00:00

I want to put code that i generate automatically and new classes in different

  • 0

I want to put code that i generate automatically and new classes in different parts of my solution. Ex:

I have these projects:

  • Model
  • DAO
  • Business
  • Web

When i create manually a new entity in Model project i want to:

  • Create in Model project your IDAO class and IService class
  • Create in DAO project your DAO class.
  • Create in Business project your Service class.
  • Create in Application_Start() method that is in Web\global.asax file the code that register the interfaces to your classes (Denpendency Injection).

All things automatically. So, is it possible?

  • 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-05-30T12:59:27+00:00Added an answer on May 30, 2026 at 12:59 pm

    Solved! I use visual studio macros.

    Obs: I changed the strategy. Instead of create a T4 file (.tt), i create a common class file (.cs) with some tags that will be changed by String.Replace.

    using System;
    // place here your necessary "usings" 
    
    namespace #namespace#
    {
        /// <summary>
        /// Class responsible for #entity# data access.
        /// </summary>
        public class #class# : I#class#
        {
        }
    }
    

    The Macro:

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE90a
    Imports EnvDTE100
    Imports System.Diagnostics
    Imports System.IO
    
    Public Module Templates
        ' Get the active class (in this case will be the entity that you have just created)
        Dim entity As String = DTE.ActiveDocument.Name.Replace(".cs", "")
        Dim projects As Projects = DTE.Solution.Projects
        ' Project where are the template classes   
        Dim projectTemplates As Project = DTE.ActiveDocument.ProjectItem.ContainingProject
    
        Sub CreateCRUD()
    
            ' Exemple of creating DAO Class
            CreateClass("NamespaceWhereAreYouProject.Repositorio\ NamespaceWhereAreYouProject.Repositorio.csproj", _
                        "DAL", _
                        " NamespaceWhereAreYouProject.Repository.DAL", _
                        "DAO" + entity, _
                        "DAOTemplate.cs")
    
        End Sub
    
        Private Sub CreateClass(ByVal currentProject As String, _
                                     ByVal currentFolder As String, _
                                     ByVal currentNamespace As String, _
                                     ByVal currentClass As String, _
                                     ByVal currentTemplate As String)
    
            ' Loading attributes
            Dim project As Project = projects.Item(currentProject)
            Dim folder As ProjectItem = project.ProjectItems.Item(currentFolder)
            Dim currentTemplatePath As String = projectTemplates.ProjectItems.Item("Templates") _
                .ProjectItems.Item(currentTemplate).Properties.Item("FullPath").Value
            Dim newClassPath As String = folder.Properties.Item("FullPath").Value + currentClass + ".cs"
    
            ' Creating class
            folder.ProjectItems.AddFromTemplate(currentTemplatePath, currentClass + ".cs")
            Dim newText As String = File.ReadAllText(newClassPath) _
                .Replace("#class#", currentClass) _
                .Replace("#namespace#", currentNamespace) _
                .Replace("#entity#", entity)
            File.WriteAllText(newClassPath, newText)
        End Sub
    End Module
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that I want to put into an svn repository for
When using setTimeout , you have to put the code you want to execute
I have a page layout for my MOSS '07 site that I want put
i have the below code i want to put in a global method set
i want to put the id into the colorbox below this code nom works
hey, hi i want put limit on object creation means a class can have
I have a QueueProcessor class that processes a work queue. I want to send
I'm trying to generate code from an XSD that has two complexTypes extending a
I want to pull list of colors from model and put the color select
I have a table that's generated by a normal PHP loop. What I want

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.