<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx</link><description>User : The typeof(T) operator in C# essentially means “compiler, generate some code that gives me an object at runtime which represents the type you associate with the name T”. It would be nice to have similar operators that could take names of, say,</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9633942</link><pubDate>Thu, 21 May 2009 19:11:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9633942</guid><dc:creator>Ben Voigt [C++ MVP]</dc:creator><description>&lt;P&gt;But Eric, there's one really big advantage of typeof(name) vs GetType("name") ... it's checked at compile time. &amp;nbsp;This also lets refactoring tools get in on the action. &amp;nbsp;That's a pretty big reason to go ahead and try to get infoof approved. &amp;nbsp;I think there'd also be a significant performance delta (because typeof stores a metadata token, not strings and no runtime searching, right?)&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Those are all good reasons to do the feature, yes. -- Eric&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Consider that one of the primary use cases can be expected to be white box testing -- letting the test assembly access private members requires reflection, and it would be really nice if it could use a compile-time checked syntax and enable refactoring.&lt;/P&gt;
&lt;P&gt;Yeah, the syntax may end up not being pretty in order to accommodate those edge cases, for the instance you mentioned you'd need something like:&lt;/P&gt;
&lt;P&gt;infoof(C&amp;lt;T=int&amp;gt;.Bar(T,int))&lt;/P&gt;
&lt;P&gt;But that's still an awful lot more concise than chaining together calls to GetMethod with GetGenericTypeParameters, etc.&lt;/P&gt;
&lt;P&gt;You can probably make your life easier by only searching for bare method names in the current class (where generics names are already in scope), not base classes. &amp;nbsp;If you want a method from any other class then qualify it.&lt;/P&gt;
&lt;P&gt;Of course, GetMethod and friends have some options -- do you include static members or instance, public only or all visibilities, etc? &amp;nbsp;How do you request the MethodInfo of a property's getter vs the PropertyInfo? &amp;nbsp;I wouldn't want to have separate keywords for these so you'd need some syntax for patching them on:&lt;/P&gt;
&lt;P&gt;infoof&amp;lt;method,instance,public&amp;gt;(C&amp;lt;T=int&amp;gt;.Bar(T,int))&lt;BR&gt;infoof&amp;lt;getter,instance,public&amp;gt;(String.Length)&lt;BR&gt;infoof&amp;lt;property,static,public&amp;gt;(String.Empty)&lt;/P&gt;
&lt;P&gt;Still an awful lot better than the runtime reflection option.&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Sure, it is better. But look at how much new syntax you just added to the language, for a feature that would get very little mainstream usage, compared to, say, auto props, or query comprehensions. Offer developers a pony and of course they say they want a pony; that's unsurprising. My point is that if we give you the pony, then the unicorns we'd like to give you don't fit into the budget anymore. -- Eric&lt;/P&gt;&lt;/DIV&gt;</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634036</link><pubDate>Thu, 21 May 2009 20:20:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634036</guid><dc:creator>Mike</dc:creator><description>&lt;P&gt;Poor's man infoof:&lt;/P&gt;
&lt;P&gt;class Program {&lt;BR&gt;static MethodInfo infoof&amp;lt;T&amp;gt;(Action&amp;lt;T&amp;gt; d) {&lt;BR&gt;return d.Method;&lt;BR&gt;}&lt;BR&gt;static MethodInfo infoof&amp;lt;T1, T2&amp;gt;(Action&amp;lt;T1, T2&amp;gt; d) {&lt;BR&gt;return d.Method;&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;static void Main(string[] args) {&lt;BR&gt;Console.WriteLine(infoof&amp;lt;string&amp;gt;(Console.WriteLine));&lt;BR&gt;Console.WriteLine(infoof&amp;lt;string, string&amp;gt;(Console.WriteLine));&lt;BR&gt;}&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;Of course, it doesn't cover everything and it has the overhead of creating a delegate but hey, no strings needed!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Cute. There are similar tricks you can do with expression trees; make a lambda that does the call you want, and then extract the method info from the tree. -- Eric&lt;/P&gt;&lt;/DIV&gt;</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634088</link><pubDate>Thu, 21 May 2009 20:58:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634088</guid><dc:creator>Daniel Earwicker</dc:creator><description>&lt;p&gt;Given that the type of infoof(Thing) can already vary between PropertyInfo and MethodInfo, you could also allow it to be IEnumerable&amp;lt;MethodInfo&amp;gt; if the method name is overloaded.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634288</link><pubDate>Thu, 21 May 2009 23:33:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634288</guid><dc:creator>pminaev</dc:creator><description>&lt;p&gt;&amp;gt; Bummer. Because most of the time I really just want to get the method info of the method I’m currently running, for logging purposes during my test suites.&lt;/p&gt;
&lt;p&gt;I think that may have been true (i.e. the most common case) before WPF shipped, but now? Every time I declare a new dependency property, I have to deal with stringified property names. Ditto for OnPropertyChange methods. A typo anywhere along the line, and a very subtle bug is introduced...&lt;/p&gt;
&lt;p&gt;Frankly, I would be glad to have a &amp;quot;dumb&amp;quot; infoof that would require spelling out every single bit explicitly, with no overload resolution, implicit disambiguation etc ever taking place. E.g.:&lt;/p&gt;
&lt;p&gt; &amp;nbsp;infoof(int C.Bar) // instance property&lt;/p&gt;
&lt;p&gt; &amp;nbsp;infoof(static int C.Bar) // static property&lt;/p&gt;
&lt;p&gt; &amp;nbsp;infoof(void C.Blah(int, int)) // non-generic method taking two ints&lt;/p&gt;
&lt;p&gt; &amp;nbsp;infoof(void C.Blah&amp;lt;T&amp;gt;(T, T)) // generic method&lt;/p&gt;
&lt;p&gt; &amp;nbsp;infoof(void C.Blah&amp;lt;int&amp;gt;(int ,int)) // a specific instantiation of that same method&lt;/p&gt;
&lt;p&gt; &amp;nbsp;infoof(void C.Blah&amp;lt;int&amp;gt;(int ,int)) // a specific instantiation of that same method&lt;/p&gt;
&lt;p&gt; &amp;nbsp;infoof(void C&amp;lt;T&amp;gt;.Blah()) // method of an open generic type&lt;/p&gt;
&lt;p&gt; &amp;nbsp;infoof(void C&amp;lt;int&amp;gt;.Blah()) // method of a closed generic type &lt;/p&gt;
&lt;p&gt;Wordy? Yes, sure, but it solves the &amp;quot;uncaught typo&amp;quot; problem, and doesn't leave the room for ambiguities.&lt;/p&gt;
&lt;p&gt;By the way, wasn't &amp;quot;new&amp;quot; syntax for delegate instantiation in C# 1.0, before assignment was sugared for delegate lvalues and method groups, also lengthy for the same reason (to require the user to explicitly specify the delegate type, and therefore avoid the need to deal with overload resolution)?&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634292</link><pubDate>Thu, 21 May 2009 23:38:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634292</guid><dc:creator>pminaev</dc:creator><description>&lt;p&gt;&amp;gt; Given that the type of infoof(Thing) can already vary between PropertyInfo and MethodInfo, you could also allow it to be IEnumerable&amp;lt;MethodInfo&amp;gt; if the method name is overloaded.&lt;/p&gt;
&lt;p&gt;When you use infoof(), you'd normally want to get one particular method. If you instead get a sequence, and still has to work with reflection methods on those MethodInfo objects to find the method you need (by argument count etc), you might as well just use reflection from the get go. For infoof() to be usable for scenarios where it's desirable, it really needs to be able to unambiguously identify the specific method/property.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634323</link><pubDate>Fri, 22 May 2009 00:10:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634323</guid><dc:creator>Voltaire</dc:creator><description>&lt;P&gt;The perfect is the enemy of the good.&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Point taken. But my point is that the resource-consuming mediocrity is the enemy of the awesome. Like I said before, how many free unicorns are you willing to give up in order to get this free pony? -- Eric&lt;/P&gt;&lt;/DIV&gt;</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634348</link><pubDate>Fri, 22 May 2009 00:25:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634348</guid><dc:creator>Daniel Earwicker</dc:creator><description>&lt;p&gt;@pminaev - yes, but the remaining problems could then be solved with some extension methods defined on IEnumerable&amp;lt;MethodInfo&amp;gt;.&lt;/p&gt;
&lt;p&gt;MethodInfo mi = infoof(SomeMethod).GetOverload&amp;lt;int, string&amp;gt;();&lt;/p&gt;
&lt;p&gt;The overload selection would not be checked at compile time, but at least the name would be.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634362</link><pubDate>Fri, 22 May 2009 00:29:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634362</guid><dc:creator>Brad</dc:creator><description>&lt;p&gt;I agree with pminaev. In many ways, I love WPF, but the whole string names for dependency properties and OnPropertyChange is an ugly mess.&lt;/p&gt;
&lt;p&gt;I imagine that all of the reflection that WPF is doing is probably also a performance bottleneck (although I can't back that up).&lt;/p&gt;
&lt;p&gt;Perhaps the real solution to this problem isn't infoof but something like a property delegate.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634398</link><pubDate>Fri, 22 May 2009 00:54:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634398</guid><dc:creator>pminaev</dc:creator><description>&lt;p&gt;@Daniel&lt;/p&gt;
&lt;p&gt;&amp;gt; yes, but the remaining problems could then be solved with some extension methods defined on IEnumerable&amp;lt;MethodInfo&amp;gt;.&lt;/p&gt;
&lt;p&gt;Not really - you open the same can of worms Eric described (e.g. how do you differentiate between Foo(int,int), and Foo&amp;lt;T=int&amp;gt;(T, T)?), you just move the problems from compiler to library space. But they don't go away.&lt;/p&gt;
&lt;p&gt;@Brad&lt;/p&gt;
&lt;p&gt;&amp;gt; Perhaps the real solution to this problem isn't infoof but something like a property delegate.&lt;/p&gt;
&lt;p&gt;I don't see how it would help for WPF dependency properties. A delegate for an instance property would require an instance (just as a delegate for a method property requires an instance) when constructed using language sugar, and not via reflection. And when you register WPF dependency properties, you do it in static initializers and/or ctor, so you don't have that instance.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634417</link><pubDate>Fri, 22 May 2009 01:24:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634417</guid><dc:creator>Paul Batum</dc:creator><description>&lt;p&gt;I no longer pine for infoof now that we have expression trees, but it does seem a little unfortunate that there are now many .NET projects out there with relatively similar chunks of code that inspect the expression tree and give you back the appropriate info instance. What would be nice is if the BCL team would add a small library to do this work. That way when you get people still complaining about the lack of infoof, you can point them to the library and be done with it.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634460</link><pubDate>Fri, 22 May 2009 02:06:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634460</guid><dc:creator>configurator</dc:creator><description>&lt;p&gt;&amp;quot;Like I said before, how many free unicorns are you willing to give up in order to get this free pony?&amp;quot;&lt;/p&gt;
&lt;p&gt;I would have given up pretty much everything in .Net 4 for this. But that's just me - I don't use dynamic and all that, and I can't stand string properties.&lt;/p&gt;
&lt;p&gt;I agree with pminaev - this should be an extremely verbose feature, but it should exist. His syntax is pretty much what I thought of. You treat this feature as syntactic sugar, but there is no way to do this currently except string properties - which are the root of all evil because they are not compile-time checked.&lt;/p&gt;
&lt;p&gt;&amp;lt;/rant&amp;gt;&lt;/p&gt;
&lt;p&gt;Off topic: Eric, what about that memoization post you promised two and a half months ago?&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634593</link><pubDate>Fri, 22 May 2009 04:41:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634593</guid><dc:creator>commongenius</dc:creator><description>&lt;p&gt;Wow...where to begin...&lt;/p&gt;
&lt;p&gt;&amp;quot;...nowhere in C# previously did we have a parenthesized, comma-separated list of types. But that’s not at all hard to parse.&amp;quot;&lt;/p&gt;
&lt;p&gt;In fact, such a syntax DOES exist: Bar(int, int) is how you specify overload resolution in C# XML documentation, the parser for which is already part of csc. In fact, it is not at all clear to me why the XML doc overload resolver couldn't be turned into infoof exactly as is; surely that would give us our 80% with minimal effort?&lt;/p&gt;
&lt;p&gt;&amp;quot;But look at how much new syntax you just added to the language, for a feature that would get very little mainstream usage, compared to, say, auto props, or query comprehensions.&amp;quot;&lt;/p&gt;
&lt;p&gt;If you offered me a choice between either automatic properties and query comprehensions, or infoof, I would pick infoof without hesitation. Query comprehension syntax is nicer to read and write than method syntax in many cases, but not excessively so; and automatic properties are almost useless, especially in the presence of code snippets. Contrast that to infoof, which has NO alternative implementation (and NO, the runtime-evaluated expression tree tricks are nowhere near the same thing), but is critical for avoiding runtime failures when working with metadata, and surely the decision becomes obvious? And yet you and others continue to deprioritize a feature which has been more hotly requested by the community than any other that I have heard of. It is beyond maddening.&lt;/p&gt;
&lt;p&gt;+1 to configurator's comment. If C# 4 had NOTHING but infoof, I would consider that a worthy investment of the C# language team's time.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634624</link><pubDate>Fri, 22 May 2009 05:23:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634624</guid><dc:creator>Judah Himango</dc:creator><description>&lt;p&gt;Configurator and commongenius are overstating the matter. However, I would really like to see something like infoof. Even something simpler like nameof(foo.Bar) to aide in PropertyChanged and DependencyProperties would probably take care of 90% of the issues.&lt;/p&gt;
&lt;p&gt;(Unless you fine C# guys have any better ideas to resolve these issues and the others mentioned in this thread?)&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634661</link><pubDate>Fri, 22 May 2009 06:20:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634661</guid><dc:creator>Jonathan Pryor</dc:creator><description>&lt;p&gt;This largely already exists in library space. &amp;nbsp;Google up &amp;quot;static reflection&amp;quot; -- e.g. &lt;a rel="nofollow" target="_new" href="http://www.clariusconsulting.net/blogs/kzu/archive/2007/12/30/49063.aspx"&gt;http://www.clariusconsulting.net/blogs/kzu/archive/2007/12/30/49063.aspx&lt;/a&gt; -- which makes use of expression trees (as Eric suggested many comments ago, but this idea has been around for over a year).&lt;/p&gt;
&lt;p&gt;It also nicely handles the method overload resolution problem in a nice manner, all without adding additional language complexity.&lt;/p&gt;
&lt;p&gt;The only problem with it is that it's slow -- depending on the types involved, I've seen it take anywhere from 1.5x - 5x slower than normal string-based Reflection. &amp;nbsp;Acceptable? &amp;nbsp;Maybe.&lt;/p&gt;
&lt;p&gt;Fastest by far in my testing -- faster than string-based Reflection, in fact -- is Mike's &amp;quot;Poor's man infoof&amp;quot; using the Delegate.Method property. &amp;nbsp;This effectively bypasses most of the Reflection infrastructure (no Type.GetMember(), etc.), and is the closest we can get to IL member lookup resolution.&lt;/p&gt;
&lt;p&gt;The only problem with it is that it only works for methods, not properties. &amp;nbsp;(It also shows how much C#'s type inferencing sucks, as if you have e.g. Lamba.Method&amp;lt;T&amp;gt;(Action&amp;lt;T&amp;gt;) and Lambda&amp;lt;T,R&amp;gt;(Func&amp;lt;T,R&amp;gt;) methods, and have a 'static void Foo.Bar(int)' func, Lambda.Method(Foo.Bar) fails to work, even though there's only one method it can possibly match and I'd expect the parameter type to be inferrable. &amp;nbsp;Here's hoping that C#4 improves things...)&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634668</link><pubDate>Fri, 22 May 2009 06:34:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634668</guid><dc:creator>AC</dc:creator><description>&lt;p&gt;Observation: I think the real reason people want an infoof operator is that they don't want to use reflection, even though what they're asking for is available via reflection. That seems to stem from reflection being, well, confusing to use, and a little unwieldy. But like everyone else I write some unit tests, muddle through it, and when it works I have a gin and try to forget.&lt;/p&gt;
&lt;p&gt;Given that, what is the real-world context most people want this stuff for? Enlighten me.&lt;/p&gt;
&lt;p&gt;If anyone's listening, I'd like a data access technology from MS that isn't end-of-lifed after version 1. &lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634741</link><pubDate>Fri, 22 May 2009 08:41:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634741</guid><dc:creator>Joe</dc:creator><description>&lt;p&gt;Given that the guidance around reflection has, since day one, been &amp;quot;[bold]don't use it[/bold] [fineprint]unless you really really have to[/fineprint],&amp;quot; it's not surprising that people jump at any possible alternative to it. &amp;nbsp;It's awkward to use, error prone, and &amp;quot;slow&amp;quot; (which I'd guess for 90%+ of the cases it's used isn't an issue, but we all have this burning need to to make code &amp;quot;fast&amp;quot;).&lt;/p&gt;
&lt;p&gt;However, the .NET ecosystem has evolved quite a bit since 1.0, and we now live in a world of expression trees, dependency properties, code&amp;lt;-&amp;gt;contract generation, ubiquitous unit tests, right-click refactoring, etc. etc. etc. &amp;nbsp;Every one of those tools has a single shared requirement: metadata. &amp;nbsp;Without it, they are useless, and as more and more tools leverage the power of metadata, it becomes more and more difficult to avoid reflection.&lt;/p&gt;
&lt;p&gt;In short, the old guidance is showing its age. &amp;nbsp;Sooner or later, metadata will have to become a first-class citizen, with easy access, compile-time sanity checks and a fast runtime path. &amp;nbsp;Infoof may or may not be the solution that does that, but it's hard to see the need diminishing.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634765</link><pubDate>Fri, 22 May 2009 09:20:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634765</guid><dc:creator>runefs</dc:creator><description>&lt;p&gt;Just before c# 3 was released I read an article about reflection and Lambda and combining the two to make type safe reflection:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.clariusconsulting.net/blogs/kzu/archive/2006/07/06/TypedReflection.aspx"&gt;http://www.clariusconsulting.net/blogs/kzu/archive/2006/07/06/TypedReflection.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;it might be intereseting to some of the followers of this post.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634773</link><pubDate>Fri, 22 May 2009 09:33:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634773</guid><dc:creator>dimkaz</dc:creator><description>&lt;p&gt;GetCurrentMethod is not a good solution.&lt;/p&gt;
&lt;p&gt;Method can be inlined and GetCurrentMethod will return the method that IL was inlined into.&lt;/p&gt;
&lt;p&gt;What's inlined can be changed between versions of call and so the only thing one can do is to add NoInlining attribute.&lt;/p&gt;
&lt;p&gt;It's ugly&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634841</link><pubDate>Fri, 22 May 2009 11:12:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634841</guid><dc:creator>pminaev</dc:creator><description>&lt;p&gt;&amp;gt; Method can be inlined and GetCurrentMethod will return the method that IL was inlined into.&lt;/p&gt;
&lt;p&gt;I'm not 100% certain on this, but I believe that calling GetCurrentMethod() will actually prevent the calling method from being inlined, specifically so that you don't get wrong results.&lt;/p&gt;
&lt;p&gt;GetCallingAssembly() is the one that can give you the wrong result because of inlining (and documented as such).&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634863</link><pubDate>Fri, 22 May 2009 11:29:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634863</guid><dc:creator>Matthew Jones</dc:creator><description>&lt;p&gt;&amp;quot;Like I said before, how many free unicorns are you willing to give up in order to get this free pony? -- Eric&amp;quot;&lt;/p&gt;
&lt;p&gt;Haha, nice one Eric. &amp;nbsp;That made me laugh. &amp;nbsp;You have quite a way with words ;) &amp;nbsp;(That is so going on my quote list)&lt;/p&gt;
&lt;p&gt;As always I really appreciate the insight into the decision making process behind adding features. &amp;nbsp;Very nice article :)&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634904</link><pubDate>Fri, 22 May 2009 12:13:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634904</guid><dc:creator>James Hart</dc:creator><description>&lt;p&gt;I'm not sure why people see infoof as an 'alternative' to using reflection - given that we'd expect the resulting type of the expression to be a System.Reflection.MethodInfo, it's more just a better way in to reflection than starting off with a string.&lt;/p&gt;
&lt;p&gt;Basically, it comes down to the fact that typeof(Foo) turns into an IL ldtoken operation on the type metadata to get a runtime type handle, which is then resolved into a Type object by a call to Type.GetTypeFromHandle(), which is nice and quick. What we want is a clean way to compile code into the equivalent ldtoken to generate a RuntimeMethodHandle and have it resolved to a MethodInfo - something no library can accomplish, hence the pressure on the language and compiler team for a solution. That suggests a couple of things to me:&lt;/p&gt;
&lt;p&gt;1) it should never return a PropertyInfo, only a MethodInfo - there being no such thing as a RuntimePropertyHandle. It should be possible to get hold of property getter or setter methods, of course.&lt;/p&gt;
&lt;p&gt;2) it should be methodof not infoof (avoiding the confusing in-foof pronunciation that most people will read it as)&lt;/p&gt;
&lt;p&gt;3) you can put freaky syntaxes inside the methodof(...) braces - a comma separated list of typenames is NOTHING - after all, typeof(..) supports the crazy 'angle-bracketed comma-delimited list of optional whitespace tokens' syntax for generic types (e.g. typeof(Action&amp;lt;,,,,&amp;gt;). I'd accept things like Class.PropertyName.get, Class.EventName.add, Class.this[int].get... the proposals above about verbose syntaxes are fine. &lt;/p&gt;
&lt;p&gt;ultimately, what's possible in the syntax should pretty much be determined by what IL supports as ldtoken arguments in terms of methodrefs, methodspecs, and so on.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9634908</link><pubDate>Fri, 22 May 2009 12:21:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634908</guid><dc:creator>Kirk Jackson</dc:creator><description>&lt;p&gt;Hi Eric, I'm enjoying the back-story behind diferent feature decisions. I enjoyed the User / Eric conversation :)&lt;/p&gt;
&lt;p&gt;Kirk&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9635190</link><pubDate>Fri, 22 May 2009 17:01:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9635190</guid><dc:creator>David V. Corbin</dc:creator><description>&lt;p&gt;Not sure how I feel specifically about infoof().....&lt;/p&gt;
&lt;p&gt;But 100% certain that I despise ANYTHING that requires me to use a string to represent information. The lack of compile time validation has probably caused more bugs (at least in &amp;quot;successful&amp;quot; builds, not necessarily in releases) than any other single factor since I have been programming in C#.&lt;/p&gt;
&lt;p&gt;Because of this, our mandate for testing (which has to be manuaklly written) when using any feature that is string based, costs significant $$$ [we estimate $10-$25 per usage!!]&lt;/p&gt;
&lt;p&gt;If anything can be done to provide alternatives which do not rely on strings, it would trump almost every other item on &amp;quot;my&amp;quot; backlog (including most of the 3.5 and 4.0 features]&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9635386</link><pubDate>Fri, 22 May 2009 19:22:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9635386</guid><dc:creator>PQ</dc:creator><description>&lt;p&gt;Like Paul Batum said, why doesn't the team set up an &amp;quot;infoof&amp;quot; project on codeplex, promote it and open it up to everyone to cover the accepted 80 % classes with the current syntax? this could help the team in also seeing where they'd need to focus their attention when this is discussed again...&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9635551</link><pubDate>Fri, 22 May 2009 20:28:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9635551</guid><dc:creator>Ken</dc:creator><description>&lt;P&gt;Totally enjoyed the dialog driven format of this post. Definitely drives home the point. But the experience could have been enhanced by simply substituting "Booger" (aka Dudley Dawson), Mr Peabody, Beavis, or any other more palpable character in place of "User". Maybe next time?&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Indeed. I considered making the dialogue between &lt;A class="" href="http://en.wikipedia.org/wiki/Dialogue_Concerning_the_Two_Chief_World_Systems"&gt;Simplicio and Sagredo&lt;/A&gt;, or &lt;A class="" href="http://en.wikipedia.org/wiki/What_the_Tortoise_Said_to_Achilles"&gt;Achilles and the Tortoise&lt;/A&gt;, but thought that&amp;nbsp;doing so&amp;nbsp;might distract from my point. &lt;/P&gt;
&lt;P&gt;I confess that writing a dialogue about minor points of programming language design&amp;nbsp;as a conversation between&amp;nbsp;&lt;A class="" href="http://en.wikipedia.org/wiki/Beavis_and_Butt-head"&gt;Beavis and Butt-head&lt;/A&gt; had not occurred to me; I encourage you to try the form yourself and report back how well it works. -- Eric&lt;/P&gt;&lt;/DIV&gt;</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9635557</link><pubDate>Fri, 22 May 2009 20:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9635557</guid><dc:creator>Jonathan</dc:creator><description>&lt;p&gt;I can attest to the trickiness of this problem.&lt;/p&gt;
&lt;p&gt;I have been developing a library to help me generate type safe MSIL with Reflection.Emit, which define classes to wrap the various FooBuilder and FooInfo classes, and encapsulate calls to ILGenerator.Emit with the correct OpCode and validating that the types are consistent. And I have built an associated tool, that produces a library of static readonly properties to represent the members of a given class as objects from my library. Currently, the support for generics and private/protected members in this tool leaves much to be desired, and I find it is a hard problem to even define what the correct behavior is, even when the use case is only my personal use.&lt;/p&gt;
</description></item><item><title>Eric Lippert on infoof()</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9635594</link><pubDate>Fri, 22 May 2009 20:51:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9635594</guid><dc:creator>Tim Robinson</dc:creator><description>&lt;p&gt;I previously mentioned some hypothetical C# fieldof and methodof operators, which would obtain FieldInfo and MethodInfo objects, in the same way that typeof retrieves Type at runtime. Eric Lippert explains the pros and cons of a combined infoof operator,&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9635738</link><pubDate>Fri, 22 May 2009 22:07:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9635738</guid><dc:creator>pminaev</dc:creator><description>&lt;p&gt;@James&lt;/p&gt;
&lt;p&gt;&amp;gt; it should never return a PropertyInfo, only a MethodInfo - there being no such thing as a RuntimePropertyHandle. It should be possible to get hold of property getter or setter methods, of course.&lt;/p&gt;
&lt;p&gt;I think you're putting the implementation before the usage scenarios. There are many cases where what we want is the property - in fact, I dare say that such cases would probably make the majority. If a feature would be implemented that does not achieve this, it's next to useless, no matter how efficiently it's implemented.&lt;/p&gt;
&lt;p&gt;To be honest, I don't care much about efficiency for such things anyway (they aren't likely to be used in tight inner loops, or other scenarios where the hit would be noticeable). If it's as slow as reflection, it's fine by me. The only thing I really want is compile-time checking and type safety. &lt;/p&gt;
&lt;p&gt;Looking at dependency properties again, the code:&lt;/p&gt;
&lt;p&gt;class Foo {&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static readonly DependencyProperty BarProperty = DependencyProperty.Register(&amp;quot;Bar&amp;quot;, typeof(int), typeof(Foo));&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public int Bar { ... }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Now there are quite a few points where it can go wrong. We need to be sure that the string &amp;quot;Bar&amp;quot; actually matches the name of the property Bar; we need to make sure that registered type for the property matches the actual type; and we need to make sure that owner type is correct. All of these are not in any way checked statically. Furthermore, refactoring tools won't catch them, either - if you rename Bar or change its type, you have to hunt all registered dependency properties manually, without help from auto-rename or &amp;quot;Find Usage&amp;quot;.&lt;/p&gt;
&lt;p&gt;Now compare to something like this:&lt;/p&gt;
&lt;p&gt;class Foo {&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static readonly DependencyProperty BarProperty = DependencyProperty.Register(infoof(int Foo.Bar));&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public int Bar { ... }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Both name and type of property are checked at compile-time. Owner type is obtained from PropertyInfo automatically. &lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9637053</link><pubDate>Sat, 23 May 2009 12:42:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9637053</guid><dc:creator>Wilfried Wieser</dc:creator><description>&lt;p&gt;I think it is quite &amp;quot;natural&amp;quot; that the design process for a feature supposed to give information about some existing language feature X reveals lots of corner cases if X itself has corner cases (like the &amp;quot;odious overloads&amp;quot; examples). In other words, the &amp;quot;infoof&amp;quot; design problems reveal design problems inside the space &amp;quot;of&amp;quot; refers to.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9637105</link><pubDate>Sat, 23 May 2009 13:27:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9637105</guid><dc:creator>Tasman</dc:creator><description>&lt;P&gt;I think, it's wrong to propose reflection as an alternative to "nameof" (or whatever you call it) and the example at the end of the story to be honest &amp;nbsp;is not realistic. &lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Not realistic? Upon what data do you base that conclusion? Do you, like me, also get to see thousands of emails from C# users describing what features they'd like to see, and their real-world scenarios that drive those feature requests? Do you get input from focus groups? Do you get together with a few hundred MVPs once a year and talk to them about possible new features and how they'd use them? If you don't do these things then how do you know what is "realistic" for the industry as a whole? -- Eric&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Why do I need "nameof" operator? Mostly just for two things.&lt;/P&gt;
&lt;P&gt;First, to retrieve the name of the variables for assertions (how many ArgumentExceptions you throw in your code? how often you refactor your code?).&lt;/P&gt;
&lt;P&gt;Next, for attributes. Current framework architecture requires to write method or property name as a string when it is needed to reference it in attribute. I'd like to see more checks in this area at complie-time due to possible refactorings, typos, etc. So, as for me something like &amp;nbsp;&lt;/P&gt;
&lt;P&gt;[ItemsSource(nameof(MyClass, Items))] &lt;/P&gt;
&lt;P&gt;class MyCLass { public IList Items {get; } }&lt;/P&gt;
&lt;P&gt;would be quite ok. &lt;/P&gt;
&lt;P&gt;Will it be possible to use infoof in cases like this? Can it be used within existing framework infrastructure that requires compile time string input? &amp;nbsp;I'm a little afraid that while trying to solve all the possible issues the feature will not be usable in the end. &lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;The attribute case is one of the most common driving scenarios for this feature request. -- Eric &lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;If there was quite stupid "nameof" operator that just generated the compile time string from resolved item name or error in case of any ambiguities it would be much much more better than now when we deal with such errors in runtime.&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Indeed, it is always easier to make a weak feature that doesn't do anything difficult. The down side is that weak features still cost a lot, and you end up with a language full of weak features. -- Eric &lt;/P&gt;&lt;/DIV&gt;</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9637170</link><pubDate>Sat, 23 May 2009 14:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9637170</guid><dc:creator>Joren</dc:creator><description>&lt;p&gt;I'd far rather have more metaprogramming-like features such as expression trees than an improvement on reflection. I don't see why people would want infoof over named and optional parameters and especially co- and contravariance. I have want for those features almost in every project, while I only felt the need to use reflection once or twice.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9637720</link><pubDate>Sat, 23 May 2009 21:14:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9637720</guid><dc:creator>Tasman</dc:creator><description>&lt;p&gt;Thank you Eric for your explanations, now I can sleep well :)&lt;/p&gt;
&lt;p&gt;When I was talking about &amp;quot;not realistic&amp;quot; example I just meant that this feature is something different, e.g. there are several logging frameworks that write down caller name (via reflection, I don't think infoof will help such frameworks) and it takes a few minutes to google the solution.&lt;/p&gt;
&lt;p&gt;Of course it's definitely better to specify attributes with say MethodInfo instead of method names but I was just wondering if infoof returns MethodInfo how can it be converted to string at compile time to coexist with the way things are done now (this is actually a week feature, it's already there and we have to live with it). I believe you have the answer but from my point of view it's a real challenge to combine these two worlds and I can only hope you found a way to do it.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9637759</link><pubDate>Sat, 23 May 2009 21:42:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9637759</guid><dc:creator>Tanveer Badar</dc:creator><description>&lt;P&gt;Two observations:&lt;/P&gt;
&lt;P&gt;"It is very easy to design a feature that hits what initially looks like 80% of the cases. And then you discover that the other 80% of the cases are not covered, "&lt;/P&gt;
&lt;P&gt;How can both be 80%? Am I missing something here? It should be '80% of the cases, and then you discover that the other 20% of the cases are not covered'.&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;It's a joke. You get through what you THINK are 80% of the cases, you've spent 80% of your budget on them, and then you discover that in fact you are only half done. In that scenario&amp;nbsp;you are going to either ship a half-done feature, or you're going to spend 160% of your budget. Hence the joke. -- Eric&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;Secondly, are you sure your example&lt;/P&gt;
&lt;P&gt;class C&amp;lt;T&amp;gt; &lt;BR&gt;{&amp;nbsp;&lt;BR&gt;&amp;nbsp;public void Bar(int x, T y) {}&lt;BR&gt;&amp;nbsp;public void Bar(T x, int y) {}&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;public void Bar(int x, int y) {}&lt;BR&gt;}&lt;BR&gt;class D : C&amp;lt;int&amp;gt;&lt;BR&gt;{ …&lt;/P&gt;
&lt;P&gt;is correct given this: &lt;A href="http://blogs.msdn.com/samng/archive/2008/02/13/generic-method-substitutions-and-unification.aspx" target=_new rel=nofollow&gt;http://blogs.msdn.com/samng/archive/2008/02/13/generic-method-substitutions-and-unification.aspx&lt;/A&gt; and &lt;A href="http://blogs.msdn.com/samng/archive/2008/03/04/generic-method-substitutions-and-unification-part-two.aspx" target=_new rel=nofollow&gt;http://blogs.msdn.com/samng/archive/2008/03/04/generic-method-substitutions-and-unification-part-two.aspx&lt;/A&gt; ?&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Indeed, as Sam's blog notes, this is a case where what is allowed by the C# language and what is allowed by the CLR are different. We're still trying to figure out what the right resolution is; until we do, I strongly recommend that you avoid situations like this.&amp;nbsp;-- Eric&lt;/P&gt;&lt;/DIV&gt;</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9638037</link><pubDate>Sun, 24 May 2009 01:59:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9638037</guid><dc:creator>Jeff Brown</dc:creator><description>&lt;p&gt;@pminaev's verbose option is pretty much what I've had in mind whenever I think about this feature because there are just so many edge cases. &amp;nbsp;Even if some lightweight sugary syntax is provided for simple non-overloaded members, there needs to be an unambiguous specification available.&lt;/p&gt;
&lt;p&gt;Even so some cases like explicit interface implementations would be tortuously difficult to specify and probably shouldn't be supported at all since they just aren't useful enough. &amp;nbsp;Either that or we would need to provide syntax like: &amp;nbsp;infoof(IEnumerator List&amp;lt;T&amp;gt;.(System.IEnumerable.GetEnumerator())) with some goofy parentheses to escape the explicit member name. &amp;nbsp;But really?&lt;/p&gt;
&lt;p&gt;That makes me wonder what the visibility rules should be... &amp;nbsp; I imagine that for safety and consistency reasons we should use ordinary visibility rules governing member access in lexical scopes. &amp;nbsp;In that case, references to explicit interface implementations are right out since we can't even refer to the explicit members within their own implementation! &amp;nbsp;(good riddance)&lt;/p&gt;
&lt;p&gt;Obviously the syntax does need to support the keyword escaping mechanism: infoof(string MyType.@namespace) assuming we have a field called namespace. &amp;nbsp;This presents no new challenges to the language.&lt;/p&gt;
&lt;p&gt;Indexers are pretty easy: infoof(object MyType.Item[int]). &amp;nbsp;Of course Item doesn't appear in the C# language anywhere else so this leaks implementation details. &amp;nbsp;So we could use infoof(object MyType.this[int]) I suppose. &amp;nbsp;*cringe*&lt;/p&gt;
&lt;p&gt;Referring to get / set / add / remove / raise methods is kind of pointless but not hard. &amp;nbsp;We could adopt the usual prefix naming convention: infoof(string MyType.get_Property()). &amp;nbsp;Indexed property accessor methods follow similarly. &amp;nbsp;The prefixes leak through reflection anyways so they aren't exactly hidden implementation details.&lt;/p&gt;
&lt;p&gt;Another question is whether infoof should accept types or whether that should remain the domain of typeof. &amp;nbsp;My intuition is to that infoof should only provide references to non-type members because otherwise we have an ambiguity in the case where a type T has a property called T. &amp;nbsp;Using typeof(T) correctly resolves the type. &amp;nbsp;Using infoof(object T.T) should get the property. &amp;nbsp;If we provide a lightweight syntax for non-overloaded members, then infoof(T) should also get the property.&lt;/p&gt;
&lt;p&gt;Constructors and finalizers aren't hard: infoof(MyType(int)), infoof(~MyType()). &amp;nbsp;It should be noted that the parentheses must not be omitted from constructor signatures.&lt;/p&gt;
&lt;p&gt;As long as we use full names for everywhere then there isn't much potential ambiguity. &amp;nbsp;The problems start when we extend the syntax to allow specification of non-overloaded members with a short form name... so we might do well to just leave that option out!&lt;/p&gt;
&lt;p&gt;Has anyone attempted to work out a full detailed proposal for infoof, its variations and ramifications? &amp;nbsp;Would it be of use if someone in the community produced such a proposal?&lt;/p&gt;
&lt;p&gt;Anyways, my main use-case driving this is for use in attributes but there are also quite a few cases, particularly for testing, where static binding to a member reference is required. &amp;nbsp;Delegates and expression trees are cumbersome are of limited utility for some scenarios.&lt;/p&gt;
&lt;p&gt;I do recognized that matter how this feature is scoped 'infoof' will be a lot of work for compiler and downstream tool writers. &amp;nbsp;I know quite a few tools that will probably barf when presented with attributes that contain member tokens that are not types. &amp;nbsp;I hope that someday a reasonable variation of this idea will appear in the language since it will greatly benefit static metaprogramming.&lt;/p&gt;
&lt;p&gt;Of course, someday I'd also like to see the custom attribute blobs sprout the ability to express recursive data structures besides arrays similar to Java annotations. &amp;nbsp;:-)&lt;/p&gt;
&lt;p&gt;*wish* *wish* *wish*&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9639626</link><pubDate>Mon, 25 May 2009 03:59:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9639626</guid><dc:creator>piers7</dc:creator><description>&lt;p&gt;Fair enough, up to a point.&lt;/p&gt;
&lt;p&gt;What I've wished for many a time (and I don't think I'm alone) is a nameof operator I can use with method arguments so as to populate the ArgumentException's parameter in such a way that it is type-safe + refactor-safe. Getting full ParameterInfo metadata would be a bonus of course, but not required to be useful.&lt;/p&gt;
&lt;p&gt;I struggle to think when nameof(argument) (or infoof(argument) for that matter) could ever have an edgecase associated with it, but I agree this would be (in your terms ) a 'week' feature in that it would only work within the scope of the method that has the arguments.&lt;/p&gt;
&lt;p&gt;[in the rest of the world we call this incremental delivery: solve the easy problems first, and come back to the hard ones if you have time]&lt;/p&gt;
&lt;p&gt;Note that a more general 'nameof' operator skips your overload resolution problem, since *it doesn't do any* : you still need to pass the output from nameof to a reflection API *along with bindingflags, args etc...* to resolve to a method. It just saves you from littering your codebase with strings that you already put in the codebase once (as method/property/argument identifiers) and struggle to see why you should have to duplicate.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9640582</link><pubDate>Mon, 25 May 2009 18:52:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9640582</guid><dc:creator>Stefan Wenig</dc:creator><description>&lt;p&gt;@piers7: if it does not do any overload resolution, how can it be refactoring-safe?&lt;/p&gt;
&lt;p&gt;i.e., if there are several overloads, and one of them gets renamed, will the reference in nameof be renamed too?&lt;/p&gt;
&lt;p&gt;I thought of a similar mechanism (in presence of several overloads, just return all of them, so methodof() would always return an array). same problem though. there is just no concept of referencing a name in C#, so anything would probaby be cumbersome.&lt;/p&gt;
&lt;p&gt;as for the argument checks: 1) argument names have no runtime representation, so this would be an entirely different feature, and 2) how bad is this really? I believe a VS code snippet will solve this problem quite well. the argument name does not follow refactorings, but how often does such a mistake happen, and how often is this really a problem? (most of the times, it will still be clear which argument caused the problem, unless you actually swapped names)&lt;/p&gt;
&lt;p&gt;@Eric&lt;/p&gt;
&lt;p&gt;a few other ideas:&lt;/p&gt;
&lt;p&gt;- explicit interface implementations: just don't support them. you can use infoof to get the interface member straight from the interface and go from there.&lt;/p&gt;
&lt;p&gt;- getting getters/setters and adders/removers: just let us have the PropertyInfo/EventInfo, they have methods to get to those values&lt;/p&gt;
&lt;p&gt;- indexers and operators: pretty uninteresting. the kinds of operators are easily available, so they can be retreived using a library (MyUtil.GetIndexer (Type t)). &lt;/p&gt;
&lt;p&gt;I would not consider an implementation that does not have any of those above weak.&lt;/p&gt;
&lt;p&gt;- private members: just be consistent with typeof and disallow access&lt;/p&gt;
&lt;p&gt;overloads and generics are tricky though, granted. &lt;/p&gt;
&lt;p&gt;the problem is that if you don't give us infoof, we'll have to take care of overload resolution ourselves, on a library level. which is worse.&lt;/p&gt;
&lt;p&gt;in any case I think the expression tricks used to extract MemberInfos from lambda-expressions would be good enough. the only problem here is that we cannot use them where we'd need them most: in attributes.&lt;/p&gt;
&lt;p&gt;so I think I'll give you the point about infoof and rather than keep on discussing stuff that is already decided, ask for a different one:&lt;/p&gt;
&lt;p&gt;Remove C# attribute restrictions, including generics and argument types&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=425856"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=425856&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The funny part is that the first part of this request (generics) would actually be _really_ easy to implement, something that's not supposed to be true for any language feature. (but that's only because everything is already in place and you would just need to remove an unnecessary error check)&lt;/p&gt;
&lt;p&gt;Anyway, thanks for the great explanation. I admit that I've been in the &amp;quot;how hard can it be&amp;quot; camp, but I don't have any good answer to the generic overload question except &amp;quot;don't support&amp;quot;, but in this case I understand why you'd rather not do that. &lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9640899</link><pubDate>Tue, 26 May 2009 01:17:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9640899</guid><dc:creator>pminaev</dc:creator><description>&lt;p&gt;&amp;gt; private members: just be consistent with typeof and disallow access&lt;/p&gt;
&lt;p&gt;typeof() does not disallow access to private types, if the code that uses it has access to them.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9641240</link><pubDate>Tue, 26 May 2009 12:31:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9641240</guid><dc:creator>Stefan Wenig</dc:creator><description>&lt;p&gt;@pminaev Eric wrote &amp;quot;(2) What if overload resolution would have skipped a particular method because it is not accessible? It is legal to get method infos of methods that are not accessible; metadata is always public even if it describes private details. Should we make it impossible to get private metadata, making the feature weak, or should we make it possible, and make infoof use a subtly different overload resolution algorithm than the rest of C#?&amp;quot;&lt;/p&gt;
&lt;p&gt;I think in the context of the question the comment makes sense.&lt;/p&gt;
&lt;p&gt;BTW, making infoof able to access members that would otherwise be unaccessible would be a dangerous feature anyway. there should not be any hard-coded references to private members of other assemblies in any case, and doing it via reflection wouldn't make it any better. stuff is private for a reason. we should only access private members via reflection if they are dynamically discovered, as in a serializer.&lt;/p&gt;
&lt;p&gt;but the whole discussion is moot anyway. we're not going to get it.&lt;/p&gt;
</description></item><item><title>Fabulous Adventures In Coding</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9641454</link><pubDate>Tue, 26 May 2009 16:55:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9641454</guid><dc:creator>Patrick Steele's .NET Blog</dc:creator><description>&lt;p&gt;If you don't read Eric Lippert's Fabulous Adventures In Coding , you're really missing out on some great&lt;/p&gt;
</description></item><item><title>Fabulous Adventures In Coding</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9641463</link><pubDate>Tue, 26 May 2009 17:10:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9641463</guid><dc:creator>Patrick Steele</dc:creator><description>&lt;p&gt;If you don&amp;amp;#39;t read Eric Lippert&amp;amp;#39;s Fabulous Adventures In Coding , you&amp;amp;#39;re really missing out&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9660613</link><pubDate>Sat, 30 May 2009 02:26:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9660613</guid><dc:creator>jods</dc:creator><description>&lt;p&gt;Indeed there's a balance between usefulness and cost.&lt;/p&gt;
&lt;p&gt;Uniquely identifying a method is horribly complicated, probably requires a clumsy syntax, and surely adds a lot of complexity (= costs).&lt;/p&gt;
&lt;p&gt;At the same time I don't see many use cases for statically getting a MethodInfo. Everything I can think of is ouputting the method name in messages (e.g. logging, or assertations).&lt;/p&gt;
&lt;p&gt;For those scenarios GetCurrentMethod or a static aspect weaver like Post# can do wonders. And even if they break that's not my code logic that's breaking, just some outdated messages.&lt;/p&gt;
&lt;p&gt;I think this pretty much rules out a methodof operator, and I am fine with this.&lt;/p&gt;
&lt;p&gt;But please give the propertyof a chance. &lt;/p&gt;
&lt;p&gt;You wrote that doing only part of the feature is &amp;quot;weak&amp;quot;, but is it really? In that case typeof is &amp;quot;weak&amp;quot; but I'm sure you don't want to remove it, do you?&lt;/p&gt;
&lt;p&gt;1. propertyof is not so expensive. Properties are relatively easy to identify: propertyof(Length), or maybe propertyof(Array.Length) when outside the class. The only slightly tricky case is indexed properties, which are unsupported in C# anyway. So the worse case left is generic types... propertyof(List&amp;lt;T&amp;gt;.Count).&lt;/p&gt;
&lt;p&gt;2. Ideally the compiler could infer from usage if propertyof should return a string (the property name) or a PropertyInfo instance.&lt;/p&gt;
&lt;p&gt;3. This would be incredibly useful! Use cases are many. We currently must write property names as string at tons of places in the framework: attributes (e.g. ItemsSourceAttribute), INotifyPropertyChanged (very common those days), DependencyProperties registration, ...&lt;/p&gt;
&lt;p&gt;And you know what the problem with strings is. Say hello to runtime errors because of typos, and goodbye to safe refactoring, &amp;quot;Find all references&amp;quot;, etc.&lt;/p&gt;
&lt;p&gt;I personnally don't think your argument to justify not implementing propertyof holds... regarding infoof in its genericity, sure. But in the particular propertof case, no.&lt;/p&gt;
</description></item><item><title>В Инфуфа веруем: диалог</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9692994</link><pubDate>Wed, 03 Jun 2009 23:58:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9692994</guid><dc:creator>Блог Эрика Липперта (перевод)</dc:creator><description>&lt;p&gt;Пользователь: Оператор typeof(T) в C#, по существу, означает &amp;#171;компилятор, сгенерируй некий код, который&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9802321</link><pubDate>Thu, 25 Jun 2009 01:25:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9802321</guid><dc:creator>Douglas McClean</dc:creator><description>&lt;p&gt;I agree completely with both Eric and James Hart.&lt;/p&gt;
&lt;p&gt;How about we compromise, and get a way to generate a ldtoken instruction for the current method only? &lt;/p&gt;
&lt;p&gt;Even better would be one that returns a RuntimeMethodHandle instead of a MethodBase, since I think the usual case is to pass it to some sort of diagnostic method that may only need to use it in rare cases where something is wrong and so in the normal case it may be able to skip the cost of constructing a MethodBase from a RuntimeMethodHandle (metadata loading, etc); but I can understand why, for consistency with the existing typeof keyword, which both ldtoken's the RuntimeTypeHandle and creates a Type for it, it might be desirable just to have it always make the MethodBase.&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9827596</link><pubDate>Thu, 09 Jul 2009 23:47:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9827596</guid><dc:creator>Serge</dc:creator><description>&lt;p&gt;What you think about &amp;quot;operator .?&amp;quot; ? &lt;/p&gt;
&lt;p&gt;&amp;lt;object&amp;gt;.?&amp;lt;member&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;quot;operator .?&amp;quot; is equivalent of construction&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;NullMemberType result;&lt;/p&gt;
&lt;p&gt;if (&amp;lt;object&amp;gt; != null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;result = &amp;lt;object&amp;gt;.&amp;lt;member&amp;gt;;&lt;/p&gt;
&lt;p&gt;else&lt;/p&gt;
&lt;p&gt; &amp;nbsp;result = null;&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;where MemberType is type of &amp;lt;member&amp;gt; result&lt;/p&gt;
&lt;p&gt;where NullMemberType is &lt;/p&gt;
&lt;p&gt; &amp;nbsp;MemberType for case MemberType is class;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;MemberType for case MemberType is Nullable&amp;lt;T&amp;gt;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Nullable&amp;lt;MemberType&amp;gt; for case MemberType is struct&lt;/p&gt;
&lt;p&gt; &amp;nbsp;void for case MemberType is void&lt;/p&gt;
&lt;p&gt;i.e. for MemberType is void - this operator is equivalent of construction&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;if (&amp;lt;object&amp;gt; != null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;object&amp;gt;.&amp;lt;member&amp;gt;();&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;this operator is very needed in script and business logic, &lt;/p&gt;
&lt;p&gt;and this operator is realized Null Object Pattern (&lt;a rel="nofollow" target="_new" href="http://en.wikipedia.org/wiki/Null_Object_pattern"&gt;http://en.wikipedia.org/wiki/Null_Object_pattern&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;example of using&lt;/p&gt;
&lt;p&gt;now&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;int? age = null; &lt;/p&gt;
&lt;p&gt;var root = Root; &lt;/p&gt;
&lt;p&gt;if (root != null) &lt;/p&gt;
&lt;p&gt;{ &lt;/p&gt;
&lt;p&gt; &amp;nbsp;var config = root.Config; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;if (config != null) &lt;/p&gt;
&lt;p&gt; &amp;nbsp;{ &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;var user = config.User; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if (user != null) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; age = user.Age; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;} &lt;/p&gt;
&lt;p&gt;} &lt;/p&gt;
&lt;p&gt;if (age != null &amp;amp;&amp;amp; age.Value &amp;gt;= 21) { //bla-bla }&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;whit &amp;quot;operator .?&amp;quot;&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;if (Root.?Config.?User.?Age &amp;gt;= 21) {//bla-bla}&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;now this operator realized is very ugly as&lt;/p&gt;
&lt;p&gt;if (Root._no(_ =&amp;gt; _.Config)._no(_ =&amp;gt; _.User)._nv(_ =&amp;gt; _.Age) &amp;gt;= 21) {//bla-bla}&lt;/p&gt;
&lt;p&gt;public static class NullableExtensions&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static void _n&amp;lt;TItem&amp;gt;(this TItem item, Action&amp;lt;TItem&amp;gt; func)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if (item != null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;func(item);&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static TResult _no&amp;lt;TItem, TResult&amp;gt;(this TItem item, Func&amp;lt;TItem, TResult&amp;gt; func) where TResult : class&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if (item == null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;return null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return func(item);&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static TResult? _nv&amp;lt;TItem, TResult&amp;gt;(this TItem item, Func&amp;lt;TItem, TResult?&amp;gt; func) where TResult : struct&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if (item == null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;return null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return func(item);&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static TResult? _nv&amp;lt;TItem, TResult&amp;gt;(this TItem item, Func&amp;lt;TItem, TResult&amp;gt; func) where TResult : struct&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;if (item == null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;return null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return func(item);&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;ps&lt;/p&gt;
&lt;p&gt;what is better? &amp;quot;operator.?&amp;quot; or &amp;quot;operator?.&amp;quot;&lt;/p&gt;
</description></item><item><title>re: In Foof We Trust: A Dialogue</title><link>http://blogs.msdn.com/ericlippert/archive/2009/05/21/in-foof-we-trust-a-dialogue.aspx#9893586</link><pubDate>Thu, 10 Sep 2009 13:55:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9893586</guid><dc:creator>Niall Connaughton</dc:creator><description>&lt;p&gt;I'm confused. I was looking at some Reflector C# output for code generated by PostSharp, and it uses a &amp;quot;methodof&amp;quot; operator I'd never heard about before.&lt;/p&gt;
&lt;p&gt;Here's an example of the code it has generated:&lt;/p&gt;
&lt;p&gt;~targetMethod~1 = methodof(SomeClass.SomeMethod);&lt;/p&gt;
&lt;p&gt;Is this just fictional C# syntax that Reflector has whirled up by examining what the IL is doing? The IL is:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;L_003a: ldtoken instance class [SomeAssembly]ReturnType SomeType::SomeMethod(class [SomeAssembly]SomeArgumentType, string)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;L_003f: call class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)&lt;/p&gt;
&lt;p&gt;Anyone point me to some links to learn from? This isn't my area of expertise...&lt;/p&gt;
</description></item></channel></rss>