473,836 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there something like a "CurrentMet hod" property on a class object ?

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 "functionT1 2" object.

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

Oriane
Nov 17 '05 #1
9 1424
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.Diagnost ics.StackFrame class and optionally
the System.Diagnost ics.StackTrace class.
You can also probably use the System.Reflecti on.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****@guerman tes.com> wrote in message
news:O2******** ******@tk2msftn gp13.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 "functionT1 2" object.

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

Oriane
Nov 17 '05 #2
Hi Dmytro,
isValid is a method on my own using reflection and the "RuleAttrib ute" 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.Reflecti on.MethodInfo class.

Thanks

Oriane

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> a écrit dans le message de news: On************* *@tk2msftngp13. phx.gbl...
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.Diagnost ics.StackFrame class and optionally
the System.Diagnost ics.StackTrace class.
You can also probably use the System.Reflecti on.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****@guerman tes.com> wrote in message
news:O2******** ******@tk2msftn gp13.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 "functionT1 2" object.

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

Oriane

Nov 17 '05 #3
In this case, in the IsValid method, you can capture the stack trace with
the System.Diagnost ics.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****@guerman tes.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi Dmytro,
isValid is a method on my own using reflection and the "RuleAttrib ute"
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.Reflecti on.MethodInfo class.

Thanks

Oriane

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> a écrit dans le
message de news: On************* *@tk2msftngp13. phx.gbl...
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.Diagnost ics.StackFrame class and
optionally
the System.Diagnost ics.StackTrace class.
You can also probably use the System.Reflecti on.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****@guerman tes.com> wrote in message
news:O2******** ******@tk2msftn gp13.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 "functionT1 2" object.

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

Oriane


Nov 17 '05 #4
using System.Reflecti on;
....
MethodBase methodBase = MethodBase.GetC urrentMethod();

Gabriel Lozano-Morán
Nov 17 '05 #5
Thank you Dmytro,

now you can perhaps ask another question: is there a way to avoid the calling of the "isValid" in the method?
I mean, to "trigger" the call to "isValid" automatically when entering in the method code ?

I think this is not possible, but it could have made my code prettier !!

What I would try to do is to emulate the [PrincipalPermis sionAttribute ] behaviour...

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> a écrit dans le message de news: O$************* @TK2MSFTNGP12.p hx.gbl...
In this case, in the IsValid method, you can capture the stack trace with
the System.Diagnost ics.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****@guerman tes.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi Dmytro,


isValid is a method on my own using reflection and the "RuleAttrib ute"
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.Reflecti on.MethodInfo class.

Thanks

Oriane

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> a écrit dans le
message de news: On************* *@tk2msftngp13. phx.gbl...
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.Diagnost ics.StackFrame class and
optionally
the System.Diagnost ics.StackTrace class.
You can also probably use the System.Reflecti on.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****@guerman tes.com> wrote in message
news:O2******** ******@tk2msftn gp13.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 "functionT1 2" object.

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

Oriane


Nov 17 '05 #6
OK.

Thanks a lot
"LOZANO-MORÁN, Gabriel" <ga************ @no-spam.com> a écrit dans le message de news: ej************* *@TK2MSFTNGP12. phx.gbl...
using System.Reflecti on;
...
MethodBase methodBase = MethodBase.GetC urrentMethod();

Gabriel Lozano-Morán

Nov 17 '05 #7
Oriane wrote:
Thank you Dmytro,

now you can perhaps ask another question: is there a way to avoid the
calling of the "isValid" in the method?
I mean, to "trigger" the call to "isValid" automatically when
entering in the method code ?

I think this is not possible, but it could have made my code prettier
!!

What I would try to do is to emulate the
[PrincipalPermis sionAttribute ] behaviour...


Yes, and it would eliminate the need to do the "try to find the current
method" dance you were asking about.

Look at this article:

http://msdn.microsoft.com/msdnmag/is...contextsinnet/

It's tricky to do this, but I have done it for reasons similar to yours.

There's a few other articles, besided that one, that talk about this topic
on the Net. You might want to look for them too.

--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]
Nov 17 '05 #8
Still, read Reginald's post carefully. I believe what this poster suggests
is just another name for Aspect-Oriented Programming I suggested earlier in
this thread. And this would be the best way to implement your validity
check.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Oriane" <or****@guerman tes.com> wrote in message
news:OK******** ******@TK2MSFTN GP09.phx.gbl...
OK.

Thanks a lot
"LOZANO-MORÁN, Gabriel" <ga************ @no-spam.com> a écrit dans le message
de news: ej************* *@TK2MSFTNGP12. phx.gbl...
using System.Reflecti on;
...
MethodBase methodBase = MethodBase.GetC urrentMethod();

Gabriel Lozano-Morán


Nov 17 '05 #9
"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Still, read Reginald's post carefully. I believe what this poster suggests
is just another name for Aspect-Oriented Programming I suggested earlier in this thread. And this would be the best way to implement your validity
check.


Ok. I will follow your advice.

Sincerely
Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2022
by: Oriane | last post by:
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 private void functionT12 ()
0
9672
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10854
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10601
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9388
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5652
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.