interface

Adding Interface Implementation to ExpandoObject

我们两清 提交于 2019-12-14 02:25:22
问题 I am passing information between a SQL database and a PLC using 3rd party OPC libraries. There are essentially two transactions. Information passed from the PLC to the SQL server is statically typed. Very specific data is captured by the PLC and passed to the SQL database. Information passed from the SQL server to the PLC is dynamically typed and may be limited to a single property or hundreds. ITransaction.cs public interface ITransaction : INotifyPropertyChanged { short Response { get; set;

Delphi7, passing object's interface - causes Invalid Pointer Operation when freeing the object

帅比萌擦擦* 提交于 2019-12-14 01:49:18
问题 I have a class that implements an interface, which is made available for plugins. The declaration of class is quite simple. There is only one instance of this class for an entire application. When the function that returns the interface is called, it calls _AddRef on the retrieved interface before passing it back as result. Unfortunately it works until I try to free the object (see "finalization" section) - it reports Invalid Pointer Operation. If I comment it out, it works fine (however

Interface inheritance consistency

蹲街弑〆低调 提交于 2019-12-14 01:36:43
问题 First look at this code: class Program { static void Main(string[] args) { var x =(Base) new Derived(); ((IMethod)x).DoWork(); Console.ReadKey(); } } interface IMethod { void DoWork(); } abstract class Base : IMethod { void IMethod.DoWork() { Console.WriteLine("Base.DoWork"); } } class Derived : Base, IMethod { public void DoWork() { //here I where I want to call base.DoWork(); Console.WriteLine("Derived.DoWork"); } } Output: Derived.DoWork Desired: Base.DoWork Derived.DoWork I'm dealing with

How to define the default implementation of an interface in c#?

情到浓时终转凉″ 提交于 2019-12-14 00:15:03
问题 There is some black magic code in c# where you can define the default implementation of an interface. So you can write var instance = new ISomeInterface(); Any pointers? UPDATE 1: Note that I did not ask if this is a good idea. Just how was it possible to do it. UPDATE 2: to anyone seeing the accepted answer. "this should be treated merely as a curiosity." from Marc Gravel "Newing up" Interfaces "It's a bad idea to use a tool designed for COM interop to do something completely and utterly

Can I dynamically instantiate an interface at runtime? Well Yes I can but is there a better way?

早过忘川 提交于 2019-12-14 00:12:53
问题 Say I have a bunch of classes that implement an interface: public interface IBuilding { string WhatAmI(); } Class house:IBuilding { string Ibuilding.WhatAmI(){return "A House";} } Class Skyscraper:IBuilding { string Ibuilding.WhatAmI(){return "A Skyscraper";} } Class Mall:IBuilding { string Ibuilding.WhatAmI(){return "A Mall";} } And then I want to dynamically choose what to instantiate the class: enum buildingType { house, Skyscraper, Mall }; string someMethodOrAnother() { string building=

Why can't I pass a `func() []int` as `func() []interface{}` in go?

断了今生、忘了曾经 提交于 2019-12-13 22:53:24
问题 I have the following definition: func (c *Collector) RegisterSource(f func() []interface{}) { c.source = f } I attempt to call it as follows but get an error: func source() []int { return []int{ 0, 1, 2, 3, 4 } } ... c.RegisterSource(source) This is met with: cannot use source (type func() []int) as type func() []interface {} in argument to c.RegisterSource 回答1: The relevant Go FAQ entry states that []T and []interface{} «do not have the same representation in memory». To understand why, let

Explicit casting on objects with interface. What's the use of parentheses

梦想与她 提交于 2019-12-13 21:23:30
问题 I have found a similar question, but it didn't really concern the interface issue - Issue about casting object brackets public class Speak { /* Line 1 */ public static void main(String[] args) { /* Line 2 */ Speak speakIT = new Tell(); /* Line 3 */ Tell tellIt = new Tell(); /* Line 4 */ speakIT.tellItLikeItIs(); /* Line 5 */ (Truth)speakIt.tellItLikeItIs(); /*Line 6 */ ((Truth)speakIt).tellItLikeItIs(); /* Line 7 */ tellIt.tellItLikeItIs(); /* Line 8 */ (Truth)tellIt.tellItLikeItIs(); /* Line

Interfaces in C++: why do I need an interface class + another parent class?

孤街醉人 提交于 2019-12-13 21:22:57
问题 This question explains nicely how to create interfaces in C++. Here is the code: class IDemo { public: virtual ~IDemo() {} virtual void OverrideMe() = 0; }; class Parent { public: virtual ~Parent(); }; class Child : public Parent, public IDemo { public: virtual void OverrideMe() { //do stuff } }; One thing is not clear to me though: What do I need the class Parent for? 回答1: You're not required to inherit from anything besides your interface to make use of the interface, however you can do so

Cannot loop through list A(icollection) of generic type B where A and B both implement same interface

元气小坏坏 提交于 2019-12-13 21:07:21
问题 The intro is a bit tedious, but is just for clearity! Some might even learn something from it or get some handy insights. My question is found at the bottom. I really hope someone can help me! I have this interface public interface IEFEntity { object GetPKValue(); bool PKHasNoValue(); } All my automatic genereted EF classes implement this interface and implement the 2 methods. This is done via a separate file using partial classes so the implementation is not gone when regenerating the EF

Classes that defacto implement an interface but do not declare the fact

只谈情不闲聊 提交于 2019-12-13 20:55:15
问题 I will illustrate my question with the below posted code. It was created specifically for this purpose. The fact that it uses inner interface and inner classes is immaterial (it was just a convenience). The code compiles and runs as expected. In this code I use inheritance with the sole purpose to declare that a class implements an interface , so later on I can cast them up and use polymorphic behavior. Parent classes already have methods to comply with the interface, so no overriding is