Cast an object with Type T to Type T<System.Guid>
-
06-09-2019 - |
Question
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.
Solution
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.
OTHER TIPS
Got it working by passing CustomerBase<Guid>
as type to the function which builds the customer object
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow