我有程序集A
,其中MyCustomAttribute
位于。跨程序集获取自定义属性
现在我有大会B
,在那里我有reference
组装A
和我在组装B
MyCustomAttribute
使用。
现在我想获得的所有MyCustomAttribute
在inctanses B. 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