Silverlight MethodCaller

Silverlight MethodCaller

Old forum URL: forums.lhotka.net/forums/t/6309.aspx


JimStone posted on Monday, February 02, 2009

In the CSLA Silverlight version of the MethodCaller class the definition of oneLevelFlags includes DeclaredOnly, Instance, and Public.

In CSLA .Net, oneLevelFlags also includes NonPublic.

What is there about SilverLight that precludes using NonPublic?  I would prefer to not have to declare my DataPortal_xxx methods as Public.

VS documentation for silverlight BindingFlags shows NonPublic as an option.

sergeyb replied on Monday, February 02, 2009

Reason is that you cannot invoke private methods via reflection in Silverlight.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: JimStone [mailto:cslanet@lhotka.net]
Sent: Monday, February 02, 2009 10:33 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Silverlight MethodCaller

 

In the CSLA Silverlight version of the MethodCaller class the definition of oneLevelFlags includes DeclaredOnly, Instance, and Public.

In CSLA .Net, oneLevelFlags also includes NonPublic.

What is there about SilverLight that precludes using NonPublic?  I would prefer to not have to declare my DataPortal_xxx methods as Public.

VS documentation for silverlight BindingFlags shows NonPublic as an option.



RockfordLhotka replied on Monday, February 02, 2009

Well, you CAN invoke private members, but only in the same physical class as the reflection code.

Any other class (including a base class or subclass) is prohibited from using reflection on private members of another class.

MethodCaller is designed to invoke members of other classes, and so in SL it can only interact with public members.

As an aside, this is the reason there's no BinaryFormatter or NetDataContractSerializer in SL. Both those technologies use private reflection, and so can't be implemented.

And this is why CSLA now has MobileFormatter, which is our answer to the lack of BF/NDCS, since CSLA can't function without that high-fidelity serialization model.

And the MobileFormatter is the primary reason the field manager came into being in CSLA 3.5 (because I anticipated this eventuality), so we could create a serializer that serializes private field values without the need for reflection.

I suspect this was all time well spent. Not only because it makes Silverlight rock, but also because the same basic restrictions apply to the compact framework and to Windows Azure. The field manager combined with the MobileFormatter should make it easier to tackle those platforms going forward.

Copyright (c) Marimer LLC