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 1115861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:13:05+00:00 2026-05-17T03:13:05+00:00

Here is the Context : I try to code a mapper for converting my

  • 0

Here is the Context :

I try to code a mapper for converting my DomainModel Objects to ViewModel Ojects dynamically. The problem I get, it’s when I try to invoke a method of generic class by reflection I get this error :

System.InvalidOperationException : Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.

Can someone help-me to figure out where is the fault ? It would be greatly appreciated

Here is the Code (I tried to simplified it) :

public class MapClass<SourceType, DestinationType>
{

    public string Test()
    {
        return test
    }

    public void MapClassReflection(SourceType source, ref DestinationType destination)
    {
        Type sourceType = source.GetType();
        Type destinationType = destination.GetType();

        foreach (PropertyInfo sourceProperty in sourceType.GetProperties())
        {
            string destinationPropertyName = LookupForPropertyInDestinationType(sourceProperty.Name, destinationType);

            if (destinationPropertyName != null)
            {
                PropertyInfo destinationProperty = destinationType.GetProperty(destinationPropertyName);
                if (destinationProperty.PropertyType == sourceProperty.PropertyType)
                {
                    destinationProperty.SetValue(destination, sourceProperty.GetValue(source, null), null);
                }
                else
                {

                       Type d1 = typeof(MapClass<,>);
                        Type[] typeArgs = { destinationProperty.GetType(), sourceType.GetType() };
                        Type constructed = d1.MakeGenericType(typeArgs);

                        object o = Activator.CreateInstance(constructed, null);

                        MethodInfo theMethod = d1.GetMethod("Test");

                        string toto = (string)theMethod.Invoke(o,null);

                }
                }
            }
        }


    private string LookupForPropertyInDestinationType(string sourcePropertyName, Type destinationType)
    {
        foreach (PropertyInfo property in destinationType.GetProperties())
        {
            if (property.Name == sourcePropertyName)
            {
                return sourcePropertyName;
            }
        }
        return null;
    }
}
  • 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-17T03:13:05+00:00Added an answer on May 17, 2026 at 3:13 am

    You need to call GetMethod on the constructed type constructed, not on the type definition d1.

    // ...
    
    Type d1 = typeof(MapClass<,>);
    Type[] typeArgs = { destinationProperty.GetType(), sourceType.GetType() };
    Type constructed = d1.MakeGenericType(typeArgs);
    
    object o = Activator.CreateInstance(constructed, null);
    
    MethodInfo theMethod = constructed.GetMethod("Test");
    
    string toto = (string)theMethod.Invoke(o, null);
    
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the problem with the cancel button of MFMailComposeViewController. Here is my context
here is my code in Controller var q = context.post; return View(q); in view
Here is the code I use to draw: - (void) drawSomething { CGContextRef context
How I get the Context? Am I doing something wrong here? This is my
I have try this code on DatabaseHelper.java Line Number 34 public DatabaseHelper(Context context) throws
Here is My Whole Code....... BroadcastExample.java package com.example.broadcast; > import android.app.Activity; import > android.content.Context;
I try to run this code on emulator: package andr.andr; import android.app.Activity; import android.content.Context;
I have the following code: try { res = new Utils(ubc_context).new DownloadCalendarTask().execute().get(); } catch
Here is my try: @header(Content-type: text/html; charset=utf-8); @header(Location:/index.php); @header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1 @header(Expires:
Here is my dial plan in asterisk: [main-context] exten => s,1,Gosub(subcontext,s,1) exten => s,n,NoOp(End

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.