Given the following code:
var n1 = new AssemblyName ("TestDll, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089");
var n2 = new AssemblyName ("TestDll, Version=2.0.0.2001, Culture=en-US, PublicKeyToken=ab7a5c561934e089");
Console.WriteLine (AssemblyName.ReferenceMatchesDefinition (n1, n2));
Console.WriteLine (A...
Hi, how do I find out the return type of a method from the MethodBase? I'm using PostSharp and trying to override the CompileTimeValidate(MethodBase method) method to make sure the attribute is applied to a method with the correct signature.
Thanks,
...
Hello,
I need to use reflection to get the binding value in a control that is a DataGridTemplateColumn (e.g HyperLinkButton). Does anyone know how I might do this? It seems simple enough to do this with a TextBlock because it has a “TextProperty” dependency property, but I can’t seem to get a binding expression from a control that does ...
.NET I want to clone a value type's fields. How can i set a field value on a value type using reflection (or something else dynamically)?
This works for reference types but not for value types. I understand why but I don't know an alternative.
shared function clone(of t)(original as t) as t
dim cloned as t
'if class then execute p...
Is there any way to change the name of a dynamic assembly after it has been created? I'm using a framework that uses dynamic methods, and it is creating a dynamic assembly with the same name as my main assembly (which causes problems with WPF when it tries to load resources). So I need to find a workaround, and I thought of trying to cha...
Is there a way to find the QMetaObject instance of a class, given the class name? what I like to do is to load objects from disk, but for this to happen, I need a way to retrieve a QMetaObject instance using the name of a class, in order to use the QMetaObject to create an instance.
...
I have two classes Address and Employee as follows:
public class Address
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
public class Employee
{
public string First...
How can you identify anonymous methods via reflection?
...
Using C# 3.5 I am trying to generate dynamic types at runtime using reflection emit. I used the Dynamic Query Library sample from Microsoft to create a class generator. Everything works, my problem is that 100 generated types inflate the memory usage by approximately 25MB. This is a completely unacceptable memory profile as eventually I ...
I have a method which compares two objects and returns a list of all the property names which are different.
public static IList<string> GetDifferingProperties(object source, object target)
{
var sourceType = source.GetType();
var sourceProperties = sourceType.GetProperties();
var targetType = target.GetType();
var targe...
package reflection;
import java.io.*;
import java.lang.reflect.*;
class class0
{
public void writeout0()
{
System.out.println("class0");
}
}
class class1
{
public void writeout1()
{
System.out.println("class1");
}
}
class class2
{
public void writeout2()
{
System.out.println("class2");
}
}
class clas...
I have an attribute declared on property. How can I get the property name inside the attribute?
...
Updated question given Andrew Hare's correct answer:
Given the following C# classes:
public class Bar : Foo, IDisposable
{
// implementation of Bar and IDisposable
}
public class Foo : IEnumerable<int>
{
// implementation of Foo and all its inherited interfaces
}
I want a method like the following that doesn't fail on the as...
I've got a custom attribute that I want to apply to my base abstract class so that I can skip elements that don't need to be viewed by the user when displaying the item in HTML. It seems that the properties overriding the base class are not inheriting the attributes.
Does overriding base properties (abstract or virtual) blow away att...
I have a class Similar to this
public class Model
{
public TimeSpan Time1 {get; set;}
public TimeSpan Time2 { get; set; }
public TimeSpan Time3 { get; set; }
public TimeSpan Time4 { get; set; }
}
Now Let's Imagine I have to populate the times during runtime and then Figure out the time remaining between Time 1 and T...
I have a solution called StoreExample
It has one web project - StoreExample.Web
It has one class library StoreExample.Core
Web has a reference to Core. What is the proper way to get an assembly reference to StoreExample.Core so I can loop over the classes in StoreExample? It seems like in LoadAssembly() method call I have to know the ...
How can I get the ConstructorInfo for a static constructor?
public class MyClass
{
public static int SomeValue;
static MyClass()
{
SomeValue = 23;
}
}
I've tried the following and failed....
Type myClass = typeof (MyClass);
// throws exception
myClass.TypeInitializer.Invoke(null);
// returns null (a...
So I have something like the following in Java:
private List<SomeType>variable;
// ....variable is instantiated as so ...
variable = new ArrayList<SomeType>();
// there's also a getter
public List<SomeType> getVariable() { /* code */ }
What I would like to be able to do is figure out that variable is a collection of SomeType progra...
Is it possible in a .NET app (C#), to conditionally detect if a class is defined at runtime?
Sample implementation - say you want to create a class object based on a configuration option?
...
From managed code, how do I load a managed type from another assembly at runtime, assuming the calling code does not have a static reference to the assembly?
To clarify, let's say I have class Lib in Lib.cs compiled into Lib.dll. I want to write a class Foo in a separate assembly called Foo.dll, that does not have a reference to Lib.dll...