Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新此扩展以处理FlatLoopValueInjection_C#_Generics_Valueinjecter - Fatal编程技术网

C# 更新此扩展以处理FlatLoopValueInjection

C# 更新此扩展以处理FlatLoopValueInjection,c#,generics,valueinjecter,C#,Generics,Valueinjecter,我在stackoverflow上发现了这段代码,但我注意到它不能处理FlatLoopValueInjection,我想让它处理这段代码,但我不知道如何处理 public static ICollection<TTo> InjectFrom<TFrom, TTo>(this ICollection<TTo> to, IEnumerable<TFrom> from) where TTo : new() { for

我在stackoverflow上发现了这段代码,但我注意到它不能处理FlatLoopValueInjection,我想让它处理这段代码,但我不知道如何处理

public static ICollection<TTo> InjectFrom<TFrom, TTo>(this ICollection<TTo> to, IEnumerable<TFrom> from) where TTo : new()
        {
            foreach (var source in from)
            {
                var target = new TTo();
                target.InjectFrom(source);
                to.Add(target);
            }
            return to;
        }
publicstaticicollection-InjectFrom(此ICollection-to,IEnumerable-from),其中TTo:new()
{
foreach(from中的变量源)
{
var target=new TTo();
目标。从(源)注入;
添加(目标);
}
返回;
}

我知道这需要更新
target.InjectFrom(源代码)但我不确定如果它可以接受任何东西(FlatLoopValueInjection、UnflatLoopValueInjection等)并使用它会有什么好处,这不是我想要的Omu。添加InjectFrom只会使使用它变得很困难。我希望它仍然是通用的,但句柄(FlatLoopValueInjection、UnflatLoopValueInjection等)FlatLoopValueInjection与InjectFrom+扁平化的作用相同