interface

How do I get DataContractJsonSerializer to use concrete type in type hint when serializing generic class from interface

青春壹個敷衍的年華 提交于 2019-12-11 06:14:51
问题 I have a set of classes as follows: a Command, which Executes and stores a Result; a Response, which is created as in order to return the Result in a serialized form (plus extra metadata which I've left out). The Response.Result must be of type object, as it is used for a bunch of different commands, each of which can have a Result of any type at all. The Command is generic, and I'd like it to accept an interface rather than concrete type, but when I do, the serialized response contains the

Typescript object wrapping, typings and generics [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-11 06:13:47
问题 This question already has answers here : Typescript typings, generics and abstract classes (2 answers) Closed 2 years ago . This is somewhat the transformation of a question I posted somewhere else yesterday. My objective is not to get a working result but to have a better understanding of the kind of design I can obtain while returning the correct types. This by using here a minimalist example, so please don't tell me it's useless or does nothing. Code sample (Try it in Typescript playground

Issue translating data back from serialization into Go struct dynamically using reflection

早过忘川 提交于 2019-12-11 05:55:59
问题 I'm having trouble using reflection in Go to fetch data from a cache dynamically into various statically declared struct types: func FetchFromCacheOrSomewhereElse(cacheKey string, returnType reflect.Type) (out interface {}, err error) { fetchFromCache := reflect.New(returnType).Interface(); _, err=memcache.Gob.Get(*context, cacheKey, &fetchFromCache); if (err==nil) { out=reflect.ValueOf(fetchFromCache).Elem().Interface(); } else if (err==memcache.ErrCacheMiss) { /* Fetch data manually... */ }

Could we autowire an interface without any implementation in Spring?

北慕城南 提交于 2019-12-11 05:49:32
问题 We have to share our code base with a partner for developing, but we don't want to reveal the implementation of some services. Say we have an interface FooService and its implementation FooServiceImpl . public interface FooService { void doSomething(); } @Service public class FooServiceImpl implements FooService { @Override public String doSomething(); { ... } } Many other classes autowire this service in and call doSomething(). For example: @Service public class BarServiceImpl implements

C# How to implement interface where concrete classes differs?

主宰稳场 提交于 2019-12-11 05:38:18
问题 First, sorry for the vaque title, but I don't know a good title for my question. In my application I use criteria. The criteria can be seen as controls. I have textboxes, but also radio buttons and check boxes. I use interfaces to achieve this: ICriteria is the base interface where all criteria classes inherits from. TextType inherits from ICriteria. RadioType also inherits from ICriteria. But, RadioType must have choices. Both, TextType and RadioType do have some properties which are the

Create object from dynamically load assembly and cast it to interface (.NET 2.0)

只谈情不闲聊 提交于 2019-12-11 05:22:15
问题 I have a problem with dynamically loaded assemblys and casting it to interface. Where is my mistake? Main app (load plugins): namespace Console_IFce_Test { class Program { static void Main(string[] args) { Console.WriteLine("Press any key to find IPlugin library..."); Console.ReadKey(); string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.dll"); Console.WriteLine("Loading assembly: {0}", Path.GetFileName(files[0])); Assembly asm = Assembly.LoadFrom(files[0]); //Trying this,

How to convert between an Object[] and an interface (IProject[]) in Java?

此生再无相见时 提交于 2019-12-11 05:10:31
问题 I have an Object[] in Java and want to convert it to IProject[], which is a Java interface (org.eclipse.core.resources.IProject), in order to write a plugin for eclipse. Is this possible? Regards 回答1: You can't convert the array itself - arrays know the type of their slots, so you can't just cast an instance of Object[] to an expression of type IProject[] , even if the array happens to contain only instances of IProject (unless you happen to have a variable of type Object[] which actually

Delphi: How to call a method when i click a control?

自古美人都是妖i 提交于 2019-12-11 05:05:10
问题 i have a method: procedure Frob(Sender: TObject); that i want to call when i click a menu item. The method comes to me though an interface: animal: IAnimal; IAnimal = interface procedure Frob(Sender: TObject); end; The question revolves around what to assign to the OnClick event handler of a menu item (i.e. control): var animal: IAnimal; ... begin ... menuItem := TMenuItem.Create(FileMenu) menuItem.Caption := 'Click me!'; menuItem.OnClick := <-------- what to do ... end; The obvious choice,

Enumerating a Mocked Indexer Property Causes the Collection to Become Empty

末鹿安然 提交于 2019-12-11 04:53:06
问题 Okay, to reproduce, here is what you need public interface IWorkbookSet { IWorkbooks Workbooks { get; } } public interface IWorkbooks : IEnumerable { IWorkbook this[int index] { get; } IWorkbook this[string name] { get; } int Count { get; } } public interface IWorkbook { IWorksheets Worksheets { get; } } public interface IWorksheets : IEnumerable { IWorksheet this[int index] { get; } IWorksheet this[string name] { get; } int Count { get; } IWorksheet Add(); IWorksheet AddAfter(IWorksheet

C++ Is a components-based architeture implemented via inheritance considered good practice?

纵饮孤独 提交于 2019-12-11 04:47:57
问题 I'm implementing an architecture when i have a container of heterogeneous objects which may have or not some common methods-attribute. I need to cycle through them and apply some functions, update some members, and call some methods over the various interfaces. I've come up to what i believe a "standard" architecture, based on inheritance: #include <vector> #include <memory> #include <iostream> using namespace std; struct Base { virtual ~Base() {} }; struct PositionInterface { int x = 0; int