In .NET, if there is a class with a method Foo<T>(T t) (no constraints) and a method Foo(string s), calling Foo("test") calls the Foo that accepts a string. This is all good and well, unless the string overload is an extension method, in which case the generic version is always called. Is there some workaround for this problem, or am I out of luck?
Is there any way I can make an extension method take priority over a generic method?
360 views Asked by AlphaModder At
1
There are 1 answers
Related Questions in C#
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in GENERICS
- Go: "embedded type cannot be a type parameter"
- In Rust, how to inspect values captured by a closure?
- How to declare abstract class static fields in Python?
- Default type parameters on Rust structs: is it possible to provide a default type containing a lifetime?
- What line of code do I change to avoid duplication in a linked list?
- phpstan - return a generic
- No exact matches in reference to static method 'buildExpression'
- How to create a string literal based on generic character type in c++20?
- How to write a reusable DB transaction wrapper?
- Typescript generic initially infers then is set
- How does instanceof with generics work in Java despite type erasure?
- How to use generic classes with fields of another generic class of the same generic type?
- Getting List<T> from object[] in generic method
- How to call a method on a generic type from inside the generic class?
- Is there a way to use static member as an interface in dart?
Related Questions in OVERLOAD-RESOLUTION
- What are the implications of over.over#note-2?
- In C++ why can't I take the address of a function that also has a templated version?
- C++ How to allow copy-list-initialization for a perfect forwarding function?
- Compiler diverge on overload resolution using argument-dependent lookup and constraint expression
- Ambiguity due to implicit conversion when using a template but not with normal function
- Overload resolution and template argument deduction - why is 0 special?
- How to make operator= accept derivatives of parameter like operator+?
- How does overload resolution work with variadic template arguments and a non template argument derived type
- Priority confusion on function overloading with multiple parameters
- Function template overload with std::function type parameter, nullptr value and shared_ptr type
- How can I get the behavior of a plain `auto` return type when using "expression SFINAE"?
- Parameter pack in overload resolution
- Is a function template accepting const char(&)[N] more specialized than function template accepting const T&?
- Why does overload resolution prefer std::nullptr_t over a class when passing {}?
- c++ address of an overloaded function
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Short answer: no
In page 163 of the C# 5.0 Language Specification, we can see that after all overload resolution was attempted on a
Method Group(a set of overloaded methods), and no suitable candidates are found, the compiler will try to search for applicable extension methods. This means that all the funky stuff such as generic type inference will take precedence over extension methods. To quote: