namespace GenericsTest
{
public class AGenericClass<T>
{
public class NestedNonGenericClass
{
}
}
}
In the example above, should NestedNonGenericClass be considered a generic class?
The reflection API says it's a generic class, and even hands me the template parameters of the containing class as the...
Hello everyone,
I am generating an Assembly on the fly using Reflection.Emit and then saving it.
It contains one Type and a static Main() method in it.
.NET is kind enough to automatically reference a required assembly.
However, in Main(), there is a call to a method from another assembly and it doesn't get referenced in the standard w...
Hi,
I want to load one of four separate C# assemblies based upon what the build target is. This is going into a webservice with .net framework 3.0.
possibilities:
32-bit debug: AmtApiWrapper32d.dll
32-bit release: AmtApiWrapper32.dll
64-bit debug: AmtApiWrapper64d.dll
64-bit release: AmtApiWrapper64.dll
Those wrappers are a separa...
A method declared in one of Microsoft's Primary Interop assemblies is wrong.
It is declared as:
void Write(object[] psarray);
which is incorrect, and should actually be declared as:
void Write([In, MarshalAs(UnmanagedType.SafeArray)] object[] psarray);
I need to force the compiler to use [In, MarshalAs(UnmanagedType.SafeArray)], w...
Hi guys,
I want to get the PropertyInfo for a specific property. I could use:
foreach(PropertyInfo p in typeof(MyObject).GetProperties())
{
if ( p.Name == "MyProperty") { return p }
}
But there must be a way to do something similar to
typeof(MyProperty) as PropertyInfo
Is there? Or am I stuck doing a type-unsafe string com...
Question
I'm writing some code that needs to be able to get the values of the parameters from the method that called into the class. I know how to get all the way to the ParameterInfo[] array, but I don't know how to then get the values. Is this even possible?
If it is, I think it has something to do with using the MethodBody property ...
I've got a class that looks something like this:
public class Parent
{
public class Subclass
{
}
}
and using reflection I'm trying to find the subclass
void main
{
Parent p = new Parent();
Type t = p.GetType();
Type s = t.GetNestedType("Subclass"); //s is not set
}
This doesn't work because there apparently ...
I have classes that store data, and methods to go get data for individual loans.
I have code that walks properties and pulls the data back, but according to the MSDN coding guidelines properties are just supposed to get data, not do anything. My properties actually move to a screen on a mainframe and scrape data. So when I am mousing ov...
Assume the following type definitions:
public interface IFoo<T> : IBar<T> {}
public class Foo<T> : IFoo<T> {}
How do I find out whether the type Foo implements the generic interface IBar<T> when only the mangled type is available?
...
I am using this code where I am invoking the run method of a List of classes that I loaded dynamically from dlls:
for (int i = 0; i < robotList.Count; i++)
{
Type t = robotList[i]; //robotList is a List<Type>
object o = Activator.CreateInstance(t);
t.InvokeMember("run", BindingFlags.Default | BindingFlags.InvokeMethod, null,...
When you have a class car that implements IVehicle and you want to wrap it in a decorator that forwards all calls to car and counts them, how would you do it?
In Ruby I could just build a decorator without any methods and use method_missing to forward all calls to the car object.
In Java I could build a Proxy object that runs all code ...
public class ExampleClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
Horse hr1 = new Horse();
Horse hr2 = new Horse();
Horse hr3 = new Horse();
Horse hr4 = new Horse();
Set hrSet = new HashSet();
hrSet.add(hr1);
hrSet.add(hr2);
hrSet.add(hr3);
hrSet....
Hi,
My application is processing IList's. ILists of different user defined types. I'm thinking that i can use reflection to to see what type of object the IList contains and then create a new instance of that type and subsequently add that to the IList itself?
So at any one time I might be processing
IList<Customer> l;
and I'd like ...
A variable of the type Int32 won't be threated as Int32 if we cast it to "Object" before passing to the overloaded methods below:
public static void MethodName(int a)
{
Console.WriteLine("int");
}
public static void MethodName(object a)
{
Console.ReadLine();
}
To handle it as an Int32 even if it is cast to "Object" can be achieved ...
I'm trying to figure out a way of getting a particular piece of code called when a path is recognised. I'm going to be registering paths from different plugins. This allows them to fight over the paths that they want.
The idea being that the plugins say here are the paths that I'm interested in, when you get a match create an instance o...
Here's a simplified version of my class:
public abstract class Task
{
private static object LockObject = new object();
protected virtual void UpdateSharedData() { }
protected virtual void UpdateNonSharedData() { }
public void Method()
{
lock(LockObject)
{
UpdateSharedData();
}
...
Hi,
I do some type analysis in runtime using Reflection. If I have a MethodInfo instance,
how can I figure out if this is a "real" method or is a getter/setter method of a property? And if it is a property, how can I find the its hosting PropertyInfo back?
...
A beginner question about reflection, I suppose:
Is it possible to find all classes or interfaces in a given package? (Quickly looking at e.g. Package, it would seem like no.)
...
How would I test a property of a type to see if it is a specified type?
EDIT: My goal is to examine an assembly to see if any of the types in that assembly contain properties that are MyType (or inherited from MyType).
Here is the track I've gone down...
AssemblyName n = new AssemblyName();
n.CodeBase = "file://" + dllName;
Assembly ...
Preamble
So, this question has already been answered, but as it was my first question for this project, I'm going to continue to reference it in other questions I ask for this project.
For anyone who came from another question, here is the basic idea: Create a web app that can make it much easier to create other web applications or we...