A
Ajeet
hi
I am having some difficulty in casting using generics. These are the
classes.
public interface IProvider<PROF>
where PROF : IProviderProfile
{
//Some properties/methods
}
public interface IAuthenticationProvider<PROF, TOK, CRED> :
IProvider<PROF>
where PROF : IAuthenticationProviderProfile
where TOK : IToken
where CRED : ICredential
{
//Some methods.
}
public class ADAMAuthenticationProvider :
IAuthenticationProvider<ADAMAuthenticationProviderProfile,
ADAMUserToken, UsernamePasswordCredential>
{
}
The first two are interfaces. The third class is the concrete provider.
My problem is that I cannot cast an instance of
ADAMAuthenticationProvider to IProvider<IProviderProfile>.
I should note here that ADAMAuthenticationProviderProfile derives from
IAuthenticationProviderProfile which derives from IProviderProfile.
Similarly the token and credential concrete classes are derived from
the interfaces mentioned in the constraints in the 2nd interface.
What do I have to do to be able to cast it as desired? If you can give
me links that describe the solution, I will be grateful (I tried some
googling but to no luck so far).
Regards,
Ajeet.
I am having some difficulty in casting using generics. These are the
classes.
public interface IProvider<PROF>
where PROF : IProviderProfile
{
//Some properties/methods
}
public interface IAuthenticationProvider<PROF, TOK, CRED> :
IProvider<PROF>
where PROF : IAuthenticationProviderProfile
where TOK : IToken
where CRED : ICredential
{
//Some methods.
}
public class ADAMAuthenticationProvider :
IAuthenticationProvider<ADAMAuthenticationProviderProfile,
ADAMUserToken, UsernamePasswordCredential>
{
}
The first two are interfaces. The third class is the concrete provider.
My problem is that I cannot cast an instance of
ADAMAuthenticationProvider to IProvider<IProviderProfile>.
I should note here that ADAMAuthenticationProviderProfile derives from
IAuthenticationProviderProfile which derives from IProviderProfile.
Similarly the token and credential concrete classes are derived from
the interfaces mentioned in the constraints in the 2nd interface.
What do I have to do to be able to cast it as desired? If you can give
me links that describe the solution, I will be grateful (I tried some
googling but to no luck so far).
Regards,
Ajeet.