Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 289893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:56:53+00:00 2026-05-12T05:56:53+00:00

Platform: C# 2.0 WinForms I have a factory class that provides an instantiation of

  • 0

Platform: C# 2.0 WinForms

I have a factory class that provides an instantiation of a particular data mapper depending on the type that I send it, the code is as such:

public static IDataMapper<T> GetMapper<T>() where T: IDto
{
    Type mapperType = MapperLocator.GetMapper(typeof(T));

    return (IDataMapper<T>)mapperType.Assembly.CreateInstance(mapperType.FullName);
}

I am using DynamicProxy2 to intercept method calls to my DTO objects. In my intercept method I am trying to call the above factory using the type from Invocation.TargetType. However this comes back with the exception:

The type or namespace name ‘invocation’ could not be found.

Obviously this is because any calls to a generic method need to know the type explicitly from what I understand at compile time. Obviously I can’t do that in this case and I definitely am not going to do a switch statement across all of my DTO objects.

So, can you guys suggest a strategy or point out what I am doing wrong? I am trying to make this as generic as possible so that it could fit across all of my objects and any new ones as well as code portability to other projects.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:56:54+00:00Added an answer on May 12, 2026 at 5:56 am

    I’m not familiar enough with DTO to know whether or not there’s enough information here for a full solution. That said, another answer is mostly correct; the C# compiler needs type information at compile time.

    There is, however, a way around this: reflection. System.Reflection (particularly MethodInfo in your case I think) will allow you to write a fully generic solution.

    If I’ve understood the question correctly, what you’d do is get the MethodInfo for that factory function, substitute in the type with MakeGenericMethod, and then Invoke that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UserControl that is part of a Class library. I reference this
I have an app that I've written in C#/WinForms ( my little app ).
I have C# code I want to use in both a WinForms app and
I have a WinForms application that needs to behave in specific ways (specifically shell
We have a WinForms app that runs fine on x86, but has many third-party
Good day, IDE Visual Studio 2010 .NET 3.5 Platform WinForms The SO question difference
Platform - iOS. Language - Object c, OpenGL. I have to put 2 UIViews
Is there a platform-independent method to embed file data into a c++ program? For
Imagine a cross-platform library that has to create its own windows without relying on
The Situation: I have a software project written in .NET 4.0 with a WinForms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.