MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

Serializable not valid for Enums? #284

Open ajj7060 opened 7 years ago

ajj7060 commented 7 years ago

We're in the process of porting our business code to be compatible with Xamarin, and I got an unexpected compilation error.

CS0592 Attribute 'Serializable' is not valid on this declaration type. It is only valid on 'class, struct' declarations.

This is the Serializable attribute from Csla's portable library (portable-net45+win8+wpa81). I'm assuming this is a bug as I don't see any reason why Enums shouldn't be able to be marked as Serializable, but wanted to check here before I created a bug issue.

rockfordlhotka commented 7 years ago

There is no Serializable attribute in Xamarin, so CSLA provides that attribute to help avoid compiler errors, even though the attribute is actually not really used by anything except MobileFormatter, and even that is a legacy formality.

MobileFormatter can't serialize an enum however (iirc anyway), so this error should be helpful in informing you that the value can't be serialized by the only serializer supported on Xamarin by CSLA: MobileFormatter.

ajj7060 commented 7 years ago

Oh, interesting. So how do you serialize enums then? Do we need to store it as an integer backing field?

rockfordlhotka commented 7 years ago

I'm quite certain we support properties that are of an enum type, but we don't require the enum type itself to be serializable, because what we transfer over the network is the int representation.

ajj7060 commented 7 years ago

Ah ok, that clears things up then. Sound perfect, thanks!

rockfordlhotka commented 7 years ago

On the other hand, since our Serializable attribute is basically just a decoration - if it is causing you issues with x-plat compilation we should probably extend it to support enums too.

Do you want to create a PR to that effect?

ajj7060 commented 7 years ago

Actually that's what I had originally thought, that it was there to help make porting the code easier with one less thing to worry about. I've never used Git before, but I'll attempt to get you a PR tonight.

ajj7060 commented 7 years ago

So I think I got it. Not as easy as branch/commit :-)

rockfordlhotka commented 7 years ago

If you use the 'GitHub for Windows' app it helps.

  1. Fork
  2. Branch
  3. Commit
  4. PR