Locations of visitors to this page
    Sprouting Synapses       Minimize  

             
            Minimize  
Author: SkySigal Created: 7/11/2008 1:37 PM
.NET tips and tricks to do with Reflection in C#.

By SkySigal on 9/6/2008 3:13 AM

image Damn!

 

 

 

AssemblyName x = thisAssembly.GetName();

triggers:

Request for the permission of type 
'System.Security.Permissions.FileIOPermission, ...etc'
 failed.

This is going to be fun, trying to get the assembly version without that error (eg: on Silverlight)...

Any ideas?

powered by metaPost

By SkySigal on 8/30/2008 4:05 PM

blog_csharp_reflection Somewhere on the net yesterday I read a comment stating that Reflection was not allowed in an Internet zone.
Say what?!?! I use Reflection a lot...

Turns out that whomever made that comment...was...misleading. MSDN's Documentation for ReflectionPermission states:

Controls Reflection of non-public types/members. Controls some features of Emit APIs.

By SkySigal on 8/29/2008 6:04 PM

blog_csharp_reflection When invoking a method that has no out params, its relatively easy -- but when it has out or ref methods its very very easy to miss the MakeByRefType method!

Let's first discuss getting a MethodInfo for the easier case (DateTime.Parse), and then the more complex (DateTime.TryParse), next.

These are the parameters we'll use:

By SkySigal on 8/10/2008 4:52 AM

blog_csharp Getting Private Fields by Reflection is...almost easy... but it doesn't always work... Here's why.

Read More »

By SkySigal on 8/10/2008 4:18 AM

blog_csharp Reflection is just one of those things that are wonderful about C#... but you do wish it were faster.

That said, here's how to get and set properties via Reflection...

Read More »

By SkySigal on 7/11/2008 1:45 PM

We’re used to requesting the name of the current method by doing something like this:

Type thisClassInstanceType = this.GetType();

Where this doesn’t work, is within a static method, where there is no ‘this’ instance.

In such cases, do the following:

Type thisStaticMethodClassType = 
  System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;

 

If you are interested in the method itself, rather than the class that wraps it, its even easier:

string thisMethodName = 
  System.Reflection.MethodBase.GetCurrentMethod().Name;

 

Further reading:
powered by metaPost


             
Copyright 2007 by Sky Sigal