简体   繁体   中英

Cast an object with Type T to Type T<System.Guid>

I inherited a project with a Windows mobile part. To make a long story short, my problem is this:

[DBPropertyUpdate("CustomerId")]
[DBPropertyRetrieve("CustomerId")]
public CustomerBase<T> Customer
{
    get { return _customer; }
    set { _customer = SetProperty(_customer, value); }
}

throws an exception.

In a watch window I have the following:

> NAME         VALUE                           TYPE

_customer   {Pss.Common.Mia.Customer}   Pss.Common.Mia.CustomerBase<System.Guid> {Pss.Common.Mia.Customer}
(Pss.Common.Mia.CustomerBase<System.Guid>)_customer Cannot convert type 'Pss.Common.Mia.CustomerBase<T>' to 'Pss.Common.Mia.CustomerBase<System.Guid>'  

I am not familiar with this code, but was hoping there would be some easy way to convert 'Pss.Common.Mia.CustomerBase<T>' to 'Pss.Common.Mia.CustomerBase<System.Guid>' The seconcd Watch entry was my attemp, which as you can see fails.

The variable _customer typed as CustomerBase<Guid> cannot possibly be cast to CustomerBase<T> since T is not known. You must also type _customer as CustomerBase<T> for this to work.

通过将CustomerBase<Guid>作为类型传递给构建客户对象的函数,使其正常工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM