P
proxyuser
I was hoping there was something like that built in, but maybe not. I'll
give that a try, thanks.
It is built in. Extensions are a new feature in .NET 3.5.
I was referring to the "ToString" imlemementation, not extensions.
I was hoping there was something like that built in, but maybe not. I'll
give that a try, thanks.
It is built in. Extensions are a new feature in .NET 3.5.
Peter Duniho said:I admit, it's not really clear to me what behavior you're really trying to
accomplish here. Assuming that "option 1" would actually satisfy the
requirement, how is having to hard-code the method name in a call to
Type.GetMethod() any different than simply hard-coding the method name in
some output method? Why is "option 1" even an option at all?
That is, I understand that being able to do so would ensure refactoring
the code results in the string effectively being refactored as well, but
what is the real goal here? What ultimate benefit do you achieve by being
able to convert the name of a method you're about to call into a string?
And why can that benefit not be achieved by moving the logic emitting
and/or using that string into the method being called, rather than at each
call site?
What are you really trying to do here?
Peter Duniho said:I admit, it's not really clear to me what behavior you're really trying to
accomplish here. Assuming that "option 1" would actually satisfy the
requirement, how is having to hard-code the method name in a call to
Type.GetMethod() any different than simply hard-coding the method name in
some output method? Why is "option 1" even an option at all?
That is, I understand that being able to do so would ensure refactoring
the code results in the string effectively being refactored as well, but
what is the real goal here? What ultimate benefit do you achieve by being
able to convert the name of a method you're about to call into a string?
And why can that benefit not be achieved by moving the logic emitting
and/or using that string into the method being called, rather than at each
call site?
What are you really trying to do here?
This is not going to work because to get the name of the method you
must first know the name of the method.
I have to ask is this information is of any real value to the user?
This is not going to work because to get the name of the method you
must first know the name of the method.
I have to ask is this information is of any real value to the user?
Registered User said:This is not going to work because to get the name of the method you
must first know the name of the method.
Registered User said:This is not going to work because to get the name of the method you
must first know the name of the method.
All due respect, but it would be unwise for any of us to take anything for
granted. The mere fact that you _want_ to do something does not in and of
itself prove that it's of value.
Isn't incorrect output at run-time a failure? If someone's looking at the
output and sees the name of a method that doesn't exist, that seems like
that would be an indication that something's wrong.
The above breaks if someone fails to set the Name property correctly
People waste time on things that turn out to be useless, or at the very
least the wrong approach, all the time. I see no reason to believe that
you are somehow magically immune to that particular aspect of the human
condition.
As I said before, until you can precisely describe what your actual
ultimate goal is, it's impossible to offer any really good advice.
All due respect, but it would be unwise for any of us to take anything for
granted. The mere fact that you _want_ to do something does not in and of
itself prove that it's of value.
Isn't incorrect output at run-time a failure? If someone's looking at the
output and sees the name of a method that doesn't exist, that seems like
that would be an indication that something's wrong.
The above breaks if someone fails to set the Name property correctly
People waste time on things that turn out to be useless, or at the very
least the wrong approach, all the time. I see no reason to believe that
you are somehow magically immune to that particular aspect of the human
condition.
As I said before, until you can precisely describe what your actual
ultimate goal is, it's impossible to offer any really good advice.
A quick review revealed no reference in the thread to Windows controlThat's not necessarily true with regard to all objects (see my recent post
in this thread related to Windows control names.) Hence, I want to know if
there is a way to get it to work here.
Ah yes the old because I said so requirement. I'll let you do whateverYou can safely assume that if I want to do it, it's of value - otherwise I
wouldn't have wasted my time on it.
A quick review revealed no reference in the thread to Windows controlThat's not necessarily true with regard to all objects (see my recent post
in this thread related to Windows control names.) Hence, I want to know if
there is a way to get it to work here.
Ah yes the old because I said so requirement. I'll let you do whateverYou can safely assume that if I want to do it, it's of value - otherwise I
wouldn't have wasted my time on it.
Registered User said:A quick review revealed no reference in the thread to Windows control
names. It could be this client didn't retrieve that particular post.
In any case I don't see the connection between a Window control's Name
property and the topic addressed by this thread.
Ah yes the old because I said so requirement. I'll let you do whatever
you wish with your time. Selah
Registered User said:A quick review revealed no reference in the thread to Windows control
names. It could be this client didn't retrieve that particular post.
In any case I don't see the connection between a Window control's Name
property and the topic addressed by this thread.
Ah yes the old because I said so requirement. I'll let you do whatever
you wish with your time. Selah
I fail to see how an object's Name property can be used to identifySee the Name property of a Windows control and you'll see what I mean. This
is the variable name that the developer assigns to the instance of the
control.
Being able to understand the why plays a big part in determiningSorry, I just get tired of the "I don't understand the need for it therefore
you don't need to do it" type of responses.
I fail to see how an object's Name property can be used to identifySee the Name property of a Windows control and you'll see what I mean. This
is the variable name that the developer assigns to the instance of the
control.
Being able to understand the why plays a big part in determiningSorry, I just get tired of the "I don't understand the need for it therefore
you don't need to do it" type of responses.
proxyuser said:See the Name property of a Windows control and you'll see what I mean. This
is the variable name that the developer assigns to the instance of the
control.
Sorry, I just get tired of the "I don't understand the need for it therefore
you don't need to do it" type of responses.
proxyuser said:See the Name property of a Windows control and you'll see what I mean. This
is the variable name that the developer assigns to the instance of the
control.
Sorry, I just get tired of the "I don't understand the need for it therefore
you don't need to do it" type of responses.
Registered User said:Don't take this personally but the "I thought of it" doesn't provide
the 'it' with any real value.
J.B. Moreno said:Such responses indicate one of three things:
1) You have either failed to adequately explain what the real
problem you are trying to solve is (and not just the method you've
chosen to solve the problem).
2) You don't need to do that.
3) Your reader is unable to understand how to apply what you want to
do to solve your problem (this is just a variation on 1 but putting the
onus on the reader).
Now, on to your actual question. I haven't done it in practice, but I
believe that theoretically this is at least a *partly solvable problem.
1. Do not call the method directly, instead create a delegate and
call it using the delegate.
2. Use instance.GetType.GetMethods() to create a collection of
MethodInfo's
3. Use Delegate.CreateDelegate to create a delegate for each of the
methodsinfo's created inst step 2.
4. Use Delegate.Equals to compare the delegate created in step 1, to
the ones created in step 3. Then use the associated MethodInfo.Name.
5. Bob's your uncle.
*I said partly solvable because I for see problems with methods that
have more than one parameter.
I really don't see why it matters. Just assume the real problem I'm trying
to solve is getting a method name from a method programmatically and go from
there. I know people are trying to help when they ask "why do you need
that", but as you can imagine it can get rather tedious over the years on
forums where you have to waste time arguing about something that just gets
in the way. You and I both know there are people who would rather spend
energy telling someone what they should or shouldn't do rather than spending
the energy on an answer, or even just not cluttering up the thread to begin
with.
Off the top of my head I don't see what the problems would be with more than
one parameter - it seems like that would work. That's an idea that
definitely did not occur to me - see, that's why these newsgroups are so
good
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.