C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Reflection and explicitly implemented interfaces


Posted Date: 04 Nov 2009    Resource Type: Articles    Category: .NET Framework
Author: HariMember Level: Gold    
Rating: 1 out of 5Points: 10



I have an interface ISomeInterface that does something.


public interface ISomeInterface
{
void DoSomething();
}

And a class SomeClass that implements ISomeInterface explicitly.

public class SomeClass : ISomeInterface
{
#region ISomeInterface Members

void ISomeInterface.DoSomething()
{
throw new NotImplementedException();
}

#endregion
}

My goal was to reflect the members of SomeClass. So i went ahead and wrote this common code :


Type type = typeof(SomeClass);
MethodInfo[] methodInfo = type.GetMethods();



Hold on where's my interface method? Taking a second look at my SomeClass i found that explicitly implemented member was private to SomeClass. Ok So this brings BindingFlags into play. BindingFlags control the binding and specify the way search is conducted for types and members in reflection. Luckly GOOGLE did the trick again.


Type type = typeof(SomeClass);
MethodInfo[] methodInfo = type.GetMethods(BindingFlags.NonPublic
BindingFlags.Instance);



To my surprise methodInfo had only those methods provided by System.Object.


For more details, visit http://thoughtorientedarchitecture.blogspot.com/2009/11/reflection-and-explicitly-implemented.html



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Reflection  .  Explicit interface  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Code Access Security 2.0
Previous Resource: Cloud Computing through .NET
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use