.NETGURU
Reflection FindMembers not working in Beta2
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngescalate' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Jesse Liberty (VIP)
I've received no answers to two postings in FreeForAll...

I've received a bug report on my book that has me baffled. I have two
examples, the first uses GetType to get a type and then GetMembers on that
type instance; works fine. The second gets the type and then uses
FindMembers. This used to work but no longer does. I've checked the
documentation and I can not figure out what is wrong. Here is the code...

namespace Programming_CSharp
{
using System;
using System.Reflection;

public class Tester
{
public static void Main()
{
// examine a single object
Type theType &# T;ype.GetType(
"System.Reflection.Assembly");

// just members which are methods beginning with Get
MemberInfo[] mbrInfoArray theType.FindMembers(MemberTypes.Method,
BindingFlags.Default,
Type.FilterName, "Get*"); // this no longer gets any
members!

foreach (MemberInfo mbrInfo in mbrInfoArray )
{
Console.WriteLine("{0} is a {1}",
mbrInfo, mbrInfo.MemberType);
}
}
}
}
-------------------------------
Jesse Liberty
Liberty Associates, Inc.
.NET Training & Development
http://www.LibertyAssociates.com
Reply to this message...
 
    
Saurabh Nandu (VIP)
Here you go . BUG Tested :-)
You *need* to specify the proper BindingFlags for this to work!! Also
the Instance and Declared BindingFlags are most important .other are
needed too

namespace Programming_CSharp
{
using System;
using System.Reflection;

public class Tester
{
public static void Main()
{
// examine a single object
Type theType &# T;ype.GetType(
"System.Reflection.Assembly");

Console.WriteLine(theType);
// just members which are methods beginning with Get
MemberInfo[] mbrInfoArray theType.FindMembers(MemberTypes.Method,
BindingFlags.Public | BindingFlags.Static |
BindingFlags.NonPublic |BindingFlags.Instance |
BindingFlags.DeclaredOnly,
Type.FilterName, "Get*"); // this works!

foreach (MemberInfo mbrInfo in mbrInfoArray )
{
Console.WriteLine("{0} is a {1}",
mbrInfo, mbrInfo.MemberType);
}
}
}
}

Regards,
Saurabh Nandu
Web Master: http://www.MasterCSharp.com <http://www.mastercsharp.com/>
Master C#, the easy way...

-----Original Message-----
From: Jesse Liberty [mailto:Click here to reveal e-mail address]
Sent: Thursday, October 18, 2001 5:11 PM
To: aspngescalate
Subject: [aspngescalate] Reflection FindMembers not working in Beta2

I've received no answers to two postings in FreeForAll...

I've received a bug report on my book that has me baffled. I have two
examples, the first uses GetType to get a type and then GetMembers on
that type instance; works fine. The second gets the type and then uses
FindMembers. This used to work but no longer does. I've checked the
documentation and I can not figure out what is wrong. Here is the
code...
-------------------------------
Jesse Liberty
Liberty Associates, Inc.
.NET Training & Development
<http://www.libertyassociates.com/> http://www.LibertyAssociates.com
Reply to this message...
 
    
Jesse Liberty (VIP)
That fixed it perfectly, thanks!

-j

-----Original Message-----
From: Saurabh Nandu [mailto:Click here to reveal e-mail address]
Sent: Thursday, October 18, 2001 12:13 PM
To: aspngescalate
Subject: [aspngescalate] RE: Reflection FindMembers not working in Beta2

Here you go . BUG Tested J

You *need* to specify the proper BindingFlags for this to work!! Also the
Instance and Declared BindingFlags are most important .other are needed too

namespace Programming_CSharp

{

using System;

using System.Reflection;

public class Tester

{

public static void Main()

{

// examine a single object

Type theType = Type.GetType(

"System.Reflection.Assembly");

Console.WriteLine(theType);

// just members which are methods beginning with Get

MemberInfo[] mbrInfoArray
theType.FindMembers(MemberTypes.Method,

BindingFlags.Public | BindingFlags.Static |
BindingFlags.NonPublic |BindingFlags.Instance | BindingFlags.DeclaredOnly,

Type.FilterName, "Get*"); // this works!

foreach (MemberInfo mbrInfo in mbrInfoArray )

{

Console.WriteLine("{0} is a {1}",

mbrInfo, mbrInfo.MemberType);

}

}

}

}

Regards,

Saurabh Nandu

Web Master: http://www.MasterCSharp.com

Master C#, the easy way...
Reply to this message...
 
 
System.Console
System.Reflection.Assembly
System.Reflection.BindingFlags
System.Reflection.MemberInfo
System.Reflection.MemberTypes
System.Type




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification