Update I fixed up the code to eliminate duplication of overridden methods and track originator of property or method by implementing Mark's suggestion. Haven't tackled property types yet (will probably start with property_getAttributes() when I do). Also stripped out vestigial underscores.
Basically I need a way to remind myself what ...
I'm trying to determine the type of a field on an object. I don't know the type of the object when it is passed to me but I need to find fields which are 'long's. It is easy enough for Longs but the primitive long seems more difficult.
I can make sure that the objects passed to me only have Longs not the primitives but I'd rather not. S...
public class CustomProperty<T>
{
private T _value;
public CustomProperty(T val)
{
_value = val;
}
public T Value
{
get { return this._value; }
set { this._value = value; }
}
}
public class CustomPropertyAccess
{
public CustomProperty<string> Name = new CustomProperty<string>("cfgf...
I want to use
Class.getMethod(String name, Class... parameterTypes)
to find the method I need to invoke with the given parameters, but apparently as described in Bug 6176992 Java doesn't include autoboxing there. So if my reflected class has a method with a (String, int) signature you still get a NoSuchMethodException with a {String.c...
Hi!
I'm reading and learning about reflection in C#. It would be fine to know how can it help me in my daily work, so I want people with more experience than me tell me samples or ideas about what kinds of things can we achieve using it, or how can we reduce de amount of code that we write.
Thanks.
...
Can someone explain this paragraph on page 258(Pro ASP.NET MVC 1.0 Chapter 6: Using the HTML Helpers)?
If you're writing a third-party
library(as opposed to a web
application) that uses the HTML
helpers, never call the overloads that
accept anonymous objects. Always call
the overloads that accept
dictionaries. Otherwise...
Hi!
I need to assign an eventHandler to an object, in this way:
_Element.AddHandler(UIElement.MouseLeftButtonUpEvent, new RoutedEventHandler(Vars.Digit), true);
but, in fact, I only have a string that contains "Digit" or other method name in the Vars object instance.
It is possible to achieve this using reflection or other kind of t...
In some part of my code I am passed a collection of objects of type T. I don't know which concrete colletion I will be passed, other than it impements IEnumerable.
At run time, I need to find out which type T is (e.g. System.Double, System.String, etc...).
Is there any way to find it out?
UPDATE: I should maybe clarify a bit more the ...
Is it possible to get the type of a generic parameter?
An example:
public final class voodoo {
public static chill(List<?> aListWithTypeSpiderMan) {
// Here I'd like to get the Class-Object 'SpiderMan'
Class typeOfTheList = ???;
}
public static void main(String... args) {
chill(new List<SpiderMan>(...
Seemingly something of a misnomer, as pass by reference is deprecated in PHP 5.3... anyway, what I'm trying to do is write a unit test framework using reflection, that allows you to pass arguments to a method which requires a reference. e.g.
class Bar {
function TestMethod($arg1, &$result) {
$result = 'hello';
return...
Following this question, why does enumerable in this:
Type type = typeof(List<string>);
bool enumerable = (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>));
return false?
Edit 1
As the above doesn't work, what would be the best way to determine if a class implements IEnumerable?
...
Hi everybody,
I'm woking on a project that requires to extend ConfigurationSection for every configuration object. Configuration information is stored into the database and it can be overriden by custom local configuration. It's the opposite order as I mentioned (local values are merged to database info, proritizing database).
Classed ...
I need the object (or "singleton object" or "companion object"... anything but the class) defined by a string name. In other words, if I have:
package myPackage
object myObject
...then is there anything like this:
GetSingletonObjectByName("myPackage.myObject") match {
case instance: myPackage.myObject => "instance is what I wanted"...
How could I avoid this dictionary (or create it dynamically)?
Dictionary<Type,Type> CorrespondingNullableType = new Dictionary<Type, Type>
{
{typeof(bool), typeof(bool?)},
{typeof(byte), typeof(byte?)},
{typeof(sbyte), typeof(sbyte?)},
{typeof(char), typeof(char?)},
{typeof(decimal), typeof(decimal?)},
{typeof(...
I need to retrieve all enums that were loaded from a given set of Assemblies.
...
I need some method that is going to get the property's string name, I don't know if this is possible in C#, is it ?
...
Is there a way to create an instance of HttpPostedFile with Reflection.
I tried:
var obj = (HttpPostedFile)typeof(HttpPostedFile).GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance,
null, Type.EmptyTypes, null).Invoke(null);
var obj2 = Activator.CreateInstance(typeof(HttpPostedFile)
...
In my CMS I have a load of modules which allow me to do some clever item listing stuff. I am trying to use them to pull out a list of their child objects via reflection, but am getting stuck with the level of generics involved.
I have got as far as this method:
var myList = moduleObj.GetType().GetMethod("ChildItems").Invoke(moduleObj, ...
I'm trying to create an instance of HttpPostedFile with
var obj2 = Activator.CreateInstance(
typeof(HttpPostedFile),
BindingFlags.NonPublic | BindingFlags.Instance,
null,
new object[] { },
System.Globalization.CultureInfo.CurrentCulture
);
but I'm getting the error 'Constructor on type 'System.Web.HttpPostedFile' ...
In a C# solution, I have multiple class libraries for the domain model, services, and repositories. I configured Unity in web.config of the main website project so that it knows what concrete objects to map to the services and repositories. For quick testing, though, I'd like to use PowerShell to load the assemblies and manipulate classe...