I appreciate that similar questions have been asked before, but I am struggling to invoke the Linq Where method in the following code. I am looking to use reflection to dynamically call this method and also dynamically build the delegate (or lambda) used in the Where clause. This is a short code sample that, once working, will help to fo...
I'm developing an application using C# in .Net Framework 3.5. In the application I create several objects from different dll (also developed in C#) using reflection. All this objects extend an abstract class (AApplication):
private AApplication BuildApplication(string path)
{
Assembly appAssembly = Assembly.LoadFrom(path...
Hi,
I feel like I'm so close to working this out and have read dozens of articles and existing questions.
I have a method like this:
public T DoStuff(object arg1, object arg2)
{
/* Do stuff and return a T */
}
And I need to be able to pass this method to another class for callback purposes.
However, when this other class calls bac...
I examine the parameters of a C# method using reflection. The method has some out parameters and for these I get back types, which have IsByRef=true. For example if the parameter is declared as "out string xxx", the parameter has type System.String&. Is there a way to convert System.String& back to System.String? The solution should of c...
I was wondering if there was a built in runtime parser for header files in C#. I have several different C header files that I want to parse (They will later be used to determine how a network packet will be deserialized).
Ideally, some option to load the .h file dynamically, create the struct, and then use reflection to somehow parse t...
Hello, I have a question involving calling a class's generic method with a type parameter that is known at runtime.
In specific, the code looks like so:
FieldInfo[] dataFields = this.GetType().GetFields( BindingFlags.Public | BindingFlags.Instance );
// data is just a byte array used internally in DataStream
DataStream ds = new DataS...
I have a class in VB with some constants that represent the string name of my security roles. I need to be able to call a function to return to me a string array(or collection, or whatever) of the values of each of these constants. I will be using it to make sure that my databases Roles table has the same roles as coded into the applic...
My intention is to investigate the "Methods" of a Type using reflection in order to verify the following :
The Methods should be instance methods and public.
Takes the parameter "params" and void in nature.
The Method does not makes recursive call.
I started as :
static void ProcessMethodInfo(Type t)
{
MethodInfo[] info...
Hi,
i need to read classes contained in a java package. Those classes are in classpath. I need to do this task from java program directly. Do you know a simple way to do?
List classes = readClassesFrom("my.package")
...
Why use of Reflection in .net C# code are recommended?
Is it definately a good parctice to use it?
What will the possible situations in a project to take maximum benefit of reflection, can we identify some?
...
For debugging purposes, I need to follow the execution of some piece of code, within a class. I would like to generate a log for all method calls, in XML, like :
<call class='pack.age.MyClass' method='myMethod1'>
<param name='param1'>param1.toString() value</param>
...
<call>Call to other method within myMethod1; you get the...
I am currently working on localizing a Form. However I am somewhat confused as to how one correctly does this.
I thought it would be possible to export control properties to a resource file automatically, but it seems this is a manual task.
My current approach is to add all the Control Properties which are of type String and are writab...
Hello,
is there a function that, given a C# type's string representation, returns the corresponding .Net type or .Net type's string representation; or any way to achieve this.
For example :
"bool" -> System.Boolean or "System.Boolean"
"int" -> System.Int32 or "System.Int32"
...
Thanks.
Edit : really sorry, it's not a "type to type...
The System.Type class provides a GetInterfaces() method that "gets all the interfaces implemented or inherited by the current Type".
The problem is that "The GetInterfaces method does not return interfaces in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which interfaces are ret...
If I run this code:
var myAsm = typeof(MyType).Assembly;
var types = myAsm.GetExportedTypes();
I get:
System.IO.FileNotFoundException : Could not load file or assembly ....
which lists a dependent assembly. However, if I do:
var myAsm = Assembly.LoadFrom(...); // DLL containing the same assembly as above
var types = myAsm.GetExp...
Say, I have an XML String like this,
<METHOD>foo</METHOD>
<PARAM1>abc</PARAM1>
<PARAM2>def</PARAM2>
...
<PARAM99>ghi</PARAM99>
<PARAM100>jkl</PARAM100>
and I have a method
void foo(String param1, String param2, ..., String param99, String param100)
{
...
}
Is there any easy way for me to map this string to a real method call with t...
I was toying with the idea of allowing module to with a class in a properties file ; something like
availableModules.properties
Contact=org.addressbook.ContactMain
Business=org.addressbook.BusinessMain
Notes=org.addressbook.Notes
...
My framework will use reflection to instantiate the relevant modules, and thereafter call methods on...
I'm getting a Type using Assembly class as follows:
var asm = Assembly.GetAssembly(typeof(MyAssembly));
var t=asm.GetType("FULLY QUALIFIED CLASS NAME", true, true);
Then I create object from this type:
var obj = Activator.CreateObject(t, new []{ params });
Now I want to convert or cast this object to a Generic object (actually SubS...
I am attempting to create an Expression that will invoke a specific generic overloaded method (Enumerable.Average in my first test case). The specific type bindings are not known until runtime however so I need to use Reflection to find and create the correct generic method (the Expression is being created from parsed text).
So if I kno...
For logging purposes, some methods in our application include the following line:
Dim Log As ILog = GetLog(Reflection.MethodBase.GetCurrentMethod().DeclaringType)
I have what might be described as an irrational fear of reflection, which I try to keep in check. However, calls like this in methods that are executed potentially a hundred...