Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a C# equivalent of typeof for properties/methods/members?

A classes Type metadata can be obtained in several ways. Two of them are:

var typeInfo = Type.GetType("MyClass")

and

var typeInfo = typeof(MyClass)

The advantage of the second way is that typos will be caught by the compiler, and the IDE can understand what I'm talking about (allowing features like refactoring to work without silently breaking the code)

Does there exist an equivalent way of strongly referencing members/properties/methods for metadata and reflection? Can I replace:

var propertyInfo = typeof(MyClass).GetProperty("MyProperty")

with something like:

var propertyInfo = property(MyClass.MyProperty)

like image 874
David Avatar asked Mar 19 '10 15:03

David


People also ask

Why is there a slash in AC?

Senior Member. You read it as "ei-cee" (no "slash" pronounced). In terms of distinguishing between "air conditioning" and "air conditioner," I can think of an example like "Today, I bought a new air conditioner" ("conditioning" not allowed). I personally would not say "Today, I bought a new AC."

Why is it called AC?

Air conditioning, often abbreviated as A/C or AC, is the process of removing heat from an enclosed space to achieve a more comfortable interior environment (sometimes referred to as 'comfort cooling') and in some cases also strictly controlling the humidity of internal air.

What is the mean of AC?

a/ c is an abbreviation for air-conditioning. Keep your windows up and the a/c on high. 60 Motel Units. All Units A/C, Heat, Cable TV.

Is AC the same as AC?

The term “A/C” stands for “air conditioning,” but it's frequently used to describe any type of home cooling equipment, such as a traditional split-system air conditioner or heat pump, mini-split unit, geothermal system, or even a window unit.


1 Answers

No, unfortunately not. It's been discussed and even named: infoof (pronounced "in-foof" for comedy value) but it's not been implemented... yet. Eric Lippert has a blog post about it.

The closest you can come in C# 3 is to make the compiler generate an expression tree, and then pull it out of that - but that's hardly pleasant.

like image 130
Jon Skeet Avatar answered Oct 06 '22 00:10

Jon Skeet