How it started?
I wanted to add two columns, that are not in business objec collection into radGridView. Specifically NewUrl anad NewIdOnFilehost. 🙂
So what i tried to do?
I put this into grid
radGridViewReuploadStatus.ItemsSource = FileHostings.Filesonic.getdAllDeletedLinks();
Then i added them new columns
<telerik:GridViewColumn Header="New F.H.Id" UniqueName="NewFilehostId" Width="*"></telerik:GridViewColumn>
<telerik:GridViewColumn Header="New URL" UniqueName="NewUrl" Width="*"></telerik:GridViewColumn>
So what is problem?
radGridViewReuploadStatus.Rows does not exists.
I don’t know why they did not added it to wpf radGridView, it is in its aspx version. I was able to get rows using getChildsOfType, but this is obviously not ideal way.
What i did next?
class dlExtended : DownloadLink {
public string NewUrl { get; set; }
public string NewIdOnFilehost { get; set; }
}
Finally the PROBLEM – what basic i don’t understand
How do i make dlExtended from DownloadLink? (i know it is wrong name convention, it is just for example 🙂 )
And how do i make list of dlExtended from collection of DownloadLink? There must be better way then using foreach!
Now i’m probably doing it wrong
So now i should do constructor and set EACH property of dlExneded according to one passed in passed DownloadLink?!
Well maybe it is doable by reflection LIKE this
public DownloadLinkExtended(DownloadLink origDl){
PropertyInfo[] myObjectProperties = origDl.GetType().GetProperties(); //BindingFlags.Public | BindingFlags.NonPublic
foreach (PropertyInfo pi in myObjectProperties)
{
if (pi.GetValue(origDl, null) != null)
{
pi.SetValue(this, pi.GetValue(origDl, null), null);
}
}
}
Well this is stupid. So what i don’t get about extending the class and adding new properties to it?
I know that EF4 classes are partial and i can add properties to them simply via partial class, but i want these only for the grid and not anywhere else.
My “Shallow” object copier is very similar to yours, but the null test is subtly different. It also has a handy extension method wrapper – so it will need to be in a static class.
However, I also have a deep copier, but this only works with serializable objects, so look into the code generation you use from the EDMX, I don’t think it will work with the EF classes directly, but does with the POCO generated classes.