Comments (4)
С точки зрения кода на CIL, вызов obj.SomeExtMethod(param1)
является синтаксическим сахаром для StaticClass.SomeExtMethod(obj, param1)
. С точки зрения того, как найти подходящий помеченный метод - пока не знаю, но не думаю, что с этим будет какая-то сверхъестественная проблема.
from lens.
Для того, чтобы найти Extension-методы, можно сделать следующее:
- Взять список пространств имен, которые были указаны через
using
. - Пройтись по классам сборок и найти типы, которые входят в эти пространства имен.
- Типы, в которых есть Extension-методы, помечены
ExtensionAttribute
и имеют модификаторpublic static sealed
. - Сами Extension-методы также помечены
ExtensionAttribute
, а их релевантность можно определить по типу первого аргумента.
from lens.
var searchType = typeof(IEnumerable<>);
var searchName = "Any";
var types = typeof(System.Linq.Enumerable).Assembly.GetTypes();
var extMeths = from type in types
where type.IsSealed && !type.IsNested && !type.IsGenericType
where type.IsDefined(typeof(ExtensionAttribute), false)
from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
where method.IsDefined(typeof(ExtensionAttribute), false)
select new { Method = method, ArgType = method.GetParameters()[0].ParameterType };
var applying = from exm in extMeths
where exm.ArgType == searchType || (exm.ArgType.IsGenericType && exm.ArgType.GetGenericTypeDefinition() == searchType)
where exm.Method.Name == searchName
select exm.Method;
applying.Dump();
from lens.
Запилено в виде класса ExtensionMethodResolver
.
from lens.
Related Issues (20)
- Операции над функциями
- Мульти-объявление неинициализированных переменных HOT 1
- Ошибка в грамматике
- Интерфейс контекстно-зависимой типизации
- Ошибка при сохранении сборки - файл занят
- Проблема с тестами Translations HOT 1
- Поддержка атрибута Obsolete
- Поддержка Expression<T>
- Fix continuous integration
- Grammar file gets included after package installing HOT 2
- RegisterFunction doesn't seem to work HOT 1
- Ошибка с замыканием в цикле
- Bad IL format HOT 1
- Verbatim strings
- Наведение порядка в коде HOT 1
- LE3063: Only public, static, non-generic methods can be imported! HOT 4
- Улучшение для вывода типов
- Портирование на .NET Core HOT 4
- Properly detect System.Private library
- RegexNamedGroupsTryParseNoThrow test doesn't work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lens.