Is this code wrong? It's just not returning anything:
public IEnumerable<string> GetMethodsOfReturnType(Type cls, Type ret)
{
var methods = cls.GetMethods(BindingFlags.NonPublic);
var retMethods = methods.Where(m => m.ReturnType.IsSubclassOf(ret))
.Select(m => m.Name);
return retMethods;
}
It's retu...
i'm playing around with c# reflection api. i can easily load type info of classes, methods etc. in an assembly.
now i wonder how can i load and read the code inside a method?
...
Hi All,
I have to implement a logic whereby given a child class, I need to access its parent class and all other child class of that parent class, if any. I did not find any API in Java Reflection which allows us to access all child classes of a parent class. Is there any way to do it?
Ex. class B extends class A
class C extends class ...
I have a grails project with some additional java source files under src/java folder. When compiling/running the server, the files under that directory get compiled into the project's target folder, together with all other groovy/grails classes. So far so good.
However, when I try to load one of the java source files (from src/java) usi...
Hi All,
Using Reflection in PHP I can dynamically create a object like so
$target = 'core_domain_Person';
$reflect = new ReflectionClass($target);
$obj = $reflect->newInstance();
I would like to replicate this same concept in JavaScript is there a way to do this out of the box? Or is there a way to replicate what Reflection is doing?...
What is the difference between normal reflection and the reflection that can be done with lambda expressions such as this (taken form build your own MVVM):
public void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property)
{
var lambda = (LambdaExpression)property;
MemberExpression memberExpression;
if (lamb...
I know I can do
for (id obj in array)
{
if ([obj isKindOfClass:[Elephant class]])
[elephants addObject:obj];
}
but I feel there must be a more elegant way of doing this. I've looked at filtering arrays but can't come up with a good predicate. Thoughts?
...
Hi,
I have read about Java Reflections but till date it has been a vague concept to me. Can someone give a brief details with short example on how to use reflections in Java ?
Thanks.
...
Hi
I want to simulate user behavior in an java application and I want to write method calls and parameters to a log file that i will read and make the same calls with.
I want to do this using reflection (java.lang.reflect.Proxy) to both write the file to a log and then read the log and make the calls. Is there a tool or way to
1.Write...
While the .NET 4 framework provides the Assembly.IsDynamic method, that's not the case with .NET 2.0/3.5.
The use case is simple: for logging purposes, I want to determine the underlying type name of an entity that might be wrapped by a dynamic proxy without having any references to NHibernate or Castle (which know about the proxy)
For...
Hello,
I wrote the question as a comment in the code, I think its easier to understand this way.
public class Xpto{
protected AbstractClass x;
public void foo(){
// AbstractClass y = new ????? Car or Person ?????
/* here I need a new object of this.x's type (which could be Car or Person)
I know that w...
I'm attempting to compile code in a text file to change a value in a TextBox on the main form of a WinForms application. Ie. add another partial class with method to the calling form. The form has one button (button1) and one TextBox (textBox1).
The code in the text file is:
this.textBox1.Text = "Hello World!!";
And the code:
nam...
I recently started work at a new company and a .net web application we have is built using reflection. I have only been out of school for a year and haven't worked with this concept. After studying the code... it looks like there is a single backend interface of type object that has about 20 classes that inherit from it. lots of generi...
Hi there
I am pretty new to XNA & game dev and am stuck at ball reflection. My ball is reflecting once it hits the bat, but only in one angle, no matter which angle the bat is at.
Here's the code:
if (BallRect.Intersects(BatRect))
{
Vector2 NormBallVelocity = Ball.velocity;
NormBallVelocity.Normalize();
Norm...
Hi,
I wonder if someone can help me. I've got a console App which I use to debug various components as I develop them.
I'd like to be able to log to the console every time an event is fired either in the object I've instantiated or in anything it's instantiated [ad infinitum]. I wouldn't see some of these events normally due to them be...
Hi,
here is the problem case i am writing a little third party library. In this library i have a class like this
public class TestClass
{
public int TestField { get; private set; }
public TestClass( )
{
TestField = 1;
}
}
Then i have a varialbe form this class like this
public Te...
How can I test to see if a class contains a particular attribute?
In [14]: user = User.objects.get(pk=2)
In [18]: user.__dict__
Out[18]:
{'date_joined': datetime.datetime(2010, 3, 17, 15, 20, 45),
'email': u'[email protected]',
'first_name': u'',
'id': 2L,
'is_active': 1,
'is_staff': 0,
'is_superuser': 0,
'l...
I want to find the token's name passed by augment into a function.
class Norm
{
const STR_NORM = 0;
const INT_NORM = 0;
}
function foo($Arg1, $Arg2 = NULL)
{
getConstName($Arg1); # Should Return STR_NORM;
return $Arg1, $Arg2;
}
echo foo(Norm::STR_NORM);
Is there any way to implement getConstName via the PHP Reflectio...
I'm trying to implement a plugable architecture in asp.net MVC. I have based my modules on the following article - http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins.
I have a DLL that contains a simple controller, and a view. The view is an embedded resource within the DLL.
The problem I'm having is, if I drop the DLL in the bi...
Hi!
How to write a simple method, that checks whether a concrete type is a custom struct (created with public struct { };) or not.
Checking Type.IsValueType is not enough, because it is also true to int, long, etc,
and adding a check to !IsPrimitiveType won't exclude decimal, DateTime and maybe some other value types. I know that most ...