Getting Property Info from generated methods

  • Thread starter Thread starter Hugo Ferreira
  • Start date Start date
H

Hugo Ferreira

Hi everyone,

I got a question which I hope someone will be able to help with ;)

Without entering in much details, here's a sample:

public override IMessage Invoke(IMessage msg) {
(...)

string methodName = (string) msg.Properties["__MethodName"];
memberInfo = myType.GetMember(methodName)[0];

if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) {
propertyInfo = myType.GetProperty(methodName.Substring(4));
}

(...)
}

Ok... This doesn't seem very correct to me, though it works :) Is there any
other way to get the correspondent property of a generated get/set method?

Cheers, and thanks in advance,

Hugo
 
Hugo,
Ok... This doesn't seem very correct to me, though it works :) Is there any
other way to get the correspondent property of a generated get/set method?

Iterate through all of the properties (Type.GetProperties) and check
if the get method (PropertyInfo.GetGetMethod) matches the one you have
(or similarly for the setter).



Mattias
 
Mattias,

Thanks... It is indeed, a solution to the problem that already occured me in
the past. But, what concerns me in that approach is the performance impact.
(Though it is less feasible and more exact than the one I showed :)

Thanks,

Hugo
 
Back
Top