So I'm playing with geotools and I thought I'd proxy one of their data-access classes and trace how it was being used in their code.
I coded up a dynamic proxy and wrapped a FeatureSource (interface) in it and off it went happily. Then I wanted to look at some of the transitive objects returned by the featureSource as well, since the ma...
sTypeName = ... //do some string stuff here to get the name of the type
/*
The Assembly.CreateInstance function returns a type
of System.object. I want to type cast it to
the type whose name is sTypeName.
assembly.CreateInstance(sTypeName)
So, in effect I want to do something like:
*/
assembly.CreateInstance(sTypeName) as Type.GetT...
I have an interface:
public abstract class Authorizer<T> where T : RequiresAuthorization
{
public AuthorizationStatus Authorize(T record)
{
// Perform authorization specific stuff
// and then hand off to an abstract method to handle T-specific stuff
// that should happen when authorization is successful
...
Hi All,
I am trying to to use reflection to achieve the following:
I need a method where i pass in an object and this method will recursively instantiate the object with child objects and set the properties with default values. I need the entire object instantiated going as many levels as needed.
this method needs to be able to handle...
I'm trying to build a way of mapping from one type to another, knwoing they will (should) have the same structure. Related Question.
For ease of the fiddly bits, I'm using AutoMapper from Codeplex, with the following function:
private static List<Type> seenTypes = new List<Type>();
private static void MapDataObjects(Type a, Type b)
{
...
I've got a Customer object with a Collection of CustomerContacts
IEnumerable<CustomerContact> Contacts { get; set; }
In some other code I'm using Reflection and have the PropertyInfo of Contacts property
var contacts = propertyInfo.GetValue(customerObject, null);
I know contacts has at least one object in it, but how do I get it ou...
Consider the following:
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
public class NotNullAttribute : Attribute
{
}
public class Class1
{
[return: NotNull]
public static string TestMethod([NotNull] string arg)
{
return arg + " + " + arg;
}
}
How, using System.Reflection, would you...
I'm looping through the page controls like so
foreach (Control ctrl in control.Controls)
{
if (ctrl is System.Web.UI.WebControls.TextBox || ctrl is System.Web.UI.WebControls.Label)
{
}
}
I want to be able to declare a variable inside this if statements that is the same type as 'ctrl' in ...
Hi,
I am trying grab all the member variables in AS3, and then foreach one i would like to process it in various ways. I would need the name and then if it is a collection of some type I would like to loop through that collection as well. I am attempting to essentially serialize in a somewhat custom fashion.
Thanks!
...
hi,
i used java reflections to get methods from a class(loaded those classes).Now i want to get the call hierarchy of those methods.How can i use call hierarchy option in eclipse IDE for that?any examples or links????
...
Hi ,
Assume I have a singleton class in an external lib to my application. But still I can
create instances of that particular class using reflection. Like this
Class clas = Class.forName(Private.class.getName());
for(Constructor c : clas.getDeclaredConstructors()){
c.setAccessible(true);
Private p = (Privat...
Hi, I have following class (as seen through reflector)
public class W : IDisposable
{
public W(string s);
public W(string s, byte[] data);
// more constructors
[MethodImpl(MethodImplOptions.InternalCall)]
internal extern W(string s, int i);
public static W Func(string s, int i);
}
I am trying to call "inter...
Thanks @dtb for help, he advised really need piece of code for generic service locator
static class Locator
{
private static class LocatorEntry<T> where T : ...
{
public static IDataManager<T> instance;
}
public static void Register<T>(IDataManager<T> instance) where T : ...
{
LocatorEntry<T>.instanc...
I am trying to create instance of class by using reflection in ASP.net web site. Class ClassName is defined and located in App_code folder. Following line returns null, what could be wrong.
Type type = Type.GetType("NameSpace.ClassName", false, true);
...
A friend of mine is working on a legacy VB6 project. I haven't touched that language in ten years, so I'm pretty rusty. Anyway, is there any kind of reflection API for VB6? Specifically, he needs a way to iterate the properties (and types) of a user-created Class. (In other words, not an external COM object, but an internal "Class Module...
Consider the following code:
class Foo(var name: String = "bar")
Now i try to get the value and the correct type of it via reflection:
val foo = new Foo
val field = foo.getClass.getDeclaredField("name")
field.setAccessible(true)
//This is where it doesn't work
val value = field.get(????)
I tried things like field.get(foo), but that...
We implement a plugin framework for our application and load plugin assemblies using Assembly.Loadfrom. We then use GetTypes() and further examine the types with each plugin file for supported Interfaces.
A path for the plugins is provided by the user and we cycle through each of the files in the folder to see if it (the plugin) support...
Let us say we have a method which accepts two arguments o1 and o2 of type Object and returns a boolean value. I want this method to return true only when the arguments are instances of the same class, e.g.:
foo(new Integer(4),new Integer(5));
Should return true, however:
foo(new SomeClass(), new SubtypeSomeClass());
should return f...
I have some code that is using reflection to pull property values from an object. In some cases the properties may throw exceptions, because they have null references etc.
object result;
try
{
result = propertyInfo.GetValue(target, null);
...
Hello
I'm trying to use an event dispatcher to allow a model to notify subscribed listeners when it changes. the event dispatcher receives a handler class and a method name to call during dispatch. the presenter subscribes to the model changes and provide a Handler implementation to be called on changes.
Here's the code (I'm sorry it's ...