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 480265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:52:31+00:00 2026-05-13T00:52:31+00:00

Background I have a few scripts that run as part of my build process

  • 0

Background

I have a few scripts that run as part of my build process that look at the various source code files and generate some more source code for me.

The scripts use CodeDom to generate them and they read the .cs files using a simple text reader.

Question

One of the scripts is looking for use of a specific class attribute called PageMenuItem and its purpose is to build a static list of page menu items.

It does this right now by reading all of the .cs files and looks for "PageMenuItem" attributes, then it counts the number of arguments and tries to figure out which constructor is being used so it can pull apart the various pieces of information.

There are 7 constructors for PageMenuItem with various parameters, so it is getting very difficult to determine from the .cs source code which constructor is being used and therefore how to parse out the information.

Instead of trying to parse the text myself, I would like to simply construct a PageMenuItem object in memory and then use its properties.

So, I need a way of taking the attribute declaration from the .cs file and construct a new instance of PageMenuItem from it.

Is that possible?


Another way of asking this question:

Given this string:

string myCodeStatement = "[MyAttribute(\"asdf\", \"foo\")]";

How can I create an object of the type MyAttribute so that I can work with that object? I have full access to the source code that defines MyAttribute.

  • 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-13T00:52:31+00:00Added an answer on May 13, 2026 at 12:52 am

    This script is part of the build process, so it needs to be pretty quick. Also, it generates source code that is going to get compiled, so I want to avoid “double compiling” my project.

    I also don’t want to have to compile and load an assembly just to reflect against it, which seems “expensive” to do several hundred times during my build process.

    I decided that I just needed to fix up how I am parsing the attributes now. —

    I’m already reading the source code and trying to count the number of attributes. I decided I could modify that code to just parse the arguments into their types and then use Activator.CreateInstance() using my parsed arguments. Activator will figure out which constructor to use and I will get an instance of my attribute class and can use its properties.

    I already know which types are available in the attribute’s constructor, so I wrote a little method that parses the stuff between the parans into their correct type (string, int, guid, etc) and then I pass that object array to the Activator.

    The Activator does the hard work of finding the correct constructor and gives me back an instance of my attribute class.

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

Sidebar

Related Questions

I have a Java process that runs in the background. How can I quickly
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.
Background: we have an application that generates reports from HTML (that may or may
We currently have some php code that allows an end user to update records
I have a problem with the following javascript code. Basically I want to run
i have a cronjob in php that calculates few business rules (eg: net rev,
Background: I have a little video playing app with a UI inspired by the
Background I have a massive db for a SharePoint site collection. It is 130GB
Background I have been asked by a client to create a picture of the
Background: I have a module which declares a number of instance methods module UsefulThings

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.