reflection

c#: Using Assemblies (via Reflection) as a (meta)data store

SOME CONTEXT one of my projects requires carrying around some of "metadata" (yes I hate using that word). What the metadata specifically consists of is not important, only that it's more complex than a simple "table" or "list" - you could think of it as a mini-database of information Currently I have this metadata stored in an XML fil...

Check method signature before creating delegate

Hi I have two delegates. I want to use reflection to load a assembly/classes and the go threw each class to see if the static methods in the class match the delegates. I got everything up to getting all the methodinfos but i can seem to find any method to check if it matches the delegate and i really dont want to try create and catch e...

.NET reflection question

Hi, The following code (packaged in a 'Console Application' Visual Studio project): using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespace TestReflection { class Program { static void Main(string[] args) { bool found = false; foreach (Assemb...

Database to GlazedList/Jtable and then edit the database through the GlazedList/JTable

I am able to break this problem down into two questions: What is the best way to put the contents of a database (MS-Access) into a GlazedList/JTable? How do I make sure any changes made to the GlazedList/JTable are reflected on the database (MS-Access)? Here are the things I know: I know how to retrieve/manipulate the information f...

Is there a way to programmatically get the source file and line number of an arbitrary MemberInfo?

I am writing a code analysis tool that uses reflection to validate a particular code base. When I encounter a type or member of interest I would like to load the symbols and extract the source file and line number where the member or type is defined. Is this possible? If so, how? class SourceInfo { public static SourceInfo GetFrom(M...

Reflection Help - Set properties on object based on another object

Hello All, I could use a bit of relection help. I am passing an object into the constructor of another object. I need to loop through the parameter's properties and set the new objects properties based on it. Most, but not all, of the params properties exist in the new object. I have this so far, the basic skeleton. public Disabilit...

Possible weaknesses regarding using reflection in a business application

Hi, Experimenting using different approaches and reducing code maintenance I have ended up using reflection to create new forms in my MDI application. The reason for this 'solution' is to provide a central place to setup new forms, implement security checks and possible future needs. I currently have a static Activator class that is i...

Will this code work on your version of Visual Studio? C#

Hello, I want to use this code to grab all methods from the assembly "Mscorlib.dll" but i get this error "Unable to cast object of type 'System.Reflection.RuntimeConstructorInfo' to type 'System.Reflection.MethodInfo'." Basically all I want to do is get a list of interfaces or Members of that assembly. Heres the code: using System;...

Using Reflection to analyze Parameters and their values

I've seen older posts here on SO, about one year old which would mean that they do not really cover .NET 4 or maybe even 3.5 on this topic. So here goes. If you with reflection were to fetch parameters for the current method ParameterInfo[] methodParams = MethodInfo.GetCurrentMethod().GetParameters(); Looping through each parameter w...

How I do add this function to console app.

Hello, I have loaded an assembly called 'Mscorlib.dll' and i wanted it to list all classes within the 'Mscorlib', which it does(using reflection). Now I want to add a function whereby the user inputs a class from the assembly and it gets all the methods from that class. How would i go around doing this? Any help would be nice ...

Pros/Cons of using an assembly as a license file?

I was initially going to use a signed serialized xml file to store license details. In planning, more and more has moved into this "license file" which will allow for us to distribute a single application and control available functions via the supplied license file. The UI and printed reports are co-branded with distributors logos, so...

Is it possible to get the contents of a loaded .net assembly as a byte array or stream?

Is it possible to get the contents of a loaded .net assembly as a byte array or stream? What I'm trying to do is something similar to (of course the real scenario is much more complex, so just storing the buffer is not an option). byte[] bytes = GetTheBytes(); Assembly asm = Assembly.Load(bytes); byte[] bytes2 = GetAssemblyAsByteArray(...

invoking method declaration without reflection

I have a base class (order) with a set of sub classes (productorder, specialorder, partsorder etc). Only Some of these sub classes implement a particular interface (ITrackingCustomer) which has a single method declaration (object getcustdetails()). As part of my solution all of my orders are processed in a central place, i.e. any cru...

How do I use Convert.ChangeType to cast to a specific class?

Hello, Does anyone know how I can use Convert.ChangeType to cast from XML to a specific class? For example: My Property public Point Loc { get { return GetValue<Point2D>("Loc"); } set { SetValue<Point2D>("Loc", value); } } My XML: <Loc> <X>1.0</X> <Y>1.0</Y> </Loc> Call to convert: prop.SetValue(targetObj, ...

Linq expression to return the first overloaded method that takes 1 string parameter

What Linq expression would I use to select the 1rst overloaded method that accepts a single string parameter? For example to return the DateTime.ToString(string format) instead of the DateTime.ToString(IFormatProvider provider). t = typeof(DateTime); string[] validMethods = { "ToString" }; return t.GetMethods().Where(a => validMethods....

Setting Code Access Policy (CAS) on console application running over network

I have a console app written in .NET 2 that uses reflection to dynamically load Assembly files, instantiate an instance of that Assembly, and invoke members of it. I had this app running very smoothly on our current servers, but we're now migrating to a new host, which is a 64-bit machine running Server 2008. The code that is executed, r...

private Methods accessible

In C# or java,even though we mark methods as private ,they still can be accessed using reflection,i.e dynamically loading the class .of course we should know the method name to get hold of it.But still i was wondering how safe is the application which is meant to secure private database or bank account etc,which can still be hacked using...

ITypeDescriptorFilterService Interface usage

Can anyone provide a better example on using ITypeDescriptorFilterService interface than the MSDN ColorCycleButton ?? http://msdn.microsoft.com/en-us/library/system.componentmodel.design.itypedescriptorfilterservice.aspx ...

How I can use Java Reflection API within EJB 3 entity ?

Dear all, I do the following steps with eclipse 3.5 ,JBoss 4.2 ,EJB3 but I face class not found exception 1.compiling this code to foo.jar file package mypackage.foo; import myejbpackage.ejb.fooInterface; class foo implements fooInterface{ @override void helloWorld(){System.out.print("HelloWorld");} } Note that fooInterface ...

C#/vb.net type mismatch looking up a constructor by reflection (Integer() vs System.Int32[])

I'm passing a type name and some parameters from C# code into a navigation framework written in VB. The navigation framework looks for a constructor on the type that matches the parameters passed in using Type.GetConstructor(Types()). The constructor that I'm looking for expects an array of integers -- Integer() in vb. But it gets an ...