Google


ADBRITE ads links
You are here: CodeIdol.com > C# > C# Cookbook, 2nd Edition > Reflection

SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

C# Cookbook, 2nd Edition



Problem: You need to determine each assembly imported by a particular assembly. This information can show you if this assembly is using one or more of your assemblies or if your assembly is using another specific assembly. Solution: Use the As...



Problem: You need to obtain all the exported types of an assembly. This information allows you to see what types are usable from outside of this assembly. Solution: Use Assembly.GetExportedTypes to obtain the exported types of an assembly: ...



Problem: You have an inheritance hierarchy that is several levels deep and has many virtual and overridden methods. You need a list of the base class method(s) that are overridden by methods within a derived class. Solution: Use the MethodInfo...



Problem: You need to find one or more members of types in an assembly with a specific name or containing part of a name. This partial name could be, for example, any member starting with the letter A or the string "Test." Solution: Use the Typ...



Problem: You need to find one or more members with a specific name, or a part of a name, that belong to an interface. Solution: Use the same technique outlined in Recipe 13.4, but filter out all types except interfaces. The first overloaded ve...



Problem: You need to determine which types have nested types contained within them in your assembly. Determining the nested types allows you to programmatically examine various aspects of some design patterns. Various design patterns may specify tha...



Problem: You need to determine all of the base types that make up a specific type. Essentially, you need to determine the inheritance hierarchy of a type starting with the base (least derived) type and ending with the specified (most derived) type. ...



Problem: You have a type and you need to find out whether it is subclassed anywhere in an assembly. Solution: Use the Type.IsSubclassOf method to test all types within a given assembly, which determines whether each type is a subclass of the t...



Problem: You need to find all the serializable types within an assembly. Solution: Instead of testing the implemented interfaces and attributes on every type, you can query the Type.IsSerialized property to determine whether it is marked as se...



Problem: You want to get information about one or more members, but you want to retrieve only a subset of members. For example, you need to obtain only the static constructor of a type, or you need to obtain only the noninherited nonpublic fields of...



Problem: You have a list of method names that you wish to invoke dynamically within your application. As your code executes, it will pull names off this list and attempt to invoke these methods. This technique might be useful to create a test harnes...



Problem: You need to configure Dotfuscator (or another type of compatible obfuscator utility) to operate independently on a number of assemblies, but you do not want to manually have to create a configuration file for each unique assembly configurat...



Problem: You need to test a type and/or a method to determine whether it is generic. Solution: Use the IsGenericType method of the Type class and the IsGenericMethod method of the MethodInfo class: public static bool IsGenericType(Type typ...



Problem: You need to obtain information about manifest resources. Solution: Use the GetManifestResourceInfo and GetManifestResourceNames methods of the Assembly class: public static void DisplayManifestResourceInfo(string asmPath) { ...



Problem: You are building a tool that examines code and you need to get access to the local variables within a method. Solution: Use the LocalVariables property on the MethodBody class to return an IList of LocalVariableInfo objects, each of w...



Problem: You want to create a generic type using only the reflection APIs. Solution: You create a generic type similarly to how a nongeneric type is created; however, there is an extra step of creating the type arguments you want to use in cre...


SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

You are here: CodeIdol.com > C# > C# Cookbook, 2nd Edition > Reflection
   
Related tags







Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......






© CodeIdol Labs, 2007