interface

Efficiently return IList<Interface> from List<T> (avoid casting from List<T> to List<I>)

蓝咒 提交于 2019-12-11 11:47:03
问题 I have the following code: public interface ISomeObject { IList<ISomeObject> Objects { get; } } public class SomeObject : ISomeObject { public SomeObject() { Objects = new List<SomeObject>(); } public List<SomeObject> Objects { get; set; } IList<ISomeObject> ISomeObject.Objects { get { // What to do here? // return Objects; // This doesn't work return Objects.Cast<ISomeObject>().ToList(); // Works, but creates a copy each time. } } SomeObject has a public property Objects that returns a List

Passing values to interface{}

廉价感情. 提交于 2019-12-11 11:37:59
问题 Short The following code does not exactly do what expected: https://play.golang.org/p/sO4w4I_Lle I assume that I mess up some pointer/reference stuff as usual, however I expect my... func unmarshalJSON(in []byte, s interface{}) error ... and encoding/json s... func Unmarshal(data []byte, v interface{}) error ...to behave the same way (eg. update the referenced passed as second argument). Long The example above is a minimal reproducer that does not make much sense. This is in order to make it

Obtain the value of a dictionary after select on of the combobox value

别说谁变了你拦得住时间么 提交于 2019-12-11 11:32:51
问题 I have created a dictionary for my combobox's value. I am trying to use .get(keys) to obtain the value that I set for the combobox. For example if I select A, it should print out Haha What , B should print out Lala Sorry , both of them are the values in my dictionary so how can I correct my code? from tkinter import * from tkinter import ttk class Application: def __init__(self, parent): self.parent = parent self.value_of_combo='A' self.combo() def textArea(self, e): self.value_of_combo =

How can I access UI Elements of a fragment inside of a Custom Adapter From an Activity in Android

六月ゝ 毕业季﹏ 提交于 2019-12-11 11:29:43
问题 Good day all, I am working on an application where I have multiple Activities (Activities A, B, B) that inflate this fragment (TheListFragment). This is a visual representation of what it looks like: Currently, I am able to change the descriptions, images, etc from the Fragment itself, but that is not what I would like to do. My goal is to have the respective activities all be able to change the fragment and use the fragment as a reusable listview. Here is some of my code: public class

COM Interface as a param of WinRT ref class, how it possible?

爱⌒轻易说出口 提交于 2019-12-11 11:26:09
问题 How I can define this class correctly: public ref class WICBMP sealed { void Load(IWICBitmapSource ^wicBitmapSource); }; 回答1: This is not possible. Only Windows Runtime types may be used when declaring members of a Windows Runtime interface (in this specific case, the compiler will need to generate an interface that declares your Load member function). You can't even do this if you try to define the interface in IDL. A runtime class can implement COM interfaces that are not Windows Runtime

Specify which implementation of Java interface to use in command line argument

廉价感情. 提交于 2019-12-11 11:22:01
问题 Say I have a Java interface Blender.java with various implementations Cuisinart.java , Oster.java , Blendtec.java , etc. Now I want to write a program like so: public class Blendifier { // ... public static void main(String... args) { Blender blender = new Cuisinart(); blender.blend(); } } But now if I want to use the Blendtec instead of the Cuisinart , I have to open up the source, change the code, and recompile. Instead, I'd like to be able to specify which Blender to use on the fly when I

How to delegate interface calls to a member that implements the interface

老子叫甜甜 提交于 2019-12-11 11:18:33
问题 Suppose, I have an interface ICry that has functions that return the sound of an animal: public interface ICry { string Cry(); } I have several classes that implement ICry: class Cat : ICry { public string Cry { get { return "Meow!"; } } } class Dog: ICry { public string Cry { get { return "Woof"; } } } If I have a PetOwner object that owns a pet, and I know this PetOwner can Cry(), but want to hide how he cries, I could do the following: class PetOwner : ICry { private Cat cat = new Cat();

MOXy/JAXB “prototype pattern” - interface inheritance

ぃ、小莉子 提交于 2019-12-11 10:58:48
问题 I'm trying to implement a version of Gang of Four's Prototype Pattern using MOXy/JAXB 2.5.0. I want to be able to specify a list of items, some of which are "based on" others, i.e. copy their data from other instances. For reusability, I'd like to create an interface that any prototype-able object should implement, which will provide annotation for the properties necessary to support the pattern. @XmlRootElement(name="IPrototype") public interface IPrototype { /** * Acts as a "copy

How do I implement an InfoWindowAdapter interface in Xamarin?

强颜欢笑 提交于 2019-12-11 10:56:53
问题 I am using Xamarin and I am wanting to create a CustomWindowAdapter that implements a GoogleMap.InfoWindowAdapter interface. I have tried this so far: public class CustomWindowAdapter : InfoWindowAdapter { } I am getting this error: Error CS0246: The type or namespace name 'InfoWindowAdapter' could not be found (are you missing a using directive or an assembly reference?) Here is the documentation for the interface: https://developers.google.com/maps/documentation/android/reference/com/google

How to declare the interface section for a procedure argument, which in turn references to a user-derived type of the same module?

别等时光非礼了梦想. 提交于 2019-12-11 10:47:52
问题 As the following code sample shows, person_list is a user-derived type and contains a type-bound procedure compare_persons . I would like compare_persons to be able to accept a certain group of compareFunc as one of its arguments, and therefore declare the interface section for compareFunc . Note the first argument of compareFunc is of type person_list . (As you might tell, person_list is like TStringList in Delphi's VCL.) The compilation cannot proceed. The error messages are: [root