参数 action<T> 给一个实例

Parameter action<T> to an instance

我想从我车内的参数中提取一个实例 class 在我的代码中我有类似的东西:

class Car
{
    static Car MakeCustomCarWithColor(string color)
    {
        return new Car(c => c.Color = color);
    }
    public Car(Action<ICustomizeCar> customization)
    {
        //here I want to access the values from customization
        // how to convert Action<ICustomizeCar>
        ICustomizeCar myCustom = ?????????????????????????????;
        // It prints the color passed from Builder class            
        Console.WriteLine(myCustom.Color);
    }

    public interface ICustomizeCar
    {
        string Color { get; set; }
    }
}

在我看来,您的 Car class 应该实现 ICustomizeCar 接口,因此您可以将此指针发送到操作。

class Car
  : ICustomizeCar
{
   ICustomizeCar::Color {get;set;} 

    static Car MakeCustomCarWithColor(string color)
    {
        return new Car(c => c.Color = color);
    }
    public Car(Action<ICustomizeCar> customization)
    {
        customization(this);
        Console.WriteLine(myCustom.Color);
    }

    public interface ICustomizeCar
    {
        string Color { get; set; }
    }
}