-
Notifications
You must be signed in to change notification settings - Fork 22
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
Improve decoder bunq/sdk csharp#43 #57
Conversation
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.
Looks good overall, just a few things that are not necessarily good or bad, as long as it's done with careful consideration
string referencedObjectPropertyName | ||
Type classTypeExpected, | ||
string referencedObjectPropertyName, | ||
string subClassObjectPropertyName = null, |
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.
Considering creating an overload for this method that omits optional params
Assert.Equal(classTypeExpected, referencedModel.GetType()); | ||
|
||
if (subClassObjectPropertyName == null || subClassTypeExpected == null) return; | ||
var subClass = referencedModel.GetType().GetProperty(subClassObjectPropertyName).GetValue( |
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.
Push invocations to newlines, e.g.
referencedModel.GetType()
.GetProperty(subClassObjectPropertyName)
.GetValue(referencedModel);
Assert.IsType(classNameExpected, referencedModel); | ||
Assert.Equal(classNameExpected, referencedModel.GetType()); | ||
Assert.IsType(classTypeExpected, referencedModel); | ||
Assert.Equal(classTypeExpected, referencedModel.GetType()); |
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.
Looks like these two assertions (L80 & L81) do the exact same thing
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.
I'd personally go with Assert.IsType()
. Just make sure it's consistent with the assertion below (L88)
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
|
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.
Remove newline
{ | ||
|
||
new JsonSerializer().Serialize(writer, 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.
Remove newline
var model = (IAnchorObjectInterface) jsonSerializer.Deserialize(token.CreateReader(), objectType); | ||
|
||
if (!model.IsAllFieldNull()) return model; | ||
var fields = objectType.GetProperties(); |
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.
Newline
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
throw new NotImplementedException(); |
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.
Is this intended? If so, maybe add a comment.
BunqSdk/Json/BunqContractResolver.cs
Outdated
|
||
foreach (var type in typesToExclude) | ||
{ | ||
if (converterRegistry.ContainsKey(type)) |
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.
No need to check if the key is present: Dictionary.Remove()
. If the key is not found, it returns false
but no exception is thrown
|
||
BunqModel GetReferencedObject(); | ||
} | ||
} |
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.
Add newline at EOF
@@ -146,5 +146,7 @@ public override string ToString() | |||
{ | |||
return BunqJsonConvert.SerializeObject(this); | |||
} | |||
|
|||
public abstract bool IsAllFieldNull(); |
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.
Is it correct BunqModel
does not implement IAnchorObjectInterface
, but still defines a IsAllFieldNull()
method? Consider extracting this method to its own interface, and implement that.
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.
Small comment.
@@ -55,7 +55,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist | |||
|
|||
public override bool CanConvert(Type objectType) | |||
{ | |||
throw new NotImplementedException(); | |||
return objectType == typeof(IAnchorObjectInterface); |
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.
You're probably looking for Type.IsAssignableFrom
here? This will return false for types implementing IAnchorObjectInterface
.
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.
LGTM
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType.IsAssignableFrom(typeof(IAnchorObjectInterface)); |
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.
Shouldn't this be inverted? E.g. return typeof(IAnchorObjectInterface).IsAssignableFrom(objectType);
checks whether objectType
implements IAnchorObjectInterface
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.
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.
rip Correct 😁
@andrederoos All yours please 👀 |
Type classTypeExpected, | ||
string referencedObjectPropertyName, | ||
string subClassObjectPropertyName = null, | ||
Type subClassTypeExpected = null) { |
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.
please lookup c# style conventions... I think ) {
needs to be on a new line.
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.
The SDK has the following structure:
private BunqResponseRaw SendRequest(HttpRequestMessage requestMessage,
IDictionary<string, string> customHeaders, string uriRelative)
{
Only {
on its own line without )
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.
bon!
@andrederoos all yours again |
Closes #56
Closes #43