Questions tagged [explicit-interface]

C# Explicit Interface Implementation when implementing two interfaces, both with the same method and different implementations

88 questions
10
votes
3 answers

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

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…
Morgan Cheng
  • 73,950
  • 66
  • 171
  • 230
10
votes
4 answers

C# - Explicit Interfaces with inheritance?

Output: B->Hello! from Explicit. Shouldn't it be:? A->Hello! from Explicit. Why doesn't explicit cast (IHello)a call IHello.Hello() from class A? interface IHello { void Hello(); } class A : IHello { public virtual void Hello() { …
Naximus
  • 579
  • 6
  • 18
9
votes
3 answers

Dependency Injection and Explicit Interface Implementation

Is there a benefit implementing interfaces explicitly with respect to Dependency Injection? As far as I understand, interfaces can be implemented either explicitly or implicitly: interface IFoo { void Bar(); } //implicit implementation class…
Thaoden
  • 3,460
  • 3
  • 33
  • 45
8
votes
3 answers

How can I call explicitly implemented interface method from PowerShell?

Code: add-type @" public interface IFoo { void Foo(); } public class Bar : IFoo { void IFoo.Foo() { } } "@ -Language Csharp $bar = New-Object Bar ($bar -as [IFoo]).Foo() #…
alex2k8
  • 42,496
  • 57
  • 170
  • 221
7
votes
4 answers

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

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…
Luis Filipe
  • 8,488
  • 7
  • 48
  • 76
7
votes
2 answers

XML Comments -- How do you comment explicitly implemented interfaces properly?

Code: public interface IFoo { void Bar(); } public class FooClass : IFoo { /// ... /// //How do you reference the IFoo.Bar() method public void Bar() { } /// ...
myermian
  • 31,823
  • 24
  • 123
  • 215
7
votes
2 answers

Explicitly implemented interface and generic constraint

interface IBar { void Hidden(); } class Foo : IBar { public void Visible() { /*...*/ } void IBar.Hidden() { /*...*/ } } class Program { static T CallHidden1(T foo) where T : Foo { foo.Visible(); ((IBar)foo).Hidden(); …
6
votes
6 answers

Explicit interface implementation limitation

I have a very simple scenario : a "person" can be a "customer" or an "employee" of a company. A "person" can be called by phone with the "Call" method. Depending on which role the "person" plays in the context of the call, e.g. the announcement of a…
Pragmateek
  • 13,174
  • 9
  • 74
  • 108
6
votes
2 answers

Fortran procedure pointer to subroutines in derived type

In Fortran, I need a procedure pointer inside a derived type that can point to one of several subroutines. This problem seems to be common on SO: Fortran save procedure as property in derived type Type bound procedure overloading in Fortran…
Charles
  • 947
  • 1
  • 15
  • 39
6
votes
4 answers

C# property not available in derived class

I'm not sure what's going on. I have the following base class: public class MyRow : IStringIndexable, System.Collections.IEnumerable, ICollection>, IEnumerable>, …
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
5
votes
3 answers

C++/CLI: Implementing IList and IList (explicit implementation of a default indexer)

I am trying to implement a C++/CLI class that implements both IList and IList. Since they have overlapping names, I have to implement one of them explicitly, and the natural choice should be IList. The implicit implementation of the indexer…
Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
5
votes
3 answers

FxCop: CA1033 - Microsoft's implementation of a ReadOnlyCollection violates this?

If you look at the code for a read-only collection it does not have an "Add" method, but instead defines the ICollection.Add(T Value) method (explicit interface implementation). When I did something similar with my ReadOnlyDictionary class, FxCop…
myermian
  • 31,823
  • 24
  • 123
  • 215
5
votes
6 answers

how List does not implement Add(object value)?

I believe it's pretty stupid, and I am a bit embarrassed to ask this kind of question, but I still could not find the answer: I am looking at the class List , which implemetns IList. public class List : IList one of the methods included in…
ET.
  • 1,899
  • 2
  • 18
  • 28
5
votes
0 answers

Why do I need an explicit interface declaration here? (C#)

I'm trying to implement a very simple interface and use it to access a property of a type that is itself accessed through an interface like so: interface ITest { IOther Other { get; } } interface IOther { } class Other : IOther { } class Test…
mistakenot
  • 554
  • 3
  • 14
4
votes
1 answer

why does the Array class implement the Ilist Interface Explicitly not Implicitly?

My target language is C# with .net framework . I want to know what is the point or the reason behind this topic ? any advice and suggestions would be highly Appreciated . EDIT why i asked this question ? because right now , some useful members of…