Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent story around immutability/mutability #11

Open
andysturrock opened this issue Jan 1, 2016 · 3 comments
Open

Consistent story around immutability/mutability #11

andysturrock opened this issue Jan 1, 2016 · 3 comments

Comments

@andysturrock
Copy link
Contributor

The following code throws a System.Security.VerificationException : Operation could destabilize the runtime.:

public class WithList
{
    public WithList(List<int> list)
    {
        ListOfInt = list;
    }
    public List<int> ListOfInt { get; }
}

void BlowUp()
{
    List<int> list = new List<int>();
    var msg = new WithList(list);
    new Serialiser<WithList>().Serialise(msg);
}

I'll take a look but you might get there quicker :-)

@drewnoakes
Copy link
Member

drewnoakes commented Jan 1, 2016

List should not be supported as it's mutable. Use IReadOnlyList instead.
However there is a bug here: it should throw on creating the serialiser.

@andysturrock
Copy link
Contributor Author

I just forked the repo to look at this. It is now more graceful as it throws System.Exception : Unable to serialise type System.Collections.Generic.List1[System.Int32]`. Your NuGet release is behind the latest code in GibHub I guess.

I agree with the point about mutability but that's not checked everywhere. Eg this still works:

        public sealed class UserScore
        {
            public UserScore(string name, int score)
            {
                Name = name;
                Score = score;
            }

            public string Name { get; set; }
            public int Score { get; set; }
        }

So it's a bit inconsistent isn't it?

@drewnoakes
Copy link
Member

Yes that is inconsistent. Will have a think. I like immutability and it's important to make it possible, but maybe Dasher shouldn't force it on users. Will have a think.

Just pushed 0.3.0 to NuGet.

@drewnoakes drewnoakes changed the title List not handled gracefully Consistent story around immutability/mutability Jan 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants