Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# version of VFP PEMSTATUS()
Message
De
20/01/2010 03:10:14
 
 
À
19/01/2010 20:07:11
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01444636
Message ID:
01444890
Vues:
44
>>>>>>Look at Bonnie's article in April 2007 of Universal Thread Magazine:
>>>>>>
>>>>>>http://www.levelextreme.com/ViewPageArticle.aspx?Session=352B65654B536B4830706B3D204F455A6670646F5559727967654E5A6F6B55635076513D3D
>>>>>
>>>>>Looks like Bonnie omitted a parameter:
if (PemStatus(oObject, "SetFocusAtAdd") && _
:-{

>>>>
>>>>Oops, yep, looks like it. My bad.
>>>>
>>>>The underscore in that line, which is a continuation character in VB but not valid in C#, was added to what I originally submitted (this was C# code) ... the magazine editor must have done that.
>>>>
>>>>~~Bonnie
>>>
>>>
>>>You can also use linQ to see if the property exists and to return the properties value.
>>>
>>>if( MyClass.GetType().GetProperty (propName) != null)
>>>{
>>>     object propValue = MyClass.GetType().GetProperty(propName).GetValue(MyClass, new object[]{});
>>>}
>>>
>>
>>Where does Linq come into that?
>>Oh - and before Gregory beats me to it - assigning a value to GetProperty() in the if clause would avoid having to re-evaluate if it's not null.....
>
>
>
>Its testing for the existence of the property before getting the value thereof.

My point was that it's evaluating 'MyClass.GetType().GetProperty(propName)' twice where you could use:
PropertyInfo p;
Object propValue;

if ((p = c.GetType().GetProperty(propName)) != null)
    propValue = p.GetValue(c, new object[] { });
>Just one reference: http://aabs.wordpress.com/2006/11/13/linq-reflection-in-c-30/ I just finished Charlie Calvert's book "Essential LinQ" and he covers this in detail. I just didn't choose to use from...where... select... syntax. There are many ways to skin the same horst.

Interesting link (no pun intended) - but it doesn't change the fact that your code just used Reflection :-}
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform