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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:55:08+00:00 2026-06-10T00:55:08+00:00

Given 3 classes, A, and B which each have an ID property, and then

  • 0

Given 3 classes,

A, and B which each have an ID property, and then various other properties

and C, which has an ID, and the combined properties of A and B,

I want to

C.InjectFrom(A);
C.InjectFrom(B);

such that the ID from A is preserved and not overwritten by B.

Obviously in this simple case, I could just reverse the order of the two calls, but in my real world example, it is slightly more complicated where I cannot just solve the problem with ordering.

Esentially I want the second injection to ignore anything that the first injection has already handled, and this may be continued down a chain of several injections. Some of these injections may be from the same objects too

C.InjectFrom(A);
C.InjectFrom<SomeInjector>(A);
C.InjectFrom<SomeInjector2>(A);
C.InjectFrom<SomeInjector3>(A);

etc.

  • 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-06-10T00:55:08+00:00Added an answer on June 10, 2026 at 12:55 am

    here you go:

    using System;
    using System.Collections.Generic;
    using Omu.ValueInjecter;
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                var a = new { Id = 1, P1 = "p1" };
                var b = new { Id = 2, P2 = "p2" };
    
                var c = new C();
    
                var propList = new List<string>();
                c.InjectFrom(new HandlePropOnce(propList), a);
                c.InjectFrom(new HandlePropOnce(propList), b);
    
                Console.WriteLine("Id = {0} P1 = {1} P2 = {2}", c.Id, c.P1, c.P2);
            }
        }
    
        public class C
        {
            public int Id { get; set; }
    
            public string P1 { get; set; }
    
            public string P2 { get; set; }
        }
    
        public class HandlePropOnce : ConventionInjection
        {
            private readonly IList<string> handledProps;
    
            public HandlePropOnce(IList<string> handledProps)
            {
                this.handledProps = handledProps;
            }
    
            protected override bool Match(ConventionInfo c)
            {
                if (handledProps.Contains(c.SourceProp.Name)) return false;
    
                var isMatch = c.SourceProp.Name == c.TargetProp.Name && c.SourceProp.Type == c.TargetProp.Type;
    
                if (isMatch) handledProps.Add(c.SourceProp.Name);
                return isMatch;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have two classes, one class has two methods each of which
Given two model classes, Foo and Bar , I want Foo to have 3
I have produced a custom attribute which simply marks a classes property as being
I have datapoints of different classes which I want to visualize. Here is the
In C++11, we have that new syntax for initializing classes which gives us a
D2.0 classes have a __monitor class property that gives access to the class object's
I have a set of classes which are all derived from a common base
I have two classes which represent a special kind of numeric value. Let's call
I have the code below which works fine, steps through the rows pinging each
I have a form which has multiple input fields, and 3 main options. depending

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.