cast interface from generic interface to same interface but with base types

时间:2016-02-12 22:06:19

标签: c# generics interface

i have following code :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView"
    android:fillViewport="true"

    >

<RelativeLayout
    android:layout_weight="1"
    android:id="@+id/relativla"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    >
    <Button
        android:layout_width="30dp"
        android:layout_height="30dp"

        android:background="@drawable/hamburger"
        android:id="@+id/navi"
        android:padding="10dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:background="@drawable/dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/descrpitiondietplan"
        android:id="@+id/textView5"
        android:layout_below="@+id/imageView"
         />


</RelativeLayout>

</ScrollView>

and i try to add following :

private List<DataPackageHandler<ISourceDataEntity<T, TD>, IValueObject<TD>, T, TD>> Handlers { get; }

but var handler is null

what am i doing wrong ?

thanks a lot for help

UPDATE

i created a

public void CreateNewDataPackageHandler<TI, TO>(IMapper<TI, TO, T, TD> mapping, IDataService<TO, TD> dataService, TD id)
            where TI : ISourceDataEntity<T, TD> 
            where TO : IValueObject<TD>
        {
            var handler = DataPackageHandler<TI, TO, T, TD>.CreateNewDataPackageHandler(mapping, dataService, id) as DataPackageHandler<ISourceDataEntity<T, TD>, IValueObject<TD>, T, TD>;
            Handlers.Add(handler);
        }

so my List is now defined as

public abstract class AHandler<T, TD>

which is capable of holding also a object of type

private List<AHandler<T, TD>> Handlers { get; }

thanks a lot for help !

0 个答案:

没有答案