Given:
public interface IA
{
void TestMethod();
}
public interface IB : IA
{
}
Why:
typeof(IB).GetMethods().Count() == 0;
?
Just to be clear:
public class A
{
public void TestMethod()
{
}
}
public class B : A
{
}
typeof(B).GetMethods().Count();
does work (it returns 5);
As a bonus:
typeof(IB).BaseType == nu...
Hi Guys,
I want to know how do I go about removing individual delegates from the invocation list of the parent delegate.
<DelegateName>.RemoveAll();
Now I can just remove all and that will work just to get the idea in motion and see if works which it should but then any delegates removed will need adding again at RunTime!!!
so: ...
...
I am iterating over the properties of various mapped tables in my code and need to know whether or not each property is lazy loaded. I have found that the instance variable used for storage, denoted by the Storage attribute on the property, will be of type System.Data.Linq.Link.
Is there a way that I can leverage these two facts at runt...
Similar to my previous question about determining if all classes in a given namespace are serializable, is there a way I can make assertions about all public properties on all classes in a given namespace? I'd like to determine that they are cased properly (eg. start with a capital char) and are all marked as virtual/overridable; is ther...
// Using reflection on the type DerivedClassB
// can we determine:
// a) that it uses the base class ctor that takes a string param
// b) the actual value that it passes?
public class BaseClass
{
public BaseClass()
{
}
public BaseClass(string someParameter)
{
}
}
public class DerivedClas...
I'm using reflection to retrieve an instance field such as this:
private int[] numbers = ....
With the field object, I can check if the field contains an array and if it does, I'd like to loop over the ints in the array. So if the object that contains the above field is called "foo", then I would have something like this:
field.setA...
How can i achieve this?
public class GenericClass<T>
{
public Type getMyType()
{
//How do I return the type of T?
}
}
Everything I have tried so far always returns type Object rather than the specific type used.
Thanks a lot.
...
Hi all, i need to call a void method with reflection that have 2 normal params and a third param that is a reference param. I've seen many posts about the problem and all suggest to use the GetMethod function instead of InvokeMember. I've tried the InvokeMember and it works, someone can explain me why?
Class1 myreferenceparam = new Clas...
I want to remove the security permissions from a class I don't have access to the source for. Is it possible to, via reflection, remove or modify the attribute?
[...PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust"), PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
after some consideration, it's occurred to...
what is the best Solution for mapping class object to lightweight class object by example:
Customer to CustomerDTO both have the same properties names, i was thinking of the best optimized solution for mapping between them , i know reflection slow me down badly , and making methods for every mapping is time consuming so any idea ?
than...
Hi,
To get the properties is not big deal, but I don´t want to get the properties inherited from another class. The bindingFlags option doesn´t have any option of this kind.
Is that possible ?
cheers
...
Hi,
I want to override a method in the System.Resources.ResourceManager class in mscorlib v4.
I want to override the method GetResourceFileName like this;
protected override string GetResourceFileName(CultureInfo culture) {
string resourceFileName = base.GetResourceFileName(culture);
return resourceFileName.Replace...
We have a function in a VS2005 project that loads assembles and get type information from them . It does not instantiate these types though. We tried to load some assembles that are compiled in 2010, but keep getting the following exception.
"Could not load file or assembly '2010ClassLibrary' or one of its dependencies. This assembly i...
Is it possible to determine an object type's alias(es) through reflection? Given the following example where myObject is of type System.Int32 -- e.g
Type t = myObject.GetType();
t.Name will be Int32. However, I would like to identify the possibile alias(es), if any, of the objects in question, so that I could resolve the type name of...
I am using jni4net to access Java code from within a C# application, and vice-versa. jni4net uses reflection to generate JNI code proxies, so obviously one of the limitations is that your Java and C# code have to compile in order to build proxies.
Unfortunately this can result in a catch-22 problem. Consider:
C# class X uses Java class...
I have 2 classes whose object should act as "partners". The first one is my Thing class, whose instances should act as Tree::TreeNodes of the gem RubyTree.
Basically, this delegation can be implemented using Forwardable:
class Thing < NoClassInheritancePlease
extend Forwardable
def initialize(title = "node")
@node = Tree::Tree...
I am calling a function that returns an object and in certain circumstances this object will be a List.
A GetType on this object might gives me:
{System.Collections.Generic.List`1[Class1]}
or
{System.Collections.Generic.List`1[Class2]}
etc
I don't care what this type is, all I want is a Count.
I've tried:
Object[] methodArgs=...
I can't figure out how to make this work:
object x = new Int32[7];
Type t = x.GetType();
// now forget about x, and just use t from here.
// attempt1
object y1 = Activator.CreateInstance(t); // fails with exception
// attempt2
object y2 = Array.CreateInstance(t, 7); // creates an array of type Int32[][] ! wrong
What's the secret ...
I have the following class:
public class Test {
public static int a = 0;
public int b = 1;
}
Is it possible to use reflection to get a list of the static fields only? I'm aware I can get an array of all the fields with Test.class.getDeclaredFields(). But it seems there's no way to determine if a Field instance represents a sta...
This may seem a little upside down faced, but what I want to be able to do is get an enum value from an enum by it's Description attribute.
So, if I have an enum declared as follows:
enum Testing
{
[Description("David Gouge")]
Dave = 1,
[Description("Peter Gouge")]
Pete = 2,
[Description("Marie Gouge")]
Ree = 3
...