interface

Generics with interfaces in F#

主宰稳场 提交于 2020-01-12 15:14:25
问题 In C# one can state that a generic parameter must implement a certain interface like so: public class Something<T> where T : IComparable { ... } How does one specify this in F#? 回答1: Generic constraints use "when" in F#: type Foo<'a when 'a :> IComparable> = member x.Bla = 0 来源: https://stackoverflow.com/questions/770143/generics-with-interfaces-in-f

Generics with interfaces in F#

那年仲夏 提交于 2020-01-12 15:14:12
问题 In C# one can state that a generic parameter must implement a certain interface like so: public class Something<T> where T : IComparable { ... } How does one specify this in F#? 回答1: Generic constraints use "when" in F#: type Foo<'a when 'a :> IComparable> = member x.Bla = 0 来源: https://stackoverflow.com/questions/770143/generics-with-interfaces-in-f

In C#, is it possible to implement an interface member using a member with a different name, like you can do in VB.NET?

混江龙づ霸主 提交于 2020-01-12 13:47:09
问题 Ok, this is a question I'm asking, not as in demonstrating good coding practices (this actually could be considered a bad practice) but rather in regards to 'can' it be done at all. That said, in VB.NET you implement an interface like this... Sub SomeInterfaceMember() Implements ISomeInterface.SomeInterfaceMember End Sub while in C# you do it explicitly like this (which can only be called via the interface)... void ISomeInterface.SomeInterfaceMember(){} or more simply, implicitly like this

C# Interfaces with optional methods

荒凉一梦 提交于 2020-01-12 11:56:26
问题 I understand that interfaces are contracts and any changes (even additions) break any dependent code. However, I could have sworn I read something a while back that one of the recent .NET versions (3, 3.5??) added a new attribute that could be applied to new interface members. This attribute allowed versioning and/or making members optional. It would have been something like: interface ITest { void MethodOne(); [InterfaceVersion(2)] void MethodTwo(); } I have looked high and low for this but

How do I cast to an interface an object may implement?

随声附和 提交于 2020-01-12 08:39:08
问题 I have the following classes & interfaces: export interface IBody { body : ListBody; } export class Element { // ... } export class Paragraph extends Element implements IBody { // ... } export class Character extends Element { // ... } I have code where I will get an array of Element derived objects (there are more than just Paragraph & Character). In the case of those that implement IBody, I need to take action on the elements in the body. What is the best way to see if it implements IBody?

Callback with interfaces or function objects? [closed]

匆匆过客 提交于 2020-01-12 05:24:41
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . In OO, one usually implements callbacks with interfaces: (rough example) class Message {} class IMsgProcessor { public: virtual void handle_msg(const Message& msg) = 0; } class RequestMsgProcessor : public IMsgProcessor { virtual void handle_msg(const Message& msg) { //

Callback with interfaces or function objects? [closed]

亡梦爱人 提交于 2020-01-12 05:23:05
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . In OO, one usually implements callbacks with interfaces: (rough example) class Message {} class IMsgProcessor { public: virtual void handle_msg(const Message& msg) = 0; } class RequestMsgProcessor : public IMsgProcessor { virtual void handle_msg(const Message& msg) { //

How to avoid re-implementing sort.Interface for similar golang structs

孤街醉人 提交于 2020-01-12 03:29:15
问题 There is one problem bothering me in Golang. Say I have 2 structs: type Dog struct { Name string Breed string Age int } type Cat struct { Name string FavoriteFood string Age int } And when I try to sort []*Dog and []*Cat by Age , I have to define 2 different sort struct like: type SortCat []*Cat func (c SortCat) Len() int {//..} func (c SortCat) Swap(i, j int) {//..} func (c SortCat) Less(i, j int) bool {//..} type SortDog []*Dog func (c SortDog) Len() int {//..} func (c SortDog) Swap(i, j

Specifying multiple interfaces for a parameter

≡放荡痞女 提交于 2020-01-12 02:58:07
问题 I have an object that implements two interfaces... The interfaces are: public interface IObject { string Name { get; } string Class { get; } IEnumerable<IObjectProperty> Properties { get; } } public interface ITreeNode<T> { T Parent { get; } IEnumerable<T> Children { get; } } such that public class ObjectNode : IObject, ITreeNode<IObject> { public string Class { get; private set; } public string Name { get; private set; } public IEnumerable<IObjectProperty> Properties { get; set; } public

Things to consider when writing for touch screen?

☆樱花仙子☆ 提交于 2020-01-11 18:51:06
问题 I'm starting a new project which involves developing an interface for a machine that measures wedge and roundness of lenses and stores the information in a database and reports on it. There's a decent chance we're going to be putting a touch screen on this machine so that it doesn't need to have a mouse or keyboard... I don't have any experience developing for full size touch screens, so I'm looking for advice/tips/info from you guys... I can imagine you want to make the elements a little