Daniel Earwicker

Fellow of the Royal Society of People Who Make Up Their Own Titles (FRSPWMUTOT)

Old version of this blog is here: http://incrediblejourneysintotheknown.blogspot.com/

Why did I move? Because in WordPress, I can copy code from Visual Studio, paste it into the WordPress post editor, and it automatically works sensibly. Blogspot is comparatively dreadful at this.

  1. AspNyc
    August 30, 2009 at 3:05 am | #1

    I came across an old post of yours ( http://stackoverflow.com/questions/616554/is-reflection-really-that-slow-that-i-shouldnt-use-it-when-it-makes-sense-to ), in which you said the following:

    “when you are reflecting to find all the types that support a certain attribute, you have a perfect opportunity to use caching. That means you don’t have to use reflection more than once at runtime.”

    That seems like something I’d want to do in a class that I’m building, but I don’t know how to do it. Here’s the code I have so far, taken from my recent question ( http://stackoverflow.com/questions/1352924/c-and-reflection ):

    public static void PrintAPI()
    {
    Type type = typeof(API);
    PropertyInfo[] props = type.GetProperties(BindingFlags.Public);

    // Sort properties alphabetically by name (http://www.csharp-examples.net/reflection-property-names/)
    Array.Sort(props, delegate(PropertyInfo p1, PropertyInfo p2)
    {
    return p1.Name.CompareTo(p2.Name);
    });

    foreach (PropertyInfo propertyInfo in type.GetProperties())
    {
    Console.WriteLine(“{0} [type = {1}]“, propertyInfo.Name, propertyInfo.PropertyType);
    }
    }

    Any suggestions how to go about caching the list of property names and types only at runtime? I’m brand-new to C# (coming from the dark ages of VBScript/Classic ASP), so my apologies if this is a really basic feature I’m missing.

    -= Jesse =-

  2. georgy
    September 24, 2010 at 3:08 pm | #2

    Are you *that* Daniel Earwicker?

    http://www.youtube.com/user/danielearwicker

    If so, I’m totally impressed.

    • earwicker
      September 24, 2010 at 6:34 pm | #3

      Yes I am, thanks!

  3. January 24, 2011 at 3:35 am | #4

    I’ve been obsessively watching your youtube videos for a good while and then I stumbled upon an answer from a certain Mr. Earwicker on stackoverflow… could it be? Yes, yes it is. Cool :D

    • earwicker
      January 24, 2011 at 3:01 pm | #5

      Thanks!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.