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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:47:54+00:00 2026-05-26T15:47:54+00:00

I have an application which exports several objects of the same Class, and plugins

  • 0

I have an application which exports several objects of the same Class, and plugins which import only specific ones. for example

public class Part
{
  string name;
  public Part(string nm)
  {
    name = nm;
  }
}

public class Car //Exports ALL Parts of the Car
{
  [Export(typeof(Part))]
  public Part steeringWheel = new Part("SteeringWheel");

  [Export(typeof(Part))]
  public Part engine = new Part("Engine");

  [Export(typeof(Part))]
  public Part brakes = new Part("Brakes");
}

public class SystemMonitorPlugin //Imports only SOME Parts from the Car
{
  [Import(typeof(Part))]
 public Part engine;

  [Import(typeof(Part))]
  public Part brakes;
}

Could someone explain how I can achieve this behavior?

  • 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-26T15:47:54+00:00Added an answer on May 26, 2026 at 3:47 pm

    You need a contract(interface) and a metadata contract (interface):

    public interface ICarPart{
        int SomeMethodFromInterface();
    }
    
    public interface ICarPartMetadata{
        string /*attention to this!!!*/ NameCarPart { get; } /* Only for read. */
    }
    

    Then you export your parts:

    [Export(typeof (ICarPart))]
    [ExportMetadata("NameCarPart","SteeringWheel")] /* is string!! */
    
    public class SteeringWheel : ICarPart {
    
        public int SomeMethodFromInterface(){
            ... //your stuff
        }
    }
    [Export(typeof (ICarPart))]
    [ExportMetadata("NameCarPart","Engine")] /* is string!! */
    
    public class Engine : ICarPart {
    
        public int SomeMethodFromInterface(){
            //Each method have diferent behavior in each part.
            ... //your stuff
        }
    }
    [Export(typeof (ICarPart))]
    [ExportMetadata("NameCarPart","Brakes")] /* is string!! */
    
    public class Brakes : ICarPart {
    
        public int SomeMethodFromInterface(){
            //Each method have diferent behavior in each part.
            ... //your stuff
        }
    }
    

    Then you can import with ImportMany and Lazy:

        [ImportMany()]
        IEnumerable<Lazy<ICarPart, ICarPartMetadata>> carParts = null;
        public void Importing(){
        ...
        ...
    
        foreach (Lazy<ICarPart,ICarPartMetadata> item in carParts){
            switch (item.Metadata.ICarPartMetadata.ToString()){
                case "SteeringWheel":
                    item.Value.SomeMethodFromInterface();
                break;
                case "Engine":
                    item.Value.SomeMethodFromInterface();
                break;
                case "Brakes":
                    item.Value.SomeMethodFromInterface();
                break;
                default:
                ...
                break;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a third-party, closed source application that exports a COM interface, which I
I have application which exports data in csv file which is stored in Document's
I have a RAM of 2 GB. We have a application which performs Export/Import
I have application with several datagrids and export to excel command, which gets focused
I have an unmanaged C++ DLL which merely exports a single class (not COM...it's
I have a Silverlight 4 application which talks to a 'manager' class, which talks
I have application which needs to use a dll (also written by me) which
I have an application which really should be installed, but does work fine when
I have an application which extracts data from an XML file using XPath. If
We have an application which needs to use Direct3D. Specifically, it needs at least

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.