Is there any way to get FieldInfo of a field in a function that is going to assign a value to that variable?
See my example:
class SomeClass{
MyType myObject = SomeOtherClass.MyFunction();
}
class SomeOtherClass{
public static MyType MyFunction(){
//Get FieldInfo about myObject here
}
}
Background:
What I wa...
Hi guys,
If you like problems to resolve, here a big one :D
First, It isn't about serialization, ok?
Well, my situation... I am writting a function that I will pass as parameter a Xml (XmlDocument) and an object (Object) as reference. It will return to me a object (object that was referenced) filled with the values from the Xml (XmlDo...
I want to increment integer members of an object using Interlocked.Increment, but I want to reference those integers via reflection. Example code I have, which is not working, is below.
public class StatBoard
{
#region States (count of)
public int Active;
public int Contacting;
public int Polling;
public int Conn...
Is it possible to get a collection of public interfaces and classes in a given package using reflection?
Question is for Java 1.6
Why:
I have a package where some classes are annotated. I want to collect them automcatically for documenting
...
Hi,
I am using LoadFrom(), to load dlls, but for some reason this load function doesn't work on all dlls,
i want to load 3000 dlls to get from each one the copyright attribute.
my code :
class ReverseDLL
{
private Assembly assembly;
private AssemblyDescriptionAttribute desc;
private AssemblyTitleAttribute title;
pri...
How do I obtain an instance of a Type class for a type not defined in the currently executing assembly or in mscorlib.dll?
a) Namely, I've defined a class type someType in assembly CSharpSnapIn.dll, located at E:\CSharpSnapIn.dll, but for some reason when I try to specify an absolute path to this assembly, I get an exception:
Type t ...
Possible Duplicates:
How To Test if a Type is Anonymous?
Anonymous Types - Are there any distingushing characteristics?
Is there a way to detect if a Type object refers to an anonymous object?
var obj = new { A = "Hello" };
Type x = obj.GetType();
// is there something equivalent to x.IsAnonymous?
Assert.IsTrue(x.IsAnonymou...
I'm trying to use Type.InvokeMember(String, BindingFlags, Binder, Object, array[]) with the default binder.
one of the arguments to the target method in the object array is a reference type set to null. I want the method I'm invoking to instantiate the reference type so that I can continue using it. For example:
using System;
namespac...
I use a method similar to the following to get some precomputed metadata related to a Type's properties.
MyData GetProperty<T, U>(Expression<Func<T, U>> member)
{
// Get the property referenced in the lambda expression
MemberExpression expression = member.Body as MemberExpression;
PropertyInfo property = expression.Member as...
Is there a way to create a reflection on a UILabel?
I know how to do it in a UIImageView, but it's different.
Thanks
...
Say I have a method:
public void SomeMethod(String p1, String p2, int p3)
{
#if DEBUG
object[] args = GetArguments();
LogParamaters(args);
#endif
// Do Normal stuff in the method
}
Is there a way to retrieve an array of the arguments passed into the method, so that they can be logged?
I have a large number of meth...
I have to call a method whose name is coming from a configuration file. I can achieve this using Reflection.MethodInfo.Invoke() method. But my scenario is all these methods should be of same signature. Can i implement it using Delegates? but how can i add a method name stored in configuration file to a delegate?
...
I have a project where a client can import an excel file, csv, or tab-delimited file. This file is loaded into a datatable which I convert into a SQLite database table. I'd really prefer to work with strongly typed objects vs datatables so is there a way to easily convert the database table created into a strongly typed class using ref...
In ImageFormat, there are a few properties such as Png, Tiff etc.
Now, given a string is it possible to retrieve the corresponding static property?
Here's the code
[Test]
public void GetPng()
{
Assert.AreEqual(ImageFormat.Png, GetImageFormat("Png")); //how to construct a GetImageFormat function?
}
...
I am given:
A class "T" which implements properties that are decorated with Attributes that I am interested in.
A PropertyInfo "p" representing a property belonging to (1) an interface "I" that T implements, (2) a base class "B" that T inherits from, or (3) the class T itself.
I need to get the Attributes defined on (or inherited by)...
I was using newInstance() in a sort-of performance-critical area of my code.
The method signature is:
<T extends SomethingElse> T create(Class<T> clasz)
I pass Something.class as argument, I get an instance of SomethingElse, created with newInstance().
Today I got back to clear this performance TODO from the list, so I ran a couple of...
How can synthetic fields be created in Java?
Can synthetic fields in java only be created at runtime?
If not: Is there a standard-compliant way to this at compile time (without changing some bytes in the class file)
...
Hi,
Does reflection breaks the idea of private methods, because private methods can be access outside of the class? (Maybe I dont understand the meaning of reflection or miss something else, please write)
http://en.wikipedia.org/wiki/Reflection_%28computer_science%29
Edit:
If relection breaks the idea of private methods - does we use p...
Hello All,
I have created a custom Attribute to decorate a number of classes that I want to query for at runtime:
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public class ExampleAttribute : Attribute
{
public ExampleAttribute(string name)
{
this.Name = name;
}
public string N...
I have a class with a private static final field, that unfortunately i need to change at run time.
using reflection i get this error: java.lang.IllegalAccessException: Can not set static final boolean field
is there any possibility to change it anyway?
Field hack = WarpTransform2D.class.getDeclaredField("USE_HACK");
hack.setAccessible...