Imagine we have an enum:
enum Foo { A=1,B=2,C=3 }
If the type is known at compile-time, a direct cast can be used to change between the enum-type and the underlying type (usually int):
static int GetValue() { return 2; }
...
Foo foo = (Foo)GetValue(); // becomes Foo.B
And boxing this gives a box of type Foo:
object o1 = foo;
Conso...
Can I retrieve a Method via reflection, somehow combine it with a target object, and return it as something that looks like a function in Scala (i.e. you can call it using parenthesis)? The argument list is variable. It doesn't have to be a "first-class" function (I've updated the question), just a syntactic-looking function call, e.g. f...
So, I have a Scala class that looks like this:
class TestClass {
var value: Option[Int] = None
}
and I'm tackling a problem where I have a String value and I want to coerce it into that Option[Int] at runtime using reflection. So, in another piece of code (that knows nothing about TestClass) I have some code like this:
def setField...
I have a class C in Assembly A like this:
internal class C
{
internal static string About_Name {
get { return "text"; }
...
}
I have about 20 such static properties. Is there a way, in an outside assembly, without using friend assembly attribute (.Net reflection only), get class C so I can invoke any of the static string pro...
What I am trying to do is load in objects from an XML save file. The problem is those objects are configurable by the user at runtime, meaning i had to use reflection to get the names and attributes of those objects stored in an XML file.
I am in the middle of a recursive loop through the XML and up to the part where I need to create a...
I am implementing a Boilerplate feature - allow users to Change descriptions of some components - like Tlabels - at run time.
e.g.
TFooClass = Class ( TBaseClass)
Label : Tlabel;
...
End;
Var FooClass : TFooClass;
...
At Design time, the value Label's caption property is say - 'First Name', when the
application is run, there ...
Given the following case:
<?php
class ParentClass {
public $attrA;
public $attrB;
public $attrC;
public function methodA() {}
public function methodB() {}
public function methodC() {}
}
class ChildClass extends ParentClass {
public $attrB;
public function methodA() {}
}
How can I get a list of me...
Hi guys.
I'm doing some dynamic code generation using Reflection, and I've come across a situation where I need to get the backing field of a property (if it has one) in order to use its FieldInfo object.
Now, I know you can use
.IsDefined(typeof(CompilerGeneratedAttribute), false);
on a FieldInfo to discover whether it's autogener...
I have seen the reverse of this question quite a few times, but have not seen how to do what I would like.
Suppose I have the following code:
var myNewData = from t in someOtherData
select new
{
fieldName = t.Whatever,
fieldName2 = t.SomeOtherWhatever
};
If I wish t...
Lets say i call method M1 on class A using reflection.
The method does not exist.
Is there any way to put a handler on class A that says, "someone is trying to execute method M1"?
Or
Is it possible to add a method dinamically to a class? I want to add a method M1...Mn that always does MyStaticClass.DoAction("M1...Mn");
Something li...
Here's a test that should, in my opinion be passing but is not.
[TestMethod]
public void can_get_open_generic_interface_off_of_implementor()
{
typeof(OpenGenericWithOpenService<>).GetInterfaces().First()
.ShouldEqual(typeof(IGenericService<>));
}
public interface IGenericService<T> { }
public class OpenGenericWithOpenService...
Hi All,
I am using .getDeclaredClasses() method to retrieve all the classes that have been defined in object. However, I am not able to retrieve anonymous classes defined in the class. Here is the code sample that I am testing:
public class TempCodes
{
public static void main(String[] args)
{
Ball b = new Ball()
{
pu...
I'm looking for an explanation for the following -
I have an assembly I'm loading using
Assembly assembly = Assembly.LoadFrom(filename);
I then loop on all the types in the assembly, and wish to try and find out if a type implements a particular interface and if so I want an instance of that type, I've tried several things which did ...
Hello,
How/am I able, using introspection or reflection get the parameters a method 1 level up in the call stack and it's values ?
...
I have an ASP.NET (3.5) page that allows a user to upload an Excel 2003 file with multiple sheets and that data is inserted into staging tables in the database. The mapping of database tables/columns to Excel sheets/columns is specified in an XML file. I use LINQ to SQL to send the data to the database.
ImportTablesDataContext db = ne...
Suppose I have a structure in C or C++, such as:
struct ConfigurableElement {
int ID;
char* strName;
long prop1;
long prop2;
...
};
I would like to load/save it to/from the following XML element:
<ConfigurableElement ID="1" strName="namedElem" prop1="2" prop2="3" ... />
Such a mapping can be trivially done in Java/C...
Say I have a class:
public class R {
public static final int _1st = 0x334455;
}
How can I get the value of the field/property "_1st" via reflection?
...
I am trying to dynamically load my authentication server type based on a setting. I am hung up on how to cast to a type when I don't know the type.
Type t = Type.GetType(WebConfigurationManager.AppSettings.Get("AuthenticationSvcImpl"));
IAuthenticationService authCli = Activator.CreateInstance(t);
return authCli.Authenticat...
Hi,
I'm searching for a way to get a list of method stubs of all classes within a jar file.
I'm not sure where to start... May I use Reflection or Javassist or some other tools of which I've not heard yet!?
At least it may be possible to unpack the jar, decompile the class files and scan with a line parser for methods, but I think that ...
What is the best way to go about this in C#?
string propPath = "ShippingInfo.Address.Street";
I'll have a property path like the one above read from a mapping file.
I need to be able to ask the Order object what the value of the code below will be.
this.ShippingInfo.Address.Street
Balancing performance with elegance. All object gr...