Re: C# Reflection--anybody use it lately?
- From: "Peter Morris" <mrpmorrisNO@xxxxxxxxxxxxx>
- Date: Wed, 16 Jul 2008 11:33:25 +0100
Example...
public class SomeClass
{
[Log]
public void DoSomething()
{
...
}
[Log]
public void DoSomethingElse()
{
...
}
public void DoSomethingElseButDontLog()
{
...
}
}
In this example when you compile your project PostSharp will use a post-compile hook in the IDE to reflect over the classes/members etc. It sees the [Log] attribute which you yourself have written and changes the code from this
{
...
}
to this
{
System.Diagnostics.Debug.WriteLine("Entering method DoSomething");
try
{
...
}
finally
{
System.Diagnostics.Debug.WriteLine("Leaving method DoSomething");
}
}
You can write what code you like in your PostSharp attribute ("Log" in this case), the attribute may then be applied to assemblies, classes, or individual members. This is one good example of how .NET attributes are used in combination with Reflection (post-compile) to alter the code you have written. This AOP approach only uses reflection during compile time and not runtime, additionally I will say that if you think AOP is only related to security then either that URL is no good or you misunderstood it.
In short, much ado about nothing. I'll cross it off my list of things
to study.
Tut tut. With this kind of attitude towards learning there's no wonder why you don't understand the benefits of such a simple thing such as Reflection.
Pete
.
- Follow-Ups:
- References:
- C# Reflection--anybody use it lately?
- From: raylopez99
- Re: C# Reflection--anybody use it lately?
- From: Peter Morris
- Re: C# Reflection--anybody use it lately?
- From: raylopez99
- C# Reflection--anybody use it lately?
- Prev by Date: Re: Reading an opened file in C#
- Next by Date: Re: C# Reflection--anybody use it lately?
- Previous by thread: Re: C# Reflection--anybody use it lately?
- Next by thread: Re: C# Reflection--anybody use it lately?
- Index(es):
Relevant Pages
|