C# ExpressionTree和IEnumerable实现

C# ExpressionTree和IEnumerable实现,c#,linq,expression-trees,C#,Linq,Expression Trees,我有以下接收类型T的泛型类,并且必须实现IEnumerable: public class ConfigurationHelper<T>: IEnumerable<object[]> where T: BaseTestConfiguration { public T _configuration; public ConfigurationHelper(configuration) { _configuration = confi

我有以下接收类型T的泛型类,并且必须实现IEnumerable:

public class ConfigurationHelper<T>: IEnumerable<object[]> where T: BaseTestConfiguration 
{
    public T _configuration;

    public ConfigurationHelper(configuration)
    {
        _configuration = configuration;
    }

    public IEnumerator<object[]> GetEnumerator()
    {
        ParameterExpression element = Expression.Parameter(typeof(T), "element");
        //use reflection to check the property that's a generic list
        foreach (PropertyInfo property in _configuration.GetType().GetGenericArguments()[0].GetProperties())
        {
        }

       /* HERE IS MY ISSUE */
       return _configuration.Select(x=>GET LIST<OTHERTYPE> PROPERTY)
                            .SelectMany(i => new object[] { AS MANY PROPERTIES AS OTHERTYPE  })
                            .GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}
我从类型T中知道的唯一一件事是,它只有一个属性类型列表,我想返回一个IEnumerable,其中包含的项与此其他类型中的属性一样多


我想使用ExpressionTrees,但我不知道如何编写它。

如果没有BestTestConfiguration的定义,我真的做不了什么。如果你能提供,我会修改代码。根据我的理解,请检查以下代码我尝试了什么:

class Program
    {
        public static void Main(string[] args)
        {
            var helper = new ConfigurationHelper<BestTestConfiguration>(new BestTestConfiguration()
            {
                Objects = new List<string>()
                {
                    "testing 1",
                    "testing 2"
                }
            });
            var item = helper.GetEnumerator();
            Console.ReadLine();
        }


    }

    public class ConfigurationHelper<T> : IEnumerable<object[]> where T : BestTestConfiguration
    {
        public T Configuration;

        public ConfigurationHelper(T configuration)
        {
            Configuration = configuration;
        }

        public IEnumerator<object[]> GetEnumerator()
        {
            ParameterExpression element = Expression.Parameter(typeof(T), "element");
            //use reflection to check the property that's a generic list
            var items = new List<object[]>();

            foreach (PropertyInfo property in Configuration.GetType().GetProperties().Where(x => x.PropertyType.IsGenericType))
            {
                var valueOfProperty = Configuration.GetType().GetProperty(property.Name).GetValue(Configuration, null);
                items.Add(new object[] {valueOfProperty});
            }

            return items.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }

    public class BestTestConfiguration
    {
        public List<string> Objects { get; set; }
    }

现在还不清楚你想要实现什么。使用伪代码来表示它。在当前代码中,每次启动枚举时都将运行整个LINQ查询。您好,您能给我一些BaseTestConfiguration的定义吗?