Is there a way to implement this pattern in a generic way?
A dispatcher object and a bunch of worker objects all derive from the same interface.
Any method call into the dispatcher object needs to be dispatched (forwarded) to one of the worker objects (with all the arguments).
Each method would need to discover it's own name, find the...
Ultimately, I'm looking forward to a reflection based approach to create a delegate wrapper for a method B(C(),D()) - to some what like (c,d)=>B(()=>c(),()=>d())
First question - Given that you've a Methodinfo, what are the considerations to create a delegate type (via reflection) which corresponds to that method signature?
Do you hav...
my problem is that TypeDescriptor doesn't return members from inherited interfaces, is this how it is supposed to be working ? or is it a bug ?
[TestFixture]
public class DescriptorTests
{
[Test]
public void Test()
{
// count = 1
...
I'm trying to retrieve MethodInfo for Where method of Enumerable type:
typeof (Enumerable).GetMethod("Where", new Type[] { typeof(IEnumerable<>), typeof(Func<,>) })
but get null. What am I doing wrong?
...
I have some code (which works fine) that looks something like this:
int integer = 42;
decimal? castTo = integer;
Then I wanted to do something similar with reflection, with some code that looks like this:
object value = source; // source was an int originally
var parameters = new object[1];
...
parameters[...
Everyone projects once in a while:
var c = dc.Products.Select( p => new {p.id, p.name});
// results in c having properties of .id and .name
What if I want to refactor that in to a method. How would I pass the Select parameter?
var c = myFunction( p => new {p.id, p.name});
Product myFunction( ??? myLambda)
{
var c = dc.Product...
If I do something like this:
var a = new List<something>();
var b = new something();
a.Add(b);
var c = a[0].GetType();
C holds the type I want (which is "something"). How could you get the type of "something" without creating the list?
...
I am using AutoMapper where it has:
.ForMember( dest => dest.id, opt => opt.MapFrom(src => src.id))
Using the far right expression src => src.id, if I have a string variable with the property's name, how would I choose the property by it?
I tried this:
src => propertyName
Then had to laugh when the value was "id".
...
I have a well known POCO class of Customer to return from my method. However, I only populate properties specified by an ever changing Expression p => new {p.id, p.name} for example, as a parameter to the method.
Somehow I need to copy all matching fields between these two objects.
var returnObject = IList<Customer>();
var partialField...
Hi All,
I'm trying to automatically register all reports in a unity container.
All reports implement IReport and also have a Report() attribute which defines the title, description and unique key (so I can read these without instantiating a concrete class).
So...
I get the report types like this
Public Shared Function GetClassesWhic...
I have a method where I am passing in two object, which have the same property names, and I'm using Reflection to get the values from one object and set the values on the other. My problem is when I come across a property that is a collection, the original is EntityCollection and the one getting set is ObservableCollection, and I'm obvio...
This code returns a variable set of fields and I want to return a strongly typed <E>:
public IList<E> Get(Expression<Func<E, object>> selectLambda == null)
{
if (selectLambda == null)
selectLambda = p => p;
var partialSet = DC.CreateQuery<E>("[" + typeof(E).Name + "]");
foreach ( var record in partialSet)
{
...
Hello,
I'm working with .net Reflector to view some .net Compact Framework .dlls and I'm getting an "Object reference not set to an instance of an object" error for one of them. I downloaded the trial version of 9Rays.Spices.Net and it loaded the .dll just fine. The only problem is that I'm getting only every other method.
I was able...
Is it possible to use Reflection is C# to fire an event? Say I have a situation like this:
public delegate void SomeEventHandler(object sender, BenArgs e);
class EventHub
{
public event SomeEventHandler SOME_EVENT;
public void fireEvent(String eventName)
{
SomeEventHandler evt = (SomeEventHandler) Delegate.CreateDe...
In a nutshell, I'm trying to do the inverse of "classObject.getDeclaredClasses()".
I have a method that receives an object of type Class<? extends Object>. I want to figure out whether it is an inner class, and if it is, I want to access the surrounding class' object instance.
Is there a smart API for this, or am I forced to do some st...
Considering the following Scala snippet:
case class Foo(v1: String, v2: Int, v3: Any)
def inspect(p: Product) =
(0 until p.productArity).foreach(i => println(p.productElement(i)))
inspect(Foo("Moin", 77, null))
Does the invocation of inspect() here means that reflection is used (in whatever way)?
I'd like to somehow be able to ac...
Consider the following case:
Public Interface IHasDateUpdated
Property DateUpdated As DateTime
End Interface
Public Class MyClass
Implements IHasDateUpdated
Public Property MyDateUpdated As DateTime Implements IHasDateUpdated.DateUpdated
End Class
Now, assuming I was referencing an instance of MyClass as an IHasDateUp...
I have a CommonMaster page that then contains a ConfigurableReportsMaster page. I then have an AutitLog.aspx page. Now, on that .aspx page I have multiple UserControls. Some of these UserControls are inheriting from an ISQLFilter interface, but not all.
While on the .aspx, in a RunReport event (that currently successfully fires) I ...
Typically I could copy values between two java beans , which have identical property names, using beanutils with java reflection e.g. PropertyUtils.setProperty(....)
In protobuf Message, we use the message builder class to set the value. This works but I would rather use reflection to automatically copy properties from the bean to the...
Hi Guys,
I am actually looking at getting the method, whose name is stored in the string "methodName", from the Class "CC1" using Java Reflection.
Method actualMethod= CC1.getMethod(methodName, parameterTypes);
This is the syntax. The problem is the method takes no parameter. How do I represent that in the parameterTypes ?
where p...