Nullable Extension Methods an Non-Null Values #1193
Unanswered
TonyValenti
asked this question in
General
Replies: 3 comments
-
Simply write non nullable overload. If you write extension for double, you can not use int as instance argument. Even though int is implicitly assignable to double. Same story for Foo and FooBase. Same story here. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Consider the following code: public static class DateTimeExtensions {
public static bool Test(this DateTime? Value){
return true;
}
public static bool Test(this DateTime Value){
return true;
}
}
...
DateTime.Now.Test(); Today, that's valid. If your proposal gets implemented, the code does not compile anymore, since the overload resolution will result in an ambiguous match. That would be a breaking change. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Actually if my proposal were to get implemented, I would expect normal
overload resolution rules to apply and for the most specific overload to be
selected.
On Mon, Dec 18, 2017 at 5:31 AM Logerfo ***@***.***> wrote:
Consider the following code:
public static class DateTimeExtensions {
public static bool Test(this DateTime? Value){
return true;
}
public static bool Test(this DateTime Value){
return true;
}
}
...
DateTime.Now.Test();
Today, that's valid. If your proposal gets implemented, the code does not
compile anymore. It would be a breaking change.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://github.com/dotnet/csharplang/issues/1193#issuecomment-352400636>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AM-qVodSU86HtJNNvuXaBdUKhcMhybzGks5tBkz3gaJpZM4REZso>
.
--
Tony Valenti
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi C# Team,
I think that I use be able to use nullable extension methods on non-null values. for example:
Beta Was this translation helpful? Give feedback.
All reactions