Maybe my question weird… I wonderd if it possible to use reflection on a phrase.
I tried to make comparison with reflection in C#. Until now I passed the name of the property as string and the value as object, like that: Cmp("foo", "abc").
In this way I have to check if foo is existing property in the class, and check if the value type match the property type (in the example above foo is string property, and the value is string). This way works fine!
I just wonder if it possible to send phrase as parameter and analize it with reflection or something simmilar.
I mean, as in the example above instead of calling the function like that Cmp("foo", "abc") just call the function like this Cmp(A.foo == "abc") (A is class that have foo propery), then analize that the property is foo and the value is "abc".
I know its sounds weird, and its not necessary for me. Its just for the idea.
Is it possible?
EDIT
If I was not clear, I have wrote the Cmp(string, string) method, and it works fine!
I just want to know if there is way to write the Cmp method like this: Cmp(A.foo == "abc"). That the parameter is a phrase.
EDIT 2
For example you can do something like it in C. You can create macro like that:
#define Cmp(phrase) printf(##phrase)
Then if you call it like Cmp(A.foo == "abc") the output will be:
A.foo == “abc”
Like pass the whole phrase as parameter and analize it. I know that macro is pre-compile thing, I just want to know if there is something like that in C#
You can use expression trees to describe an expression like
bar.Foo == "abc". Here is a simple example that assumes the you have a class namedBarthat has a property namedFoo:Calling
will return the string