You must Sign In to post a response.
  • Category: .NET

    Swapping and mapping of 2 class members dynamically


    I have 2 classes, class A class B.
    Class A is having 2 members say int a and int b
    Class B is having 1 member say int y

    now i want some logic so that i can save mapping of members of both classes like int a of class A will be mapped to int y of class B.
    by calling that logic method i can swap the values of these members dynamically (NO HARD CODING REQUIRED)

    Please provide code for this

  • #765676
    without going for a logic, it is better to use some ready made classes like AutoMapper, an open source and free mapping library which allows to map one type into another, based on conventions (i.e. map public properties with the same names and same/derived/convertible types, along with many other smart ones). Very easy to use, will let you achieve something like this.
    see below link

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765746
    you can use reference variables to map variables of different methods by declaring the function parameters as ref variables.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • Sign In to post your comments