Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The creature that won't die
Message
De
26/03/2010 09:45:18
 
 
À
26/03/2010 08:54:31
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
VFP Compiler for .NET
Divers
Thread ID:
01456123
Message ID:
01457432
Vues:
71
>>> And, oGadget isn't defined... shouldn't it be a string literal?
>>I was assuming oGadget was a property of the class containing the Doit() method - should have written 'this.oGadget' for clarity but the 'this' isn't required.
>
>Hm... interesting, and makes the code less readable. You have to know all PEMs of 'this'. Pretty much like referencing a field in the current alias, qualification is implied.

I suppose I sometimes use the 'this' (from Properties not Methods) - but in practice in C# I don't think there is anything that it could be except a parameter or a member of the class where it is being used.

>
>>>The AS operator is unintuitive but neat... implicit cast returning a null if it fails? Though, this sounds more like a try-catch "see if this works" code, instead of having an IsA(toObj, tcClass) function. What happens if you try to cast a twice subclassed timer as a timer, do you still get a reference to the original object?
>>
>>Yes - you can cast to any ancestor class....
>
>That's cool. I wish we had casting objects in VFP.
>
>>>>I'd do a bit more type checking in the first one if it was for production - but even as it stands it is safer than the VFP version...
>>>
>>>And what's unsafe in it? In the C# version ?
>>Firstly, whilst 'pi' not being null guarantees that the property exists and is public it does not guarantee that it is writeable (i.e. not readonly). Also there's no check that the type of the 'oengine' property allows 'oGadget' to be assigned to it. Something like this would be a bit safer:
if (pi != null && pi.CanWrite)
>>            {
>>                if (pi.PropertyType == oGadget.GetType())
>>                    pi.SetValue(toObj, oGadget, null);
>>            }
>
>Another thing that would be nice to have in VFP, the .canWrite - I remember writing builders and other framework code, where I'd hit some "read-only at runtime" property and then have to look for another way.

'.CanWrite' only scratches the surface of the PropertyInfo properties and methods: http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo_members.aspx
And there's also the MethodInfo for digging around in methods which reveals even more......
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform