I'm writing a custom deserializer that will deserialize a list by deserializing each of the individual objects in the collection and then putting it together.
Basically my code looks like this:
//myField is a FieldInfo that represents the field we want to put the data in
//resultObject is the object we want the data to go into
List<Ob...
Hi all,
I would like to (and I don't know if it's possible) do something if jarA is in my classpath and do something else if jarB is in my classpath. I am NOT going to be specifying these jars in the Netbeans project library references because I don't know which of the jars will be used.
Now including the jar in my Netbeans project li...
In general reflection in a base class can be put to some good and useful ends, but I have a case here where I'm between a rock and a hard place... Use Reflection, or expose public Factory classes when they really should be private semantically speaking (ie. not just anyone should be able to use them). I suppose some code is in order here...
I got myself in a situation where using the System.Attribute class seemed (at first glance) to be a good idea.
I have an object to be printed in my application, and I need a label before each property (or just a string before it). I could put each property hardcoded like:
Console.WriteLine("Color:"+obj.color);
Console.WriteLine("Size:...
I am running an executable jar and wish to find a list of classes WITHIN the jar so that I can decide at run-time which to run. It's possible that I don't know the name of the jar file so cannot unzip it
...
Is there a way of determining the name of a constant from a given value?
For example, given the following:
public const uint ERR_OK = 0x00000000;
How could one obtain "ERR_OK"?
I have been looking at refection but cant seem to find anything that helps me.
...
I'm working on an appender for log4net and I'm faced with the problem of how to manage dependencies on the log4net version my class library is built against vs. the actual version deployed on the site. My class library has to reference log4net dlls and as such it becomes tied to the version I'm referencing at built time. However, the sit...
I have a class with a property Value like this:
public class MyClass {
public property var Value { get; set; }
....
}
I want to use MethodInfo.Invoke() to set property value. Here are some codes:
object o;
// use CodeDom to get instance of a dynamically built MyClass to o, codes omitted
Type type = o.GetType();
MethodInfo mi = ...
For example I have the following tables resulting from:
CREATE TABLE A (Id int, BId int, Number int)
CREATE TABLE B (Id int, Number decimal(10,2))
GO
INSERT INTO A VALUES(1, 3, 10)
INSERT INTO B VALUES(3, 50)
INSERT INTO A VALUES(2, 5, 20)
INSERT INTO B VALUES(5, 671.35)
GO
And I run the following query multiple times:
SELECT * FROM ...
I want to do some logging while executing my JUnit test. In JUnit 3.x it was always easy to obtain the name of the currently running test case, no matter how the test case was instantiated:
public void testFoo() throws Exception() {
String testName = this.getName();
// [...] do some stuff
}
In JUnit 4 things seem to be not so easy...
I need to convert an open delegate (one in which the Target is not specified) into a closed one efficiently. I have profiled my code, and the cost of using CreateDelegate() to produce a closed delegate for an instance method is a significant fraction (>60%) of the overall run time (as it takes place for each new instance of the type).
...
I'm curious about the possibility of having a .NET class library that provides a complete abstraction of HTML (and perhaps CSS styles as well).
There would be a .NET class for every kind of HTML element, and even abstract classes (e.g. an abstract base class 'List', which 'OrderedList' and 'UnorderedList' extend).
The elements could be...
I want to convert an OpenOffice Impress Presentation file and convert it to HTML or JPEG.
I have found a few examples, but they appear to be broken. I would like to do it, in a way that it does not matter what version of OpenOffice is installed, and I do not want to bundle any interop dlls with my application. Therefore, I am looking fo...
I use a WsdlImporter and ServiceContractGenerator to set up CodeDomProvider to get an assembly which (I thought) should allow me to create an instance of my HelloWorldService.
MetadataExchangeClient mexClient = new MetadataExchangeClient(metadataAddress);
mexClient.ResolveMetadataReferences = true;
MetadataSet metaDocs = mexClient.Get...
I want to return a private field from a remoted object but i get the exception:
RemotingException was caught
Remoting cannot find field 'connectionString' on type 'DBGeneral'.
I DO get the Private field's FieldInfo object when executing the GetField() method.
FieldInfo field = o.GetType().GetField("connectionString", BindingFlags.Inst...
I have an event handler that needs to determine a type and execute code if it matches a specific type. Originally we cast it to an object and if it wasn't null we executed the code, to speed it up I used reflection and it actually slowed it down and I don't understand why.
here is a code sample
Trace.Write("Starting using Reflection"...
Hi
I am trying to get the ID field name (property name) of an entity, is it possible?
User user= new User(); //User is an Entity
string idField = ??????? //user.UserId
...
Class someInterface = Class.fromName("some.package.SomeInterface");
How do I now create a new class that implements someInterface?
I need to create a new class, and pass it to a function that needs a SomeInterface as an argument.
...
I'm creating an assembly via reflection, and then using it to create an instance of a WCF service client.
object obj =
assembly.CreateInstance(
serviceName, true,
BindingFlags.CreateInstance,null,createArgs, null, null);
Type type = obj.GetType();
obj is of type HelloWorldServiceClient.
type.GetMethods() has 14 M...
I am loading several different classes from several different .jars from a custom class loader in Java. I create a custom URLClassLoader, add several .jars to it and pass it on to a ServiceLoader to find the classes I want.
My question is: given a class, is there a way to discover which .jar it was loaded from?
...