1
我创建了一个继承LocationInterceptionAspect的属性。 出于演示的目的,代码如下:PostSharp LocationInterceptionAspect不适用于继承的属性
[Serializable]
public class RepeaterAttribute : LocationInterceptionAspect
{
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
var propertyInfo = locationInfo.PropertyInfo;
if (propertyInfo == null) return false;
if (propertyInfo.PropertyType != typeof(String))
return false;
return base.CompileTimeValidate(locationInfo);
}
public override void OnSetValue(LocationInterceptionArgs args)
{
args.Value = ((String)args.Value) + ((String)args.Value);
args.ProceedSetValue();
}
}
我有一个名为外部库,并在其中一个叫父类。
namespace External
{
public class Parent
{
public String ParentProperty { get; set; }
}
}
在控制台应用程序中,我有一个名为Child的类从Parent继承。 控制台应用程序引用外部库。
public class Child : External.Parent
{
public String ChildProperty { get; set; }
}
在我的控制台应用程序中,我的代码是。
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var child = new Child();
child.ParentProperty = "A";
Console.WriteLine("This should be 'AA' : '{0}'", child.ParentProperty);
child.ChildProperty = "B";
Console.WriteLine("This should be 'BB' : '{0}'", child.ChildProperty);
Console.ReadKey();
}
}
}
,并在控制台应用程序的AssemblyInfo.cs我:
[assembly: ConsoleApplication.Repeater(AttributeTargetTypes = "ConsoleApplication.Child")]
但是当我运行的中继器的属性没有被应用到从父类继承的“ParentProperty”。