Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generics Problem
Message
From
09/07/2010 17:48:40
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Client-side development
Miscellaneous
Thread ID:
01472084
Message ID:
01472097
Views:
48
>>>I'm trying to write a simple mapping method:
>>>
>>>
>>>
>>>private D _ConvertUser<S, D>(S Source, D Destionation)
>>>{
>>>    D RetVal = default(D);
>>>
>>>    if (Source is aspnetUser)
>>>    {
>>>        Source = (aspnetUser)Source;
>>>
>>>        RetVal = new MyMembershipUser(Source.ProviderName, Source.UserName, Source.ProviderUserKey, Source.Email,
>>>                                        Source.PasswordQuestion, Source.Comment, Source.IsApproved, Source.IsLockedOut,
>>>                                        Source.CreationDate, Source.LastLoginDate, Source.LastActivityDate,
>>>                                        Source.LastPasswordChangedDate, Source.LastLockoutDate, User.IsDomainUser, true);
>>>
>>>    }
>>>    else
>>>    { 
>>>    }
>>>
>>>    return RetVal;
>>>}
>>>
>>>
>>>
>>>It won't compile because the "Source = (aspnetUser)Source;". I get "Cannot convert type 'S' to 'aspnetUser'".
>>>
>>>How do I do this?
>>
>>
>>
>>aspnetUser u = Source as aspnetUser;
>>
>>if (u != null)
>>{
>>    RetVal = new MyMembershipUser(u.ProviderName, u.UserName, ...
>>
>>
Cetin
>
>Thanks That worked. Now I get a similar error:
>
>
>private D _ConvertUser<S, D>(S Source, D Destionation)
>{
>    D RetVal = default(D);
>
>    if (Source is aspnetUser)
>    {
>        aspnetUser User = Source as aspnetUser;
>
>        if (User != null)
>        { 
>            WalzMembershipUser W = new WalzMembershipUser(User.ProviderName, User.UserName, User.ProviderUserKey, User.Email,
>                                            User.PasswordQuestion, User.Comment, User.IsApproved, User.IsLockedOut,
>                                            User.CreationDate, User.LastLoginDate, User.LastActivityDate,
>                                            User.LastPasswordChangedDate, User.LastLockoutDate, User.IsDomainUser, true);
>
>            return  (D)W;;
>
>        }
>    }
>    else
>    { 
>    }
>}
>
>
>
>The error is on the return statement, "Cannot convert type 'WalzUtility.Security.WalzMembershipUser' to 'D'"

D d = W as D;

D should be a castable type.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform