Re: Complex Casting problem in Generics
- From: "Christof Nordiek" <cn@xxxxxxxxx>
- Date: Fri, 19 Jan 2007 17:37:39 +0100
"Ajeet" <asgrewal@xxxxxxxxx> schrieb im Newsbeitrag
news:1169221341.804965.164080@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You can cast to the IProvider interface. Give the IProvider interface all
Christof Nordiek wrote:
Hi Ajeet,
a solution could be, to have a non generic Interface IProvider from wich
IProvider<> derives.
Then you could cast to this Interface instead of casting to
IProvider<IProviderProfile>
public interface IProvider<PROF> : IProvider where PROF :
IProviderProfile
{
}
Would this help you?
No this would be of no use. I need to cast into that interface because
that interface contains some methods that I need to call. Doing this
would leave me with an empty interface which I will not be able to use.
methods you will need in the general case. The implement them either
implicitly or explicitly by calling the resp. method with typeparameter as
return type.
public interface IProvider
{
IProviderProfile GetProfile();
void OtherMethod();
}
public interface IProvider<PROF>: IProvider where PROF : IProviderProfile
{
PROF GetProfile();
}
public class MyProvider : IProvider<MyProfile>
{
public IProviderProfile GetProfile()
{
implementation goes here.
}
IProvider.GetProfile() { return GetProfile(); }
public OtherMethod()
{
some other impl. here
}
}
will this work for you?
"Ajeet" <asgrewal@xxxxxxxxx> schrieb im Newsbeitrag
news:1169107212.116176.113350@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.
.
- References:
- Complex Casting problem in Generics
- From: Ajeet
- Re: Complex Casting problem in Generics
- From: Christof Nordiek
- Re: Complex Casting problem in Generics
- From: Ajeet
- Complex Casting problem in Generics
- Prev by Date: Will a .txt file open ok from multiple locations if on a network?
- Next by Date: Re: C++/CLI is the way to go
- Previous by thread: Re: Complex Casting problem in Generics
- Next by thread: ADSI and C#
- Index(es):
Relevant Pages
|
Loading