创建" attributetargets.parameter"构造函数的自定义属性时,未调用。我想在测试类中使用FN函数的参数值。我使用了.NET CORE和.NET标准。
class Program
{
public static void Main()
{
var test = new Test();
test.Fn("Hello");
Console.WriteLine("end");
Console.Read();
}
}
public class Test
{
public void Fn([Parameter] string parm)
{
Console.WriteLine(parm);
}
}
[AttributeUsage(AttributeTargets.Parameter)]
public class ParameterAttribute : Attribute
{
public ParameterAttribute()
{
Console.WriteLine("In Parameter Attribute");
}
}
据我所知,属性构造仪仅在您开始检查类型而不是创建该类型的实例或执行方法时执行构造仪(在您的情况下)。
使用Custom 属性。
希望它有帮助!