I have a class library in which I'm using generics as below. I'm not sure if it's an improper use or not. So aside from the fact that it works and everything "depends", id like some specific critique on how this usage might fall apart. In particular In wondering about the shadowing of non generic properties with generic counterparts. Is this an accepted practice?
public interface IPickOrder
{
IPickOrderHeader Header { get; }
ERPListBase<IPickOrderLine> Lines { get; }
}
public interface IPickOrder<TPickOrderHeader, TPickOrderLine> : IPickOrder
where TPickOrderHeader : class, IPickOrderHeader
where TPickOrderLine : class, IPickOrderLine
{
new TPickOrderHeader Header { get; }
new ERPListBase<TPickOrderLine> Lines { get; }
}
public class PickOrder : IPickOrder
{
public IPickOrderHeader Header { get; protected set; }
public ERPListBase<IPickOrderLine> Lines { get; protected set; }
public PickOrder() { }
}
public class PickOrder<TPickOrderHeader, TPickOrderLine> : PickOrder, IPickOrder<TPickOrderHeader, TPickOrderLine>
where TPickOrderHeader : class, IPickOrderHeader, new()
where TPickOrderLine : class, IPickOrderLine, new()
{
public new TPickOrderHeader Header
{
get { return base.Header as TPickOrderHeader; }
protected set { base.Header = value; }
}
public new ERPListBase<TPickOrderLine> Lines { get; protected set; }
/// <summary>
///
/// </summary>
public PickOrder() : base() { }
}
IPickOrderandPickOrder? Perhaps try to write more about what are you trying to achieve with these types - how are they going to be used? – Nikola Anusev Jul 12 '12 at 8:07PickOrder<T>class, then you only use the non-genericPickOrderas a conceptual 'interface' class. In that case, makePickOrderan abstract class. – Aphelion Jul 12 '12 at 9:25