Discussion Around Parameterized Content
See original GitHub issueGiven the class…
public class Person
{
private IList<Person> _friends = new List<Person>();
public Person(string name)
{
Name = name;
}
public Person()
{
}
public string Name { get; set; }
public IList<Person> Friends
{
get => _friends;
set => _friends = value ?? throw new ArgumentNullException();
}
}
And invoking it as such:
var snoopy = new Person("Snoopy");
var charlieBrown = new Person("Charles \"Charlie\" Brown");
var sallyBrown = new Person("Sally Brown");
var marcie = new Person("Marcie");
snoopy.Friends.Add(charlieBrown);
snoopy.Friends.Add(sallyBrown);
snoopy.Friends.Add(marcie);
snoopy.Friends.Add(charlieBrown); // added twice -- intentional
var serializer = new ConfigurationContainer().EnableParameterizedContent().EnableReferences().Create();
var serializedPerson = serializer.Serialize(snoopy);
snoopy = serializer.Deserialize<Person>(serializedPerson);
The serialization will all work as expected, but an exception will be thrown on deserialization:
The value "ExtendedXmlSerializer.ExtensionModel.Types.ActivationContext" is not of type "ExsTests.Person" and cannot be used in this generic collection. Parameter name: value
If you comment out the last Friends.Add
then the object will be properly deserialized but snoopy
will be an empty object - no Friends, no Name. Please fix poor ol’ Snoopy!
Issue Analytics
- State:
- Created 5 years ago
- Comments:27 (11 by maintainers)
Top Results From Across the Web
php - What is parameterized query?
A parameterized query is a query in which placeholders are used for parameters and the parameter values are supplied at execution time. Why...
Read more >Performance Implications of Parameterized Queries
The Simple Parameterization Feature In cases in which values are specified explicitly, as in Listings 1 and 2, SQL Server invokes a feature ......
Read more >Solved Q1 Discuss the different ways we used parameterized
Question: Q1 Discuss the different ways we used parameterized SQL statements. Higher grades given for more detailed, specific and accurate responses, that use ......
Read more >Give me parameterized SQL, or give me death
Non-parameterized SQL is the GoTo statement of database programming. ... passing the field data content as a string into a larger string, ...
Read more >How and Why to Use Parameterized Queries
A parameterized query is a query in which placeholders are used for parameters and the parameter values are supplied at execution time.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue is resolved and can be closed, yes. Although could you explain exactly what the extension WritableParameterizedContentExtension (as per #196) does?
It seems to me like it just allows public setters on properties set by the ctor, but not sure if that’s the case?
Apologies, wasn’t aware of this, thought that while you were working towards v3, that v2 was still being actively maintained and improved (rather than just bug fixing).
Well, not quite. Redesigning my classes is not really an option (having an empty private ctor is an option but it feels like dodging the problem rather than fixing it). But I don’t see it as this project blocking me. I’ve always had alternatives but I thought that v2 was still being actively worked on and that as such I was contributing to this project by highlighting things that are important for developers like myself.
I don’t mind creating my own extensions and submitting a PR when they’re done - I’d actually prefer it since I’d end up with the knowledge about how to create my own extensions. But right now I don’t feel like I know enough about all of the different classes involved to create my own.
So long as you’re happy to potentially devoting more time to teaching me what each class does than what it would take you to implement it I have no problems with creating an extension and submitting a PR.