Все вопросы: [reflection]

1 159 вопросов

0
голосов
2ответов
564 просмотров

How will I do a property drill down?

How will I know if an object instance is a property or a sub property of another object instance? for example I have this class structure: public class Car { public Manufacturer Manufacturer {get;set;} } public class Manufacturer { public List<Supplier> {get;set;} } public...

2
голосов
3ответов
298 просмотров

How can I handle a POJO like a bean?

How can I access a simple java object as a bean? For example: class Simple { private String foo; String getFoo() { return foo; } private void setFoo( String foo ) { this.foo = foo; } } Now I want to use this object like this: Simple simple = new Simple(); ...

1
голосов
2ответов
3813 просмотров

could not load dll or one of its dependency

a. My C# program will load a dll (which is dynamic), for now let's take a.dll (similarly my program will load more dll like b.dll, c.dll, etc....). b. My program will invoke a method "Onstart" inside a.dll (it's constant for all the dll). I am able to achieve the above 2 cases by reflection mec...

2
голосов
3ответов
7451 просмотров

Java - getting the signature of a method in an interface, and the same for its Proxy implementation

I'm looking for a way to extract the essence of a signature in Java. The reason is that I want to use the signature as a unique key in a Map for my java.lang.reflect.Proxies. With this code: public interface MyInterface { public int compute(String s); } ... public static void main (String......

12
голосов
6ответов
3468 просмотров

How to retrieve .NET type of given StoredProcedure's Parameter in SQL?

I'm creating 'generic' wrapper above SQL procedures, and I can resolve all required parameters' names and sqltypes, but is there any way how to get it's 'underlying' .NET type? My goal is to do something like: SqlParameter param; object value; object correctParam = param.GetNETType().GetMethod...

4
голосов
2ответов
733 просмотров

How can I tell whether a field is the backing-field of an automatic-implemented property?

I'm using reflection to access and store properties and fields. However, to avoid having redundant data, I want to get rid of auto-implemented properties' backing fields, which are also enumerated as normal fields. Looks like these backing fields are named as "{PropertyName}k_BackingField", and i...

4
голосов
4ответов
11225 просмотров

Get Namespace, classname from a dll in C# 2.0

I will get dll's dynamically. I need to load the dll and get the namespace, classname to invoke a method (the method name is static it will be always "OnStart()"). Basically I need to run a method by loading the dll. Can somebody help!!!.

7
голосов
3ответов
6975 просмотров

PHP runtime class modification

So I want to be able to add/remove class methods at runtime. Before you tell me that's horrible pratice in oop, it might be, but I don't really care. The reason I want to be able to do this is because I want the application to be very modular, so some plugin could extend some base class and add m...

4
голосов
1ответов
1317 просмотров

Generic method with unspecified type possible?

I do need a solution for loading lists of objects - lookups where only one property is referenced from the current object as in this example. class LookupObjectAddress { [...] public string City { get; set; } [...] } class WorkingObject { // references the property from LookupObjectAddress...

4
голосов
3ответов
509 просмотров

How to find unexecuted code

Greetings, I have a large number of fitnesse tests for a project (1000+). Over time as features change, and shared fixtures come and go we have been left with unused orphaned code. But how to find it? For those who don't know how fit works, you have a wiki page with a like like this: | When ...

1
голосов
2ответов
1076 просмотров

.NET generic types - finding most specific type

Are there any good algorithms for determining the "best" type to instantiate in order to fulfill a request? For instance say I have the following classes: public interface ISometype<T> {} public class SomeTypeImpl<T>:ISometype<T> {} public class SomeSpecificTypeImpl<T>:I...

18
голосов
1ответов
9423 просмотров

Scala: set a field value reflectively from field name

I'm learning scala and can't find out how to do this: I'm doing a mapper between scala objects and google appengine entities, so if i have a class like this: class Student { var id:Long var name:String } I need to create an instance of that class, in java i would get the Field by it's...

3
голосов
4ответов
371 просмотров

Creating a collection of all classes that inherit from IBlahblah

Using reflection (i'm guessing?), is it possible to create a method that will return a collection of all objects that inherit from an interface named IBlahblah? public interface IBlahblah;

3
голосов
1ответов
957 просмотров

Generic type constructor resolution in C#, for IoC with generic service registrations

I'm trying to add generic service support to our IoC container, and I have a question. Let's say I have the following type: public interface IService<T> { ... } public class Service<T> : IService<T> { ... } and then the following code: Type type = typeof(Service<>); /...

0
голосов
1ответов
283 просмотров

Invalid compiler-generated .NET Class Name

I was going through Getting Started (with PostSharp) And when I saw PostSharp injected (is this expression is right?) an aspect code into assembly, I saw this oddly named class marked with CompilerGeneratedAttribute. It is named <>AspectsImplementationDetails_1. As far as I know, class n...

13
голосов
5ответов
6784 просмотров

Get read/write properties of Anonymous Type

I need to fetch all the properties of an anonymous type which can be written to. eg: var person = new {Name = "Person's Name", Age = 25}; Type anonymousType = person.GetType(); var properties = anonymousType.GetProperties(BindingFlags.Public | BindingFlags.Instance); The problem is that ...

7
голосов
2ответов
4956 просмотров

Get paths of assemblies used in Type

I need a method that takes a Type and returns the paths of all assemblies that used in the type. I wrote this: public static IEnumerable<string> GetReferencesAssembliesPaths(this Type type) { yield return type.Assembly.Location; foreach (AssemblyName assemblyName in type.Assembly.Get...

2
голосов
2ответов
2886 просмотров

How can I get delegates to property accessors from a generic type?

I'm currently building a node editor (as in Blender) and am having trouble getting delegates to property accessors from a generic type. So far the question here has brought me closest, but I'm having trouble that I think is specifically related to the type of object being generic. For reference,...

2
голосов
2ответов
1098 просмотров

Shorten this reflection property name helper method?

I want a static helper method to remove magic strings. Of course, I could pack the property method inside the TestContainer, which would remove the need to provide the TestContainer as argument. This is done nicely here. But I would like to have the helper method in one static class, in case I l...

0
голосов
1ответов
1557 просмотров

How to implement a Properties window style control/system in Windows Forms?

So what I am trying to do is to have a set UI with certain controls, and I want to have some class instance to fill in the values. For instance: Classes that can populate the UI: Sharpen, Blur, Smear, ... : FilterBase So whenever the user creates an instances of the above classes, I want to ...

1
голосов
3ответов
355 просмотров

.Net Reflection: find the parent 2 generations up the chain

I'm new to System.Reflection and I've stumbled on the following. I am using a third party executable, A, that has a custom interpreter engine class B that allows me to build simple 'tasks' that run on a mobile device. 'A' also has a class C that, when using A's default interface, shows a list of...

11
голосов
4ответов
2967 просмотров

Retrieve MethodInfo of a F# function

I would like to write a function that takes a function f as an argument and returns the System.Reflection.MethodInfo associated to f. I'm not quite sure if it is feasible or not.

5
голосов
3ответов
1259 просмотров

C# print a delegate

Is there a simple way to print the code of a delegate at runtime ? (that "contains one method"). public delegate void SimpleDelegate(); SimpleDelegate delegateInstance = delegate { DoSomeStuff(); int i = DoOtherStuff() }; Now, I would like to display on the screen the body of dele...

125
голосов
5ответов
62577 просмотров

Is it possible to set private property via reflection?

Can I set a private property via reflection? public abstract class Entity { private int _id; private DateTime? _createdOn; public virtual T Id { get { return _id; } private set { ChangePropertyAndNotify(ref _id, value, x => Id); } } public virtual DateT...

12
голосов
3ответов
5665 просмотров

It's possible in Java to access the source code of a method "reflectively"?

I'm afraid that the answer is no, but maybe one of you surprises me. Thanks. Edit 1: I'm aware that the question doesn't make much sense but I think the point was understood and, sadly, the answer is no. Anyway I changed the title of the question adding quotes to the word "reflectively" and I...

0
голосов
1ответов
70 просмотров

How do I obtain a list of all of the pages within an asp.net mvc project

How do I obtain a list of all of the pages within an asp.net mvc project for use in a dropdown list. I'd also like to obtain a list of all of the controls within that page. The problem is that I'd be calling this from a different project in the same solution. Can i use reflection for this????

3
голосов
3ответов
347 просмотров

Do languages with meta-linguistic abstraction perform better than those that just use reflection API for that?

Say, if I have a Lisp program, which uses (eval 'sym) and looks it up in its symbol-table does it actually perform better than something like aClass.getField("sym", anInstance) in "static" languages?

1
голосов
1ответов
688 просмотров

Calling a F# function via a Linq expression tree MethodCallExpression node?

I am trying to create an expression tree containing a function call to a F# function on a certain module. However, I am missing something because the System.Linq.Expressions.Expression.Call() helper function cant find the function I'm supplying. The Call() call gives an InvalidOperationException...

99
голосов
3ответов
133847 просмотров

Is it possible in Java to access private fields via reflection

Is it possible in Java to access private field str via reflection? For example to get value of this field. class Test { private String str; public void setStr(String value) { str = value; } }

0
голосов
1ответов
107 просмотров

Access code in a View via reflection

I have an HtmlHelper CmsEntry that is used like this <%= Html.CmsEntry("stores.buyourstuff")%> This helper is used lots of times and I want to generate a list of all views that contain this helper. The list should contain the Viewname and the key ("stores.buyourstuff"). Is there a too...