0

I'm having issues in understanding how to typecast an object into its parent that was using a generic.

I get the error

 Cannot convert type 'TeamTrackerExposure.TTFileUploadDict' to 'JadeSoftware.Joob.MemberKeyDictionary<JadeSoftware.Joob.JoobDictionaryKey,JadeSoftware.Joob.JoobObject>'

in the constructor

 public AC_TTFileUploadDict(DbJoobContext proc, TTFileUploadDict obj, TTPage page)
        : base(proc, (MemberKeyDictionary<JoobDictionaryKey,JoobObject >) obj, page)
    {

TTFileUploadDict has the following class definition

 public partial class TTFileUploadDict : MemberKeyDictionary<TTFileUploadDictKey, TTFileUpload>
{
 .....
 }

TTFileUploadDictKey's class definition is

 public class TTFileUploadDictKey : JadeSoftware.Joob.JoobDictionaryKey
{
 .....
 }

and lastly TTFileUpload's

 public partial class TTFileUpload : JoobObject
{
 .....
 }

I'm struggling to figure out how to typecast to a generic parent class, any assistance on how to do this would be highly appreciated!!

4

1 に答える 1

1

それを行う唯一の方法は、共変のジェネリック インターフェイスを使用することです (ただし、基本クラスではなく、インターフェイスにのみキャストできます)。C# Generics Interface Covarianceまたはhttp://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspxをご覧ください。

于 2013-08-27T04:54:39.857 に答える