I have a string like (Name := Sam&&Age=:17&& Score:=C6) and a class called Person with around 30 properties – Name, Age, Score, etc. How do I write a regex to parse the string, provided there is a variable number of properties?
Also I was thinking of doing some string replacements to convert the string to a proper JSON and then parse it. Does it sound like a good idea for production code?
I’m using C# 2010.
This regex should match your input string.
Here’s what it means:
With this, you can do a match against your string in C#:
Then loop through each property/value pair, setting the properties on your object. Setting the object properties will require some reflection and different code based on the object property types: