Skip to content

Conversation

@mojinxun
Copy link

when I use ToInt32OrDefault()

source is null
so I want get the defaultValue

but Convert.ToInt32 can't throw a Excetion , just default(int) = 0

@JonathanMagnan
Copy link
Member

Hello @mojinxun ,

Thank you for this pull request.

The problem is currently more our "ToInt32" is a shortcut to Convert.ToInt32 and you are currently changing the default behavior.

As I currently understand your problem perfectly, we must decide on our side how we should treat it.

We will review your pull request and try to provide a solution next week.

Best Regards,

Jonathan

@mojinxun
Copy link
Author

ok, I benefited from the project.

Hope you get better and better

@mojinxun mojinxun closed this May 15, 2017
@mojinxun mojinxun reopened this May 15, 2017
@mojinxun
Copy link
Author

what about it?

@JonathanMagnan
Copy link
Member

Sorry for the delay,

I will look at it today.

Best Regards,

Jonathan

@JonathanMagnan
Copy link
Member

JonathanMagnan commented Jun 22, 2017

Hello @mojinxun ,

I really don't know what to do currently with this request since we try to be backward compatible. So far, we don't like a lot adding some options to treat null as an empty string or creating more method overload to handle this scenario.

Perhaps you could try to use instead ToOrDefault<int>(null, 5) method which already does exactly your default behavior and use the default value when null is specified?

Best Regards,

Jonathan

@mojinxun
Copy link
Author

maybe we can do this

public static bool ToBooleanOrDefault(this object @this, bool defaultValue, bool isIgnoreNull = false)

@JonathanMagnan
Copy link
Member

It was part of solutions we don't like a lot.

If we find nothing better, we will implement this one over the weekend and make sure we have a new version ready for Monday.

Best Regards,

Jonathan

@JonathanMagnan
Copy link
Member

Hello @mojinxun ,

The v2.0.12 has been finally released.

An overload has you suggested has been added.

Let me know if we can close this pull request

Best Regards,

Jonathan

@JonathanMagnan
Copy link
Member

Closing Comment: Feel free to re-open if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants