Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generics Problem
Message
 
To
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:
01472104
Views:
56
>>>>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


I still can't get it right:
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);

        D d = W as D;
        return d; 
    }
}
Now I'm getting "The type parameter 'D' cannot be used with the 'as' operator because it does not have
a class type constraint nor a 'class' constraint"
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform