How to have a property in an ERL Serialized?

How to have a property in an ERL Serialized?

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


Geoff_Manning posted on Thursday, September 09, 2010

I've been banging my head but I can't get CSLA to move a property from the server to the silverlight client.  I realize that in most cases a property on the actual Editable Root List is unnecessary but I have a case where it is very necessary.  I notice that the ERL doesn't have access to the registerproperty methods, but surely there is SOME way to get a property from one end to the other?  Please don't tell me I have to wrap the ERL in an ER just to do this.  ANY help will be greatly appreciated :)

cds replied on Thursday, September 09, 2010

Hi Geoff

I just tried this out on a ERL of mine and it's quite simple.

You have to manage the property yourself - so just declare it as a normal .NET property (e.g. an auto-property) then override the OnGetState and OnSetState method, adding and getting the value.

For example, in my ERL I now have:

public int Value { get; set; }

protected override void OnGetState(SerializationInfo info)
{
    base.OnGetState(info);
    info.AddValue("Value", Value);
}

protected override void OnSetState(SerializationInfo info)
{
    base.OnSetState(info);
    Value = info.GetValue<int>("Value");
}

Hope that helps...

Craig

 

Geoff_Manning replied on Thursday, September 09, 2010

Thanks so much!  I knew that there was a way to manually manage properties but I couldn't remember how and couldn't find anything on it in my initial search, then I started to assume that perhaps you can't do that with an ERL.  Thanks again, you've saved me a lot of time.

Copyright (c) Marimer LLC