110,534
社区成员
发帖
与我相关
我的任务
分享
public void add(int i)
{
//输出i
}
public class myAttribute:Attribute
{
}
public void add([myAttribute]int i)
public class myAttribute:Attribute
{
var body=request["body"];
var obj=反序列化<user>(body);
return obj
}
public void add([myAttribute]userinfo body)
public class AAA : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
Console.WriteLine(args);
args.Arguments.SetArgument(0, "456");
args.Proceed();
}
}
我只要继承了postsharp里的东西..
我给参数加特性
public void add([AAA]int i)
{
Console.WriteLine(i);
}
就提示我
Cannot apply the custom attribute "LocalSQLManager.AAA" on the i : int32 "LocalSQLManager.Form1.add(System.Int32)":
cannot apply this custom attribute on a i : int32. Valid targets are: Parameter.
[/quote]
应该是这么用的吧
[AAA]
public void add(int i)
{
Console.WriteLine(i);
}
public class AAA : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
Console.WriteLine(args);
args.Arguments.SetArgument(0, "456");
args.Proceed();
}
}
我只要继承了postsharp里的东西..
我给参数加特性
public void add([AAA]int i)
{
Console.WriteLine(i);
}
就提示我
Cannot apply the custom attribute "LocalSQLManager.AAA" on the i : int32 "LocalSQLManager.Form1.add(System.Int32)":
cannot apply this custom attribute on a i : int32. Valid targets are: Parameter.
void md(int i)
{
cw(i);
}
add(5);
这样输出的是5
我想实现的是
void md([特性]int i)
{
cw(i);
}
当我加了特性之后.我拦截参数.
add(5);
输出50 也就是*10, 但是这个*10的操作是在哪呢?
就是在特性里拦截.
public class 特性:什么东西
{
public overrid 什么方法(参数 [] )
{
if(typeof(参数)==int)
{
base.结果=参数*10;
}
}
}
类似这种东西吧.. 虽然我不知道能否实现,只是碰到这样一个需求而已.