'T' parametresi olarak kullanmak için bir referans tipi olmalıdır, generiklerin daha derinlerine iniyorum ve şimdi bir yardıma ihtiyacım var. Konu başlığında gösterildiği gibi 'Türetilmiş' sınıfında bir derleme hatası alıyorum. Buna benzer birçok başka yazı görüyorum ama ilişkiyi göremiyorum. Birisi bunu nasıl çözeceğimi söyleyebilir mi?Tip, jenerik tip veya metod
using System;
using System.Collections.Generic;
namespace Example
{
public class ViewContext
{
ViewContext() { }
}
public interface IModel
{
}
public interface IView<T> where T : IModel
{
ViewContext ViewContext { get; set; }
}
public class SomeModel : IModel
{
public SomeModel() { }
public int ID { get; set; }
}
public class Base<T> where T : IModel
{
public Base(IView<T> view)
{
}
}
public class Derived<SomeModel> : Base<SomeModel> where SomeModel : IModel
{
public Derived(IView<SomeModel> view)
: base(view)
{
SomeModel m = (SomeModel)Activator.CreateInstance(typeof(SomeModel));
Service<SomeModel> s = new Service<SomeModel>();
s.Work(m);
}
}
public class Service<SomeModel> where SomeModel : IModel
{
public Service()
{
}
public void Work(SomeModel m)
{
}
}
}
Herhangi bir derleme hatası bulamadım –
Bu kod bu hatayı göstermiyor. Temiz bir şekilde derler. –