24 lines
673 B
C#
24 lines
673 B
C#
using Autofac.Core;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
namespace MAX.Core.Autofac
|
|
{
|
|
/// <summary>
|
|
/// autofac 找出所有属性上是否摸个特性
|
|
/// </summary>
|
|
public class CustomPropertySelector : IPropertySelector
|
|
{
|
|
public bool InjectProperty(PropertyInfo propertyInfo, object instance)
|
|
{
|
|
if (propertyInfo.CustomAttributes.Any(iterator => iterator.AttributeType == typeof(AutowiredAttribute)))
|
|
{
|
|
|
|
}
|
|
//需要一个判断
|
|
//;如果标记的有CustomPropertyAttribute特性返回True:返回true;就构造实例
|
|
return propertyInfo.CustomAttributes.Any(iterator => iterator.AttributeType == typeof(AutowiredAttribute));
|
|
}
|
|
}
|
|
}
|