Click to See Complete Forum and Search --> : [RESOLVED] LINQ, oh the joy.
jgshojr
February 9th, 2010, 08:00 AM
private IEnumerable<string> GetAllInterfaces(Type[] interfaces)
{
// Todo:
// The GetAllInterfaces method of the TypeWriter class returns a strongly
// typed IEnumerable of strings containing the Name property of each of the
// interfaces types contained in the interfaces parameter.
return from interfaces in typeof(string).GetProperties()
where interfaces.Name == typeof(string)
select interfaces;
}
VS2008, 3.5.
I took a crack at the Todo and am completely off. Guidance please?
nelo
February 9th, 2010, 08:57 AM
I would do it this way...
private IEnumerable<string> GetAllInterfaces(Type[] interfaces)
{
return from i in interfaces select i.Name;
}
I'm also new to LINQ so forgive me if it is wrong...:)
jgshojr
February 9th, 2010, 09:10 AM
I would do it this way...
private IEnumerable<string> GetAllInterfaces(Type[] interfaces)
{
return from i in interfaces select i.Name;
}
I'm also new to LINQ so forgive me if it is wrong...:)
Aha! I came up with something similar, but now I am trying to do a little more complex LINQ statement and now am REALLY stuck.
private IEnumerable<string> GetAllMembers(Type type)
{
// Todo:
// The GetAllMembers method of the TypeWriter class returns a strongly typed
// IEnumerable of concatenated strings, one for each member of the type
// parameter. Each string contains the member type and signature of the
// related member, separated by a single space. The list is sorted first by
// the member type, then by the name.
return from MemberInfo items in type.GetMembers()
orderby items.GetType
select items.GetType + " ";
// Hint:
// You can get all the members of any type by calling the GetMembers
// method of the Type class.
// Hint:
// You can obtain a member's signature by calling the ToString method
// of the MemberInfo class.
}
That's what I have so far. What am I supposed to do about the memberinfo? Typecast? (confused)
jgshojr
February 9th, 2010, 09:17 AM
Aha! I came up with something similar, but now I am trying to do a little more complex LINQ statement and now am REALLY stuck.
private IEnumerable<string> GetAllMembers(Type type)
{
// Todo:
// The GetAllMembers method of the TypeWriter class returns a strongly typed
// IEnumerable of concatenated strings, one for each member of the type
// parameter. Each string contains the member type and signature of the
// related member, separated by a single space. The list is sorted first by
// the member type, then by the name.
return from MemberInfo items in type.GetMembers()
orderby items.GetType
select items.GetType + " ";
// Hint:
// You can get all the members of any type by calling the GetMembers
// method of the Type class.
// Hint:
// You can obtain a member's signature by calling the ToString method
// of the MemberInfo class.
}
That's what I have so far. What am I supposed to do about the memberinfo? Typecast? (confused)
Nevermind, items IS MemberInfo, thus items.ToString() works. DUH.
nelo
February 9th, 2010, 09:23 AM
I would do it like this..
private IEnumerable<string> GetAllMembers(Type type)
{
from memberInfo in type.GetMembers()
order by memberInfo.GetType().ToString()
select String.Format("{0} {1}", memberInfo.GetType().ToString(), memberInfo.ToString())
}
The description could have been clearer. I'm not sure if they member signature and member name mean the same thing...
I saw your post after I'd put mine. I don't need the GetType().ToString() after all...I'm glad you figured it out.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.