Can anyone tell me if there a way to see if an action contains any code?
Action x = new Action(()=>
{
});
should return false, while
Action x = new Action(()=>
{
var x = "i am a string"
});
should return true.
Perhaps using reflection?
...
I need to convert from string that contains data to object of some type that is passed using reflection. I have an not serializable object that contains properties of any type and I want to load data to that object, for example that object has a property Color BgColor when I am trying to set "Red" value to that property I get that conver...
Is there a way to iterate over all the classes in the classpath ?
I want to make some reflective checks on some classes implementing a certain interface, but I want to do it completely dynamically, without any input on which classes to check, just browsing the classpath.
...
I have a class in vb.net like
Public Class Customer
Private _Name As String
Public Overridable Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
End Class
and a class deriving from it
Public Class Proxy...
Hi,
I have some base objects "Car", "dog", "cat" they implement an interface "IGWUIElement". I have a list of these interfaces: List myList.
At runtime I loop through the list of my elements and by examining the name of the class (using reflection) i need to populate their properties - which are not a part of the interface). I have an x...
I'm looping all the properties in an object via reflection:
For Each p As PropertyInfo In values.[GetType]().GetProperties()
If p.CanRead Then
'Do stuff
End If
Next
Can anyone tell me how to determine whether the property in question is a generic List(Of T)? If it is I need to loop the list it...
I am trying to Refactor this code as it is repeated ad nauseum throughout my program.
My problem has to do with the fact that on any given page(tabpage,panel,uc,etc) there are controls at multiple levels to spellcheck.
i.e. -->
foreach (Control control in tpgSystems.Controls)
{
if (control.GetT...
I need to create something similar to how MVC invokes an Method(Action) and also uses the Model Binder to map a NamedValueCollection to the parameters on that method. Basically I have a Controller action that needs to dynamically call a method on a class, the controller has any information sent in a form or query string plus the name of ...
Is this the appropriate way to access bean properties of an Object without knowing/caring about its exact type? (Or is there a built-in method that does this already?) Is there an appropriate exception to throw when a property does not exist or is not available?
static private Object getBeanPropertyValue(Object bean, String propertyName...
Let's say I have the following classes:
class A {
static public String a;
}
class B {
public function referToFieldInClassA() {
System.out.println(A.a);
}
}
Is there anything in the Java reflection APIs to allow me to find all places where a particular field is referenced? What I'm looking for is a way to find out that (give...
I want to use Assembly.ReflectionOnlyLoad() to extract MemberInfos from some .NET system assemblies like System, System.Windows.Forms and so on. Now the way I undestand it, I must supply the fully qualified name of the assembly (inlcuding version info and all that) or the path. However, I want my code not to rely on a specific version. I...
Consider this Java code
class A{
//@returns Class object this method is contained in
// should be A in this case
public Class<?> f() {
return getClass();
}
}
class B extends A {}
B b = new B();
System.out.println(b.f());
//output -- B.class (Wrong, should be A.class)
inside f() i can't use getClass() because that will give m...
At runtime, if a referenced assembly fails to load with e.g. "Strong name validation failed" (because it's test-signed), is there a way to provide a substitution assembly from another path that is real-signed?
I tried subscribing to AppDomain.CurrentDomain.AssemblyResolve, but it doesn't get fired, because the "bad" assembly technically...
How can you get the data type of a variable argument in Java if the varg is set to null? I use the getClass to retrieve the type. Is there any other way?
public void method(String name, Object ... vargs)
{
for(Object arg : vargs)
{
mapType.put(arg.getClass());
mapVal.put(arg);
}
}
The only thing i could thi...
Consider
Class A has two constructors new A(int), new A(int, String)
also
it has a method show()
Then given a statement like,
A a1= new A(4);
A a2= new A(3, "foo");
and later in code (or in some methods where these object were passed)
a1.show();
a2.show();
new A(3).show();
and
new A(2,"bar").show();
If I wanted to differen...
I have a program i frequently use that is made with .NET.
This program has a small bug that is very annoying and the developer to the app is nowhere to be found.
I have found the location of the problem in reflector and just want to add a single if-statement here and then recompile the program.
What is the easiest way to do this?
I ha...
I have the following case:
public interface IPerson { .. }
public class Person : IPerson { .. }
public class User : Person { .. }
Now; if I have a "User" object - how can I check if this implements IPerson using reflection? To be more precise I have an object that might have a property SomeUser, which should be of some type i...
I have an object which itself has multiple objects as fields. The question I have is, I have two objects of these kind and I want to compare these two. I know I can do equals, comparator etc. but is there a way to use reflection to get the properties of the object and make comparison.
for example, if I have a Car object, which as wheel...
Ok, maybe that title didn't make much sense, but here is the deal. Say I have a generic method with multiple type constraints, this this:
public static void DoSomethingAwesome<T>(T thing)
where T : IThing, IAwesome, IComparable<T>
{
...
}
Now.... how can I, using reflection, create something I can send in there?
If it was on...
How I can get the name of the parent class of some class using Reflection on C#?
...