有没有像“CurrentMethod”这样的东西?类对象的属性? [英] Is there something like a "CurrentMethod" property on a class object ?

查看:62
本文介绍了有没有像“CurrentMethod”这样的东西?类对象的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我目前是一个方法属性,用于检查有效性。这种方法违反规则。

我写了isValid方法,在otriginal方法中使用:


例如:

//以下是Csharp代码


[ruleAttribute(" rule1")]

private void functionT12()

{

if(v.IsValid()){

...

}

}


isValid应该用方法实例调用,taht就是说v必须参考functionT12对象。


所以问题是:如何在当前方法上创建对象引用?

是否有像CurrentMethod这样的东西。类对象的属性?


Oriane

Hi,

I''m currently a method attribute which is used to check the "validity" of this method against a rule.
I wrote the isValid method, to be used inside the otriginal method:

For instance:
// Following is Csharp code

[ruleAttribute ("rule1")]
private void functionT12 ()
{
if (v.IsValid ()) {
...
}
}

isValid should be called with an method instance, taht is to say that "v" must reference the "functionT12" object.

So question is: how can I create a object reference on the current method ?
Is there something like a "CurrentMethod" property on a class object ?

Oriane

推荐答案




我不确定IsValid方法的作用,因此需要什么信息

它需要的当前方法。


你可以使用系统.Diagnostics.StackFrame类和可选的

System.Diagnostics.StackTrace类。

您也可以使用System.Reflection.MethodInfo类。


你能描述一下你试图用

方法执行的有效性检查吗?

另外,考虑面向方面的编程技术,它们可能是只需

你需要什么验证。

另外,考虑自定义代码访问安全权限(第二个

以为 - 嗯,不确定您可以创建这些,请查看MSDN)。


-

此致,

Dmytro Lapshyn [Visual Developer - Visual C#MVP]

" ; Oriane" <或**** @ guermantes.com>在留言中写道

新闻:O2 ************** @ tk2msftngp13.phx.gbl ...



我目前是一个方法属性,用于检查有效性。

这个方法违反规则。

我写了isValid方法,在otriginal方法中使用:


For实例:

//以下是Csharp代码


[ruleAttribute(" rule1")]

private void functionT12()

{

if(v.IsValid()){

...

}

}


isValid应该用方法实例调用,taht就是说v

必须引用functionT12。对象。


所以问题是:如何在当前方法上创建对象引用?

是否有像CurrentMethod这样的东西。类对象的属性?


Oriane
Hi,

I am not sure what the IsValid method does and therefore what information on
the current method it needs.

You can possibly use the System.Diagnostics.StackFrame class and optionally
the System.Diagnostics.StackTrace class.
You can also probably use the System.Reflection.MethodInfo class.

Can you please describe the validity check you are trying to perform on a
method?
Also, consider Aspect-Oriented Programming techniques, they might be just
what you need for the validation.
In addition, consider custom Code Access Security permissions (on second
thought - hmm, not sure you can create those, please check with MSDN).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Oriane" <or****@guermantes.com> wrote in message
news:O2**************@tk2msftngp13.phx.gbl...
Hi,

I''m currently a method attribute which is used to check the "validity" of
this method against a rule.
I wrote the isValid method, to be used inside the otriginal method:

For instance:
// Following is Csharp code

[ruleAttribute ("rule1")]
private void functionT12 ()
{
if (v.IsValid ()) {
...
}
}

isValid should be called with an method instance, taht is to say that "v"
must reference the "functionT12" object.

So question is: how can I create a object reference on the current method ?
Is there something like a "CurrentMethod" property on a class object ?

Oriane


嗨Dmytro,

isValid是一个方法我自己使用反射和RuleAttribute自定义属性。

我不是在搜索CAS或安全检查,而只是搜索当前属性。我将尝试在System.Reflection.MethodInfo类中找到一些东西。


Oriane


" Dmytro Lapshyn [MVP]" < X - **** @ no-spam-please.hotpop.com> écritdansle message de news:在*********** ***@tk2msftngp13.phx.gbl ...
Hi Dmytro,
isValid is a method on my own using reflection and the "RuleAttribute" custom attribute.
I''m not searching for a CAS or security check, but just the "current" method.

I will try to find something in the System.Reflection.MethodInfo class.

Thanks

Oriane

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.com> a écrit dans le message de news: On**************@tk2msftngp13.phx.gbl...


我不确定IsValid方法是做什么的,因此关于它需要的当前方法。

您可以使用System.Diagnostics.StackFrame类和可选的System.Diagnostics.StackTrace类。
您也可以使用它System.Reflection.MethodInfo类。

你能描述一下你试图用
方法执行的有效性检查吗?
另外,考虑面向方面的编程技术,他们可能只是
你需要什么验证。
此外,考虑自定义代码访问安全权限(第二个想到 - 嗯,不确定你可以创建那些,请检查MSDN) 。

-
此致,Dmytro Lapshyn [Visual Developer - Visual C#MVP]


; Oriane" <或**** @ guermantes.com>在消息中写道
新闻:O2 ************** @ tk2msftngp13.phx.gbl ...
你好,

我是' m当前是用于检查有效性的方法属性。
这个方法违反规则。
我写了一个isValid方法,在otriginal方法中使用:

例如:
//以下是Csharp代码

[ruleAttribute(" rule1")]
private void functionT12()
{
if(v.IsValid()){
..
}


应该用方法实例调用isValid,taht就是说v。
必须引用functionT12。对象。

所以问题是:如何在当前方法上创建对象引用?
是否有像CurrentMethod这样的东西?类对象的属性?

Oriane
Hi,

I am not sure what the IsValid method does and therefore what information on
the current method it needs.

You can possibly use the System.Diagnostics.StackFrame class and optionally
the System.Diagnostics.StackTrace class.
You can also probably use the System.Reflection.MethodInfo class.

Can you please describe the validity check you are trying to perform on a
method?
Also, consider Aspect-Oriented Programming techniques, they might be just
what you need for the validation.
In addition, consider custom Code Access Security permissions (on second
thought - hmm, not sure you can create those, please check with MSDN).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


"Oriane" <or****@guermantes.com> wrote in message
news:O2**************@tk2msftngp13.phx.gbl...
Hi,

I''m currently a method attribute which is used to check the "validity" of
this method against a rule.
I wrote the isValid method, to be used inside the otriginal method:

For instance:
// Following is Csharp code

[ruleAttribute ("rule1")]
private void functionT12 ()
{
if (v.IsValid ()) {
...
}
}

isValid should be called with an method instance, taht is to say that "v"
must reference the "functionT12" object.

So question is: how can I create a object reference on the current method ?
Is there something like a "CurrentMethod" property on a class object ?

Oriane



在这种情况下,在IsValid方法中,您可以捕获使用

的堆栈跟踪System.Diagnostics.StackTrace类,获取即时

调用者的信息,然后使用Reflection(特别是MethodInfo类)来

发现应用于调用方法的属性。


-

此致,

Dmytro Lapshyn [ Visual Developer - Visual C#MVP]

" Oriane" <或**** @ guermantes.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP15.phx.gbl ...

嗨Dmytro ,

isValid是我自己使用反射和RuleAttribute

自定义属性的方法。

我不是在搜索CAS或安全检查,但只是当前

方法。


我将尝试在System.Reflection.MethodInfo类中查找内容。


谢谢


Oriane


" Dmytro Lapshyn [MVP]" < X - **** @ no-spam-please.hotpop.com> aécritdansle

message de news: On *** ***********@tk2msftngp13.phx.gbl ...
In this case, in the IsValid method, you can capture the stack trace with
the System.Diagnostics.StackTrace class, get the info on the immediate
caller and then utilize Reflection (in particular, the MethodInfo class) to
discover the attributes appplied to the calling method.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Oriane" <or****@guermantes.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi Dmytro,
isValid is a method on my own using reflection and the "RuleAttribute"
custom attribute.
I''m not searching for a CAS or security check, but just the "current"
method.

I will try to find something in the System.Reflection.MethodInfo class.

Thanks

Oriane

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.com> a écrit dans le
message de news: On**************@tk2msftngp13.phx.gbl...


我不确定IsValid方法是什么是什么,因此它需要什么信息
当前它需要的方法。

你可以使用System.Diagnostics.StackFrame类和
随意
System.Diagnostics.StackTrace类。
你也可以使用System.Reflection.MethodInfo类。

你能描述一下你试图在
上执行的有效性检查吗?方法?
另外,考虑面向方面的编程技术,它们可能只是验证所需的内容。
另外,考虑自定义代码访问安全权限(第二次)
想 - 嗯,不确定你可以创建那些,请查看MSDN)。

-
此致,Dmytro Lapshyn [Visual Developer - Visual C#MVP]

" Oriane" <或**** @ guermantes.com>在消息中写道
新闻:O2 ************** @ tk2msftngp13.phx.gbl ...
你好,

我是' m当前是用于检查有效性的方法属性。
这个方法违反规则。
我写了一个isValid方法,在otriginal方法中使用:

例如:
//以下是Csharp代码

[ruleAttribute(" rule1")]
private void functionT12()
{
if(v.IsValid()){
.. 。
}

应该用方法实例调用isValid,taht是说v
必须引用functionT12。对象。

所以问题是:如何在当前方法上创建对象引用

是否有像CurrentMethod这样的东西。类对象上的属性?

Oriane
Hi,

I am not sure what the IsValid method does and therefore what information
on
the current method it needs.

You can possibly use the System.Diagnostics.StackFrame class and
optionally
the System.Diagnostics.StackTrace class.
You can also probably use the System.Reflection.MethodInfo class.

Can you please describe the validity check you are trying to perform on a
method?
Also, consider Aspect-Oriented Programming techniques, they might be just
what you need for the validation.
In addition, consider custom Code Access Security permissions (on second
thought - hmm, not sure you can create those, please check with MSDN).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Oriane" <or****@guermantes.com> wrote in message
news:O2**************@tk2msftngp13.phx.gbl...
Hi,

I''m currently a method attribute which is used to check the "validity" of
this method against a rule.
I wrote the isValid method, to be used inside the otriginal method:

For instance:
// Following is Csharp code

[ruleAttribute ("rule1")]
private void functionT12 ()
{
if (v.IsValid ()) {
...
}
}

isValid should be called with an method instance, taht is to say that "v"
must reference the "functionT12" object.

So question is: how can I create a object reference on the current method
?
Is there something like a "CurrentMethod" property on a class object ?

Oriane






这篇关于有没有像“CurrentMethod”这样的东西?类对象的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆