Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
The creature that won't die
Message
From
26/03/2010 09:45:18
 
 
To
26/03/2010 08:54:31
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
VFP Compiler for .NET
Miscellaneous
Thread ID:
01456123
Message ID:
01457432
Views:
70
>>> 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......
Previous
Reply
Map
View

Click here to load this message in the networking platform