I have a factory method that creates objects to be used in unit tests. These objects all derive from the same base class:
public static <T extends BaseEntity> T modMake(Class<T> clazz)
{
try {
return clazz.newInstance();
} catch (InstantiationException e) {
// Should never happen
throw new AssertionError(...
I have a logging function that takes the calling object as a parameter. I then call getClass().getSimpleName() on it so that I can easily get the class name to add to my log entry for easy reference. The problem is that when I call my log function from a static method, I can't pass in "this". My log function looks something like this:...
Possible Duplicate:
Type.GetFields() - only returning public const fields
I have a class which looks like as follows:
public class MyConstants
{
public const int ONE = 1;
public const int TWO = 2;
Type thisObject;
public MyConstants()
{
thisObject = this.GetType();
}
public void EnumerateCo...
Right now, I have to do this
private delegate void set(int obj); //declare the prototype
...
Delegate delegate1 = Delegate.CreateDelegate(typeof(set), new testObject(), props[0].GetSetMethod());
((set)delegate1)(1);
Is there a way to CreateDelegate without that prototype and call it with any parameter? GetSetMethod() returns a very ...
How do you get an image to be reflected in wpf without using the xaml? I have a rectangle with a BitmapImageBrush as its fill. I want to be able to regularly flip this image (X-axis) back and forth at will in C#. I've read about using the ScaleTransform property but this only seems to work in the xaml and that's not what I want.
This is...
In Java, I can use a ClassLoader to get a list of classes that are already loaded, and the packages of those classes. But how do I get a list of classes that could be loaded, i.e. are on the classpath? Same with packages.
This is for a compiler; when parsing foo.bar.Baz, I want to know whether foo is a package to distinguish it from a...
Hi there
I am trying to determine the type of a property which an attribute relates to, from within the attributes constructor. More specificity I am looking for the class which contains the property.
my current constructor looks like this:
public IndexedCategoryAttribute(Type DefiningClass, String HeaderText, int Index)
{
...
Hi all,
I'm working on an asp.net MVC application.
I have a class that wraps a repository that fetches data from a db using simple linq statement. I've written a decorator class to add caching logic (using caching application block).
since I have several methods that I want to decorate, and the logic is all the same for each one (chec...
Does anyone know of any existing functionality in the .NET BCL to print the full signature of a method at runtime (like what you'd see in the VS ObjectBrowser - including parameter names) using information available from MethodInfo?
So for example, if you look up String.Compare() one of the overloads would print as:
public static int C...
There is already a similar question but it didn't seem to ask about the situation that the question implies.
The user asked about custom classes in a list but his list object is of type string.
I have a class Foo that has a list of Bars:
public class Foo : FooBase
{
public List<Bar> bars {get; set;}
public Foo(...
Okay, I have a an interface, lets call it
public interface bar {
string Foo;
}
also have a class that implements the interface
public fooBar : bar {
public string Foo {get; set;}
}
I then have a property hanging off another object that contains a list of interface "bar" that contain different implementations, like so,
pu...
I would like to know if there is something similar to CSharpCodeProvider, but it should work in ASP.NET Medium Trust, anyone knows a good one?
[EDIT 08-25-2009]
Why I want to do that?
I was writing a simple tutorial about Link to Objects and I would like users could write some simple querys on a textbox, post it to server to see the ...
I was writing some C# code recursively walking the referenced assemblies of a base assembly, building up a directed acyclic graph of these references to do a topological sort. I'm doing this by means of the GetReferencedAssemblies() method on the Assembly class.
While testing the code, I found - to my surprise - that some assemblies in ...
Hi,
I have a bunch of classes that each have a property called Sequence. This property is implemented from an interface called ISequenced. For this example lets call one of these classes A.
When I have a List(of A), I want to be able to sort them using the standard List.Sort(addressof delegate) where the delegate is a standard function ...
Lets say i have this class:
class Test123<T> where T : struct
{
public Nullable<T> Test {get;set;}
}
and this class
class Test321
{
public Test123<int> Test {get;set;}
}
So to the problem lets say i want to create a Test321 via reflection and set "Test" with a value how do i get the generic type?
...
Hello,
I'm trying to enumerate the properties of an Microsoft.Office.Interop.Outlook.ContactItem object (let's call it ci) with this code:
System.Reflection.BindingFlags bf = System.Reflection.BindingFlags.Default;
foreach (System.Reflection.PropertyInfo pi in ci.GetType().GetProperties(bf))
{
Conso...
This is a continuation of the post http://stackoverflow.com/questions/1319661/how-does-one-access-a-method-from-an-external-jar-at-runtime
McDowell responded with the code:
public class ReflectionDemo {
public void print(String str, int value) {
System.out.println(str);
System.out.println(value);
}
public static int getNumber...
Hi,
In C#, when I'm reflecting over a derived type, how come I don't see base classes' static fields?
I've tried both type.GetFields(BindingFlags.Static) and type.GetFields().
Thanks
...
I'm currently trying to get the type that an object was casted as in a later part of my application. This is primarily for a crazy situation that came up that would be a whole lot cleaner if I can get this to work. I wrote the following unit test that hopefully explains what I'm hoping to get working.
using System;
using NUnit.Framework...
I am curious to learn if .NET supports any form of dynamic interception of method calls (or properties invoctions) at runtime. That is, can you intercept a call to an object without static compilation information such as an interface (along the lines of the CORBA DII (link text) or COM's IDispatch).
If not, would the new 'Dynamic Typed ...