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.

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 =-
Are you *that* Daniel Earwicker?
http://www.youtube.com/user/danielearwicker
If so, I’m totally impressed.
Yes I am, thanks!
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
Thanks!