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

Improve decoder bunq/sdk csharp#43 #57

Merged
merged 19 commits into from
Dec 21, 2017

Conversation

OGKevin
Copy link
Contributor

@OGKevin OGKevin commented Dec 20, 2017

Closes #56
Closes #43

@OGKevin OGKevin added this to the 0.12.4 milestone Dec 20, 2017
Copy link

@epels epels left a 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,
Copy link

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(
Copy link

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());
Copy link

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

Copy link

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)
{

Copy link

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);

Copy link

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();
Copy link

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();
Copy link

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.


foreach (var type in typesToExclude)
{
if (converterRegistry.ContainsKey(type))
Copy link

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();
}
}
Copy link

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();
Copy link

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.

Copy link

@epels epels left a 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);
Copy link

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.

Copy link

@epels epels left a 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));
Copy link

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rip Correct 😁

@OGKevin
Copy link
Contributor Author

OGKevin commented Dec 21, 2017

@andrederoos All yours please 👀

Type classTypeExpected,
string referencedObjectPropertyName,
string subClassObjectPropertyName = null,
Type subClassTypeExpected = null) {
Copy link
Contributor

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.

Copy link
Contributor Author

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 )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bon!

@OGKevin
Copy link
Contributor Author

OGKevin commented Dec 21, 2017

@andrederoos all yours again

@andrederoos andrederoos merged commit 118bed4 into develop Dec 21, 2017
@andrederoos andrederoos deleted the improve_decoder_bunq/sdk_csharp#43 branch December 21, 2017 15:22
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

Successfully merging this pull request may close these issues.

3 participants