Exception Handler

Related Assemblies should be referenced

If you get an error like: Exp.Vehicle, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null should be referenced, I got a solution here, if there's other better and efficient solution, please leave notes;).
For example, there're three assemblies:

  1. Class library Exp.Vehicle, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null with one class:
public abstract class Vehicle {}
  1. Class library Exp.Porsche, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null reference to Exp.Vehicle, with one class:
public class Porsche : Vehicle {} 
  1. Windows Application Exp.VehicleShop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null reference to Exp.Porsche, with one class:
public class VehicleShop {}

Now in the class VehicleShop, we will need a method to create an instance of Porsche.
So as usual we write like:

public object CreateCar()
{
    return new Porsche(); //Here we get an error: `Exp.Vehicle, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null` should be referenced.
} 

In this situation, if we won't able to modify VehicleShop's references

Maybe VehicleShop is a host application that creates vehicles via System.Reflection.

My solution is:

  • In assembly Exp.Porsche, we need an additional class that do the specific work, so that VehicleShop can do the creation by calling it:
    In PorscheInitializer.cs:
public class PorscheInitializer
{
    public object GetInstance()
    {
        return new Porsche();
    }
}

In VehicleShop.cs:

public object CreateCar()
{
    return new PorscheInitializer().GetInstance();
} 

你可能感兴趣的:(Exception Handler)