C # - How to convert Lazy <List <T>> to Lazy <List <U>>?
I have Lazy<List<T>>where T is a class that contains a huge string and metadata about files. Let us call them property HugeStringand propertyMetadata
I have this class U, which has the same property HugeString, by the way. I need to convert Lazy<List<T>>to Lazy<List<U>>without loading everything.
Is it possible?
Here I create my list, and inside this method I get information about the file and the file itself:
entity.VersionedItems =
new Lazy<List<VersionedItemEntity>>(
() => VersionedItemEntity.GetFromTFSChanges(entity,chng.Changes));
This is what I want to do (commented)
ChangesetList.Add(
new HistoryLogEntryModel()
{
Revision = changeset.Changeset.ToString(),
Author = changeset.User,
Date = changeset.Date.ToString("dd/MM/yyyy"),
Message = changeset.Comment,
//VersionedItems = changeset.VersionedItems
}
But HistoryLogEntryModel has a different version of VersionedItems. And I need to convert some variables. If I converted one thing to another, it would load everything, and that would be unnecessary and slow.
Is this the right approach? How else can I achieve this?
adv.
~
+5
2
- :
public static class ExtensionMethods
{
public static Lazy<U> Convert<T,U>(this Lazy<T> source, Func<Lazy<T>, Lazy<U>> convert)
{
return convert(source);
}
}
Lazy<List<int>> source = new Lazy<List<int>>();
Lazy<List<string>> converted = source.Convert(x =>
{
return new Lazy<List<string>>()
{
Items = x.Items.ConvertAll<string>(i => i.ToString())
};
});
, , .
0