-
Notifications
You must be signed in to change notification settings - Fork 323
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
Supporting Multiple TestProperty with the same key value. #328
Conversation
navin22
commented
Jan 9, 2017
- Changed the way of deserialization using custom TraitObject.
- Added UnitTests for the same.
- Changed the way of deserialization using custom TraitObject. - Added UnitTests for the same.
// Converting Json data to array of KeyValuePairs with duplicate keys. | ||
var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(List<TraitObject>)); | ||
|
||
var listOfTratiObjects = serializer.ReadObject(stream) as List<TraitObject>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/listOfTratiObjects/listOfTraitObjects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved it.
var listOfTratiObjects = serializer.ReadObject(stream) as List<TraitObject>; | ||
listOfTratiObjects.ForEach(o=>listOfKvps.Add(new KeyValuePair<string, string>(o.Key, o.Value))); | ||
|
||
return listOfKvps?.ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is null check required for listOfKvps
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(List<TraitObject>)); | ||
|
||
var listOfTratiObjects = serializer.ReadObject(stream) as List<TraitObject>; | ||
listOfTratiObjects.ForEach(o=>listOfKvps.Add(new KeyValuePair<string, string>(o.Key, o.Value))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra allocation and insertion into listOfKvps
may not be required. Is something like below possible?
listOfTratiObjects.Select(t => new KeyValuePair<string, string>(t.Key, t.Value)).ToArray()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes possible. Changed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach looks fine. Request few changes.
#239 issue is resolved by this PR. |