У меня есть A
, где находится MyCustomAttribute
.Получить пользовательские атрибуты по сборкам
Теперь я Ассамблея B
, где я reference
к сборке A
и я использую в сборке B
MyCustomAttribute
.
Теперь я хочу, чтобы получить все inctanses из MyCustomAttribute
в Assebmly В.
Я пытаюсь что-то вроде:
public static void Registration()
{
List<MyCustomAttribute> atrr = new List<MyCustomAttribute>();
var assembly = System.Reflection.Assembly.GetCallingAssembly();
var types = (from type in assembly.GetTypes()
where Attribute.IsDefined(type, typeof(MyCustomAttribute))
select type).ToList();
}
и другими способами - но я не могу получить MyCustomAttribute
.
UPDATE
Мой атрибут
namespace NamespaceOne.Attributes
{
[AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = false,
Inherited = false)]
public class MyCustomAttribute: Attribute
{
......
}
}
Now the second Assembly(second project - ASP WebApi):
namespace SecondNamespace.Controllers
{
public class HomeController : Controller
{
[MyCustomAttribute]
public ActionResult Index()
{
MyStaticMethod.Registration(); // THIS Class andmethod in First class library - where located attribute
ViewBag.Title = "Home Page";
return View();
}
ли вы подтвердить, что 'GetCallingAssembly()' 'фактически возвращает b'? –
Да. Но внутри я не вижу свой собственный атрибут –
Не могли бы вы показать свой атрибут, а также тип, который его реализует? – Bauss