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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:21:28+00:00 2026-05-11T04:21:28+00:00

I guess this could also be asked as to how long the created type

  • 0

I guess this could also be asked as to how long the created type name is attached to an anonymous type. Here’s the issue:

A blog had something like this:

var anonymousMagic = new {test.UserName};  lblShowText.Text = lblShowText                      .Text                      .Format('{UserName}', test); 

As sort of a wish list and a couple ways to go at it. Being bored and adventurous I took to creating an string extension method that could handle this:

var anonymousMagic = new {test.UserName, test.UserID};  lblShowText.Text = '{UserName} is user number {UserID}'                      .FormatAdvanced(anonymousMagic); 

With the idea that I would get the property info from the anonymous type and match that to the bracketted strings. Now with property info comes reflection, so I would want to save the property info the first time the type came through so that I wouldn’t have to get it again. So I did something like this:

    public static String FormatAdvanced(this String stringToFormat, Object source)     {          Dictionary<String, PropertyInfo> info;         Type test;          String typeName;         //         currentType = source.GetType();         typeName = currentType.Name;         //         //info list is a static list for the class holding this method         if (infoList == null)         {             infoList = new Dictionary<String, Dictionary<String, PropertyInfo>>();         }         //         if (infoList.ContainsKey(typeName))         {             info = infoList[typeName];         }         else         {             info = test.GetProperties()                        .ToDictionary(item => item.Name);             infoList.Add(typeName, info);         }           //         foreach (var propertyInfoPair in info)         {             String currentKey;             String replacement;              replacement = propertyInfoPair.Value.GetValue(source, null).ToString();             currentKey = propertyInfoPair.Key;              if (stringToFormat.Contains('{' + currentKey + '}'))             {                 stringToFormat = stringToFormat                                  .Replace('{' + currentKey + '}', replacement);             }         }           //         return stringToFormat;     } 

Now in testing, it seems to keep the name it created for the anonymous type so that the second time through it doesn’t get the property info off the type but off the dictionary.

If multiple people are hitting this method at the same time, is it pretty much going to work in a Session like fassion; IE the names of the types will be specific to each instance of the program? Or would it be even worse than that? At what point does that name get chucked and overwritten?

  • 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. 2026-05-11T04:21:28+00:00Added an answer on May 11, 2026 at 4:21 am

    It never does. The type is generated at compile-time and you can consider it constant and unique throughout the life of the app-domain.

    I question the value of this function though. The obvious first reason is because you don’t have much of the functionality of the Format method on the String class (no escape for brackets, no formatting of values in the brackets, etc, etc).

    The second is that it basically links the format string to the type being passed in, so they are not swapped out easily. If I had two classes which had the same conceptual value, but different properties naming it, I have to change my format string to display it with your method to compensate for the fact that the property name is embedded in the format string.

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

Sidebar

Related Questions

I am busy writing my thesis (so, I guess this could count as a
Well, I guess this day had to come. My client's website has been compromised
Duplicate - this exact question was asked here - the only solution seems to
I guess this question was asked in one way or another, but I'm looking
Some student asked this on another site, but got no answers. I had a
I know this question is asked many a times,and i am also implementing the
This has probably been asked many times but here it goes : I have
I guess this is an odd one, and the answer is most likely it
I have a HashMap (although I guess this question applies to other collections) of
Okay, I guess this is entirely subjective and whatnot, but I was thinking about

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.