This seems to compile, no idea why though :/
var fields = GetFields()
.Concat(GetProperties().Cast<MemberInfo>())
.Concat(GetMethods().Cast<MemberInfo>())
.Concat(GetExtensions());
If anybody could explain I'd be happy.
Question
In its simple form, I have (in a Console app):
// They don't return null, but just for simplicity's sake
PropertyInfo[] GetProperties() { return null; }
FieldInfo[] GetFields() { return null; }
MethodInfo[] GetMethods() { return null; }
MethodInfo[] GetExtensions() { return null; }
And then somewhere else:
var fields = GetFields()
.Concat<MemberInfo>(GetProperties())
.Concat<MemberInfo>(GetMethods().Where(m => !m.IsSpecialName))
.Concat<MemberInfo>(GetExtensions());
This works (compiles fine). However in my actual case which is similar, it doesn't compile (I'm using Mono here - not in a Console app):
fields = target.GetFields(returnType, flags)
.Concat<MemberInfo>(target.GetProperties(returnType, flags))
.Concat<MemberInfo>(target.GetMethods(returnType, Type.EmptyTypes, flags, false)
.Where(m => !m.IsSpecialName))
.Concat<MemberInfo>(extensionMethods)
.Select(m => m.Name)
.ToArray();
Errors:
Error 'System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>' does not contain a definition for 'Concat' and the best extension method overload 'System.Linq.Enumerable.Concat<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments
Error Argument 2: cannot convert from 'System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>' to 'System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>'
However, if I comment the extension methods, and do a ToArray
on the Where
clause, it doesn't complain (no compile errors) which I think doesn't make sense:
fields = target.GetFields(returnType, flags)
.Concat<MemberInfo>(target.GetProperties(returnType, flags))
.Concat<MemberInfo>(target.GetMethods(returnType, Type.EmptyTypes, flags, false)
.Where(m => !m.IsSpecialName).ToArray())
//.Concat<MemberInfo>(extensionMethods)
.Select(m => m.Name)
.ToArray();
If I uncomment it starts complaining (gives the same error) again.
Any ideas what's going on?
EDIT: This really seems to be a Mono thing. I copy-pasted the same sample code from the console app (the code posted first) to my actual environment, I got the same errors.
EDIT: Some details about the runtime:
MonoDevelop-Unity
Version 4.0.1
Installation UUID: dc9fa750-d2af-42c8-9831-b510b08f6d28
Runtime:
Microsoft .NET 4.0.30319.18408
GTK 2.24.13
GTK# (2.12.0.0)
Solution
This seems to compile, no idea why though :/
var fields = GetFields()
.Concat(GetProperties().Cast<MemberInfo>())
.Concat(GetMethods().Cast<MemberInfo>())
.Concat(GetExtensions());
If anybody could explain I'd be happy.