Doesn't make it impossible, you'd just have to explicitly implement GetType, etc. on the interface instance, right?

By on 4/13/2009 7:00 PM ()

Doesn't make it impossible, you'd just have to explicitly implement GetType, etc. on the interface instance, right?

Don't think so - the point is that implementing the interface puts an attribute on the object.GetType() etc methods. Explicit implementation adds new and different methods to the type. So the attribute has no effect (i.e. it does not hide the GetType method from intellisense, in the example). It's a nice trick to abstract applying some attributes to a number of methods, by just implementing an interface.Furthermore, GetType cannot be overridden since it's not virtual, so without this trick I see no way of even applying an attribute to object.GetType.

By on 4/14/2009 1:27 AM ()

You're right -- I don't know what I was thinking.

Another case is being able to override part of an interface. Like, suppose a base class provides an interface implementation for IBigInterface. Then a subclass implements an interface that implements IBigInterface2 which adds a single member. You have to duplicate all the definitions, and if the base class doesn't have implicit implementations, you have to re-implement everything too. (AFAIK)

By on 4/16/2009 11:35 PM ()

One caveat on <i>EditorBrowsableAttribute<i> - it only works on assembly references as documented <A href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105485&wa=wsignin1.0">here</A>. Should you have the source project in Visual Studio (rather than an assembly reference) the attribute will be ignored. This makes the attribute significantly less useful for anything other than 3rd-party libraries. regards, Danny

By on 4/17/2009 5:56 AM ()

<quote>One caveat on <i>EditorBrowsableAttribute<i> - it only works on assembly references as documented <A href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105485&wa=wsignin1.0">here</A>. Should you have the source project in Visual Studio (rather than an assembly reference) the attribute will be ignored. </quote>I think they mean it doesn't work only in the same project. Works for me if I refer to an F# project (with the attribute) from a C# project. This could also be because under the hood all inter-language references are handled as assembly references, haven't tried with two C# projects.

By on 4/17/2009 8:15 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper