не получается реализовать мост с помощью дженериков
От: Visor2004  
Дата: 12.01.12 10:04
Оценка:
Дано: вот такая иерархия наследования

  public interface INativeResourceHolder [ +T ] where T : INativeResource
  {
    Resource : T
    {
      get;
      set;
    }
  }

  public class NativeResourceHolder [ T ] : PresentationObject, INativeResourceHolder [ T ] where T : INativeResource
  {
    protected Resource : T implements INativeResourceHolder [ T ].Resource
    {
      get;
      private set;
    }
  }

  public interface INativeBrush : INativeResource
  {
    Opacity : float
    {
      get;
      set;
    }
    
    Transform : Matrix
    {
      get;
      set;
    }
  }
  
  public interface INativeSolidColorBrush : INativeBrush
  {
    Color : Color
    {
      get;
      set;
    }
  }

  public abstract class Brush [ T ] : NativeResourceHolder [ T ] where T : INativeBrush
  {
    private mutable opacity : float;
    private mutable transform : Matrix;

    public Opacity : float
    {
      get { opacity }
      set
      {
        opacity = value;
        when ( Resource : object != null )
          Resource.Opacity = value;
      }
    }

    public Transform : Matrix
    {
      get { transform }
      set
      {
        transform = value;
        when ( Resource : object != null )
          Resource.Transform = value;
      }
    }
  }

  public class SolidColorBrush : Brush [ INativeSolidColorBrush ]
  {
    private mutable color : Color;

    public this ( color : Color )
    {
      this.color = color;
    }

    public Color : Color
    {
      get { color }
      set
      {
        color = value;
        when ( Resource != null )
          Resource.Color = value;
      }
    }
  }

  public class RoundedRectangle : Visual
  {
    public Background : Brush [ INativeBrush ]
    {
      get;
      set;
    }
  }


Хочется сделать так:

    def root = RoundedRectangle ( );
    root.Background = SolidColorBrush ( Colors.Aqua );


На что получаю ошибку:

expected Workspace.Presentation.Brush[Workspace.Presentation.INativeBrush], got Workspace.Presentation.SolidColorBrush in assigned value: the types Workspace.Presentation.INativeSolidColorBrush and Workspace.Presentation.INativeBrush are not compatible [simple unify]


Чо делать?
Помните!!! ваш говнокод кому-то предстоит разгребать.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.