Questions tagged [explicit-interface]

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

88 questions
2
votes
3 answers

Explicit Interface And Generic / Dynamic Type Conversion

Before I state my issue let me give some background information on what I'm trying to do, because perhaps there's a better way to achieve it. I got a class C which inherits two interfaces A and B. public interface A { void DoStuff(); } public…
Bauss
  • 2,767
  • 24
  • 28
2
votes
1 answer

Explicit Override Using Automatic Property

I'm trying to use a C++/CLI auto-implemented property to explicitly override an interface. In particular, I have written (in C++/CLI) interface IInterface { property Object ^MyProperty { Object ^get(void); void…
2
votes
1 answer

Dynamic and Explicit Generic Interface Implementation

I've learnt from here that dynamic variables cannot access methods on interfaces they explicitly implement. Is there an easy way to invoke the interface methods when I don't know the type parameter T at compile time? interface I { void…
Rob
  • 4,327
  • 6
  • 29
  • 55
2
votes
1 answer

Explicit Interface Implementation demanded, but only one interface in use?

Why does the following code have to have 'CalcUsable' defined using Explicit Interface Implementation syntax? (see last line of code) If I use non-explicit syntax, (ie. public decimal CalcUsable) I get an "inconsistent accessibility" error,…
CodeCabbie
  • 3,098
  • 2
  • 19
  • 30
2
votes
1 answer

Explicit interface implementation related with an IEnumerable implementation?

Why in this MSDN example is needed the GetEnumerator1 method? // Must implement GetEnumerator, which returns a new StreamReaderEnumerator. public IEnumerator GetEnumerator() { return new StreamReaderEnumerator(_filePath); } // Must…
user1785721
2
votes
2 answers

Every interface explicitly implemented? (IoC involved)

I'm very aware of the fact that such a question has probably been posted already. Yet with the involvement of IoC in this case and a lot of code I've seen a colleague in a company I'm new in made this question arise. Scenario: In the codebase of…
Alex Endris
  • 444
  • 4
  • 16
2
votes
2 answers

How do I use an explicitly implemented interface property and wpf visiblity together properly?

I have the following situation: I have a few ViewModel objects, some of which implement an interface ISomeInterface, some don't. The interfaces exposes a property called SomeEnumeration (IEnumerable). For example: public sealed class ViewModelA :…
michael
  • 14,844
  • 28
  • 89
  • 177
2
votes
1 answer

Using Explicit Interfaces to prevent accidental modification of properties in C#

I stumbled on a feature of C# method resolution that I didn't notice before. Namely, when I explicitly implement an interface that supports a setter, and the implicit interface only offers a protected set, the compiler sensibly defers to the…
JasonTrue
  • 19,244
  • 4
  • 34
  • 61
2
votes
1 answer

How to create an explicit interface declaration index property with CodeDOM

I am trying to create an explicit interface declaration index property. So for example: public interface IFoo { int this[int i] } public abstract class Foo : IFoo { int IFoo.this[int i] } I have written the following bit of code to do so…
ElfsЯUs
  • 1,188
  • 4
  • 14
  • 34
2
votes
2 answers

F# Explicit Interface Method for Two Interfaces

What is the correct way to handle this situation. I have one method in my F# class DogTree that should fulfill the requirement of implementing a Bark() method for both interfaces. type ITree = interface abstract Bark : unit -> unit …
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
2
votes
1 answer

Implementing Interfaces Explictly in F#

Ok, C# has Explictit Interface Implementation I'l like to do similar in F#. I have some Interfaces (and classes) type IState = interface abstract member Update : IAction-> IState ... end type IEnviroment = interface abstract member…
2
votes
1 answer

Explicit overriding

msft compilers for C++ support explicit overriding (see http://msdn.microsoft.com/en-us/library/ksek8777.aspx) // could be declared __interface I1, making the public scope and pure virtual implied // I use the more expressive form here for…
payo
  • 4,501
  • 1
  • 24
  • 32
1
vote
1 answer

What is this C# interface syntax called and what does it mean

I am working on a rather complex set of interfaces which allows to define objects with a specific structure. Via interfaces and generics it also allows me to define a composition of interfaces which are available in each element. The structure maps…
monty
  • 7,888
  • 16
  • 63
  • 100
1
vote
2 answers

IXmlSerializable and Immutability

I am implementing IXmlSerializable in an immutable class. To keep the class immutable I am implementing the interface explicitly, so as to hide the methods, and using a static ReadXml() method which encapsulates the ReadXml(XmlReader reader) method…
User
  • 3,244
  • 8
  • 27
  • 48
1
vote
4 answers

Can one reference a same-named implicit property in an explicit Interface implementation?

Say I have a type that implements a property with a string type: public class Record { public string Value { get; set; } } Then I have an interface that defines a property with the same name: public interface IIntValued { public int Value…
el2iot2
  • 6,428
  • 7
  • 38
  • 51