explicit-interface

Why to Use Explicit Interface Implementation To Invoke a Protected Method?

天大地大妈咪最大 提交于 2019-11-30 12:42:01
When browsing ASP.NET MVC source code in codeplex , I found it is common to have a class explicitly implementing interface. The explicitly implemented method/property then invoke another "protected virtual" method/property with same name. For example, public class MvcHandler : IHttpHandler, IRequiresSessionState { protected virtual bool IsReusable { get { return false; } } bool IHttpHandler.IsReusable { get { return IsReusable; } } } I'm now sure what's the benefit of this kind of programming. For me, I prefer to just implicitly implement the interface IHttpHandler. I guess the author just don

F# and interface-implemented members

一曲冷凌霜 提交于 2019-11-30 08:41:19
I have a vexing error. type Animal = abstract member Name : string type Dog (name : string) = interface Animal with member this.Name : string = name let pluto = new Dog("Pluto") let name = pluto.Name The last line, specifically "Name" generates a compiler error saying that "the field, constructor or member 'Name' is not defined". The workaround I've used is to write let name = (pluto :> Animal).Name However this is very annoying and creates a lot of visual noise. Is there something one can do in F# to just be able to resolve Name without telling the compiler explicitly that Name is a derived

Why does calling an explicit interface implementation on a value type cause it to be boxed?

笑着哭i 提交于 2019-11-30 03:29:43
My question is somewhat related to this one: How does a generic constraint prevent boxing of a value type with an implicitly implemented interface? , but different because it shouldn't need a constraint to do this because it's not generic at all. I have the code interface I { void F(); } struct C : I { void I.F() {} } static class P { static void Main() { C x; ((I)x).F(); } } The main method compiles to this: IL_0000: ldloc.0 IL_0001: box C IL_0006: callvirt instance void I::F() IL_000b: ret Why doesn't it compile to this? IL_0000: ldloca.s V_0 IL_0002: call instance void C::I.F() IL_0007: ret

F# and interface-implemented members

和自甴很熟 提交于 2019-11-29 12:15:33
问题 I have a vexing error. type Animal = abstract member Name : string type Dog (name : string) = interface Animal with member this.Name : string = name let pluto = new Dog("Pluto") let name = pluto.Name The last line, specifically "Name" generates a compiler error saying that "the field, constructor or member 'Name' is not defined". The workaround I've used is to write let name = (pluto :> Animal).Name However this is very annoying and creates a lot of visual noise. Is there something one can do

Fortran - explicit interface

删除回忆录丶 提交于 2019-11-29 10:05:06
I'm very new to Fortran, and for my research I need to get a monster of a model running, so I am learning as I am going along. So I'm sorry if I ask a "stupid" question. I'm trying to compile (Mac OSX, from the command line) and I've already managed to solve a few things, but now I've come across something I am not sure how to fix. I think I get the idea behind the error, but again, not sure how to fix. The model is huge, so I will only post the code sections that I think are relevant (though I could be wrong). I have a file with several subroutines, that starts with: !========================

Why does calling an explicit interface implementation on a value type cause it to be boxed?

╄→гoц情女王★ 提交于 2019-11-29 00:40:32
问题 My question is somewhat related to this one: How does a generic constraint prevent boxing of a value type with an implicitly implemented interface?, but different because it shouldn't need a constraint to do this because it's not generic at all. I have the code interface I { void F(); } struct C : I { void I.F() {} } static class P { static void Main() { C x; ((I)x).F(); } } The main method compiles to this: IL_0000: ldloc.0 IL_0001: box C IL_0006: callvirt instance void I::F() IL_000b: ret

Why does the VS Metadata view does not display explicit interface implemented members

泄露秘密 提交于 2019-11-28 13:39:33
The other day i was looking at C# Boolean struct metadata. Boolean implements the interface IConvertible. But looking at Boolean's members i could not see most of the IConvertible members. I've done some tests with some colleagues, including creating our own classes, and came to the conclusion that IConvertible must be implemented explicitly for Boolean. The question is, why are they not visible? I understand it might be a 'by design decision' but i understand that it would add greater value if they were visible to anyone inspecting the metadata. The tests were done in VS2010 .NET4.0 The

Access modifiers on interface members in C#

∥☆過路亽.° 提交于 2019-11-28 09:07:12
I am getting a compile error from the following property. The error is: "The modifier 'public' is not valid for this item" public System.Collections.Specialized.StringDictionary IWorkItemControl.Properties { get { return properties; } set { properties = value; } } but if I remove the IWorkItemControl it compiles fine. Why am I getting this error and what is the difference of having / not having the interface name in the signature? Explicit interface implementation does not let you specify any access modifiers. When you implement an interface member explicitly (by specifying the interface name

Fortran - explicit interface

自作多情 提交于 2019-11-28 03:37:39
问题 I'm very new to Fortran, and for my research I need to get a monster of a model running, so I am learning as I am going along. So I'm sorry if I ask a "stupid" question. I'm trying to compile (Mac OSX, from the command line) and I've already managed to solve a few things, but now I've come across something I am not sure how to fix. I think I get the idea behind the error, but again, not sure how to fix. The model is huge, so I will only post the code sections that I think are relevant (though

Why would a class implement IDisposable explicitly instead of implicitly?

独自空忆成欢 提交于 2019-11-27 09:25:09
I was using the FtpWebResponse class and didn't see a Dispose method. It turns out that the class implements IDisposable, but does so explicitly so that you must first cast your instance to IDisposable before calling Dispose: // response is an instance of FtpWebResposne ((IDisposable) response).Dispose(); Why would the designer of a class such as this one choose to implement IDisposable explicitly? As Anthony Pegram says , doing things this way masks the fact that the object should be disposed for the average developer who is not consulting the documentation every time he/she uses a class.