I have the following structure
public class MyClass : MyBaseClass<System.Int32>
{
}
In a static method and without instantiating a new MyClass instance how do I get the type of the generic parameter used to build the concrete base class? e.g in the above example System.Int32
...
I have a generic class in my project with derived classes.
public class GenericClass <T> : GenericInterface<T>
{
......
}
public class Test : GenericClass <SomeType>
{
}
Is there any way to find out if a Type object is derived from the GenericClass ?
t.IsSubclassOf(typeof(GenericClass<>))
is not working.
...
Ok, so I'm trying to make a nice superclass for data-access objects that can generate a tsql query to search all of the subclass's public string properties. I want to use reflection to get the type of the subclass and then iterate through all of the public string properties on the object, since those property names are the same as the d...
We have an application which we are developing in C#. We store all resources in a central resource DLL, the resource contains images, icons and strings from which we support multiple cultures.
We access the resources from any project in the solution using the following code;
private ResourceManager ResMan;
ResMan = new ResourceManager(...
I've got a polymorphic array of objects which implement two (informal) interfaces. I want to be able to differentiate them with reflection along the lines of:
if (hasattr(obj, 'some_method')) {
# `some_method` is only implemented by one interface.
# Now I can use the appropriate dispatch semantics.
} else {
# This must be th...
GetType() returns null when the type exists in an unreferenced assembly. For example, when the following is called "localType" is always null (even when using the full namespace name of the class):
Type localType = Type.GetType("NamespaceX.ProjectX.ClassX");
I don't see any reason why Type.GetType shouldn't be able to retrieve a type...
I'm not quite sure how to explain this (that's why the title is kinda weird) but I'll have a go. Basically I'm doing some Oject-Oriented Design and I want to represent various different types of object, each of which can have various actions which it can perform. An example might help: things such as a File which can have delete, rename ...
I have this method Verify_X which is called during databind for a listbox selected value. The problem is the strongly typed datasource. I want to use the abstract class BaseDataSource or an interface to call the methods supported:
Parameters[] and Select(), Instead of using the most specific implementation as seen below.
This is so on...
I'm having some problems with the following code:
private class ClientPluginLoader : MarshalByRefObject
{
public bool IsPluginAssembly(string filename)
{
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomainReflectionOnlyAssemblyResolve);
Assembly asm = Assembly.Reflectio...
I have a class (Descendant1) that inherits from a base class (BaseClass). An instance of a descendant class is passed into a method that takes BaseClass as a parameter. Then using reflection, it calls a property on the object.
public class BaseClass { }
public class Descendant1 : BaseClass
{
public string Test1 { get { return "te...
I posted a similar question a time ago. I need to load an assembly at runtime.
This is easy if I know the absolute path of the dll at runtime.
But I dont :( The assembly.Load() or LoadFromFile() fails if the file is not in the application root.
The only thing I have is the dll name. The dll could be located in the root, system32 or in...
I've written a class with a single static method that copies property values from one object to another. It doesn't care what type each object is, only that they have identical properties. It does what I need, so I'm not engineering it further, but what improvements would you make?
Here's the code:
public class ShallowCopy
{
publ...
Is there a way in Java to programmatically import a class given its full name as a String (i.e. like "com.mydummypackage.MyClass")?
...
Edit: Based on the answer from LoveMeSomeCode, I believe this issue only appears in VB.Net.
I'm trying to revert a class to a previous state by saving the old values of changed properties in a dictionary and setting them via reflection when I need to revert. I'm having a problem where if the old value is Nothing (null) I get a null refe...
In Java, is there any way to use the JDK libraries to discover the private classes implemented within another class? Or do I need so use something like asm?
...
Question
I am trying to dynamically get the default for a type that is specified in a ParameterInfo. _methods[methodName] returns a MethodInfo object.
Unfortunately, the compiler doesn't like the "paramType" bit inside the default(paramType). I'm stumped.
Error
The type or namespace name 'paramType' could not be found (are you mis...
I have created a function that takes a SQL command and produces output that can then be used to fill a List of class instances. The code works great. I've included a slightly simplified version without exception handling here just for reference - skip this code if you want to jump right the problem. If you have suggestions here, though...
I've got a custom object (example only code for ease of understanding) ...
public class MyClass
{
private string name;
private int increment;
private Guid id;
public string Name
{
get { return name; }
set { name = value; }
}
public int Increment
{
get { return increment; }
...
The title pretty much says it all. When I'm doing some reflection through my classes, will the MemberInfo.GetCustomAttributes() method preserve the order of attributes on a member, or not? The official documentation does not say anything one way or the other.
In case you're wondering why I would need this, here's the full explanation....
Edit--@Uri correctly pointed out that this was an abuse of annotations; trying to actually create the menu data itself in annotations is just silly.
They are good for binding however, I think I'll stick with using them to link the text data to the methods (the @Menu ("File") portion) since it's more explicit and flexible than reflecting...