草庐IT

IInterface

全部标签

java - JAXB 序列化接口(interface)到 XML 问题(Map<String,ISomeInterface> 不工作)

我正在尝试使用JAXB2.2.4将接口(interface)序列化为XML,但是当我在Map对象中有一个接口(interface)时,它会爆炸并给我错误:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:2countsofIllegalAnnotationExceptionscom.test.IInterface2isaninterface,andJAXBcan'thandleinterfaces.thisproblemisrelatedtothefollowinglocation:atcom.test.IInterface

c# - 如何使用 Moq 提供方法实现?

我有一个包含一些方法的接口(interface)。我有这个接口(interface)的默认实现。出于集成测试的目的,我想创建一个模拟实现,如果调用这些方法之一,它返回我的自定义值,否则回退到默认实现。是否可以使用Moq,还是我应该自己创建一个简单的stub?例子IInterfacedefault=newDefaultImplementation();varmock=newMock();mock.Setup(i=>i.Method(It.IsAny())).Calls(p=>p==0?return5:default.Method(p););TheMethodITest(mock.Obje

c# - 使用单个接口(interface)注册多个实现

有没有一种方法可以在不使用模板接口(interface)的情况下使用[simple-injector]注册由多个具体类实现的单个接口(interface)?假设我们有2个类MyClass1和Myclass2并且这两个类都实现了IInterface1现在使用[simple-injector]我们无法做到这一点container.Register();container.Register();将现有界面转换为模板界面在现有代码库上是一项艰巨的工作。希望那里有一些更简单的东西。 最佳答案 您可以使用RegisterCollection方法

c# - 实现具有通用约束的接口(interface)

有点惊讶为什么这不起作用这是编译器的限制还是不支持它是否有意义?publicclassClass1:IInterfacewhereT:Test2{publicTTest{get;privateset;}}publicclassTest2{}internalinterfaceIInterface{Test2Test{get;}}我得到的错误是'ClassLibrary1.Class1'doesnotimplementinterfacemember'ClassLibrary1.IInterface.Test'.'ClassLibrary1.Class1.Test'cannotimpleme

c# - 显式接口(interface)实现不能是虚拟的

郑重声明,我已经看过这个connectitem但我真的不明白支持这个会有什么问题。假设我有以下代码:publicinterfaceIInterface{voidMethod();}publicclassBase:IInterface{virtualvoidIInterface.Method(){thrownewNotImplementedException();}}虚拟标识符有什么问题?使用virtual修饰符可以override指示基类中有不同的实现。我现在可以通过删除虚拟方法并像这样创建派生类来使其工作:publicclassDerived:IInterface{voidIInte

c# - 转换为未明确实现的接口(interface)?

假设您定义了一些任意接口(interface):publicinterfaceIInterface{voidSomeMethod();}假设有些类碰巧有一个匹配的公共(public)接口(interface),即使它们没有“实现IInterface”。即:publicclassSomeClass{publicvoidSomeMethod(){//somecode}}有没有办法让IInterface引用一个SomeClass实例?即:SomeClassmyInstance=newSomeClass();IInterfacemyInterfaceReference=(IInterface)

c# - 在 C# 中,如果我的对象支持该接口(interface),我如何检查 T 是否属于 IInterface 类型并强制转换为该类型?

在C#中,我有一个使用generics传入T的函数,我想运行一个检查以查看T是否是一个object实现了一个interface,如果是的话调用那个interface上的methods之一。我不想让T约束只属于那种类型。可以这样做吗?例如:publicclassMyModel:IModelwhereT:MyObjectBase{publicIQueryableGetRecords(){varentities=Repository.Query();if(typeof(IFilterable).IsAssignableFrom(typeof(T))){//Filtermeisamethodt

c++ - 将 make_shared 与 protected 构造函数 + 抽象接口(interface)一起使用

给定一个抽象接口(interface)和一个从该接口(interface)派生的实现,其中构造函数受到保护(只能从类工厂创建这些对象-以实现DI模式),我如何在工厂函数中使用make_shared?例如:classIInterface{public:virtualvoidMethod()=0;};classInterfaceImpl:publicIInterface{public:virtualvoidMethod(){}protected:InterfaceImpl(){}};std::shared_ptrCreate(){std::shared_ptrobject=std::mak

c++ - 使用 C++ 接口(interface)的最佳方式

我有一个接口(interface)类类似于:classIInterface{public:virtual~IInterface(){}virtualmethodA()=0;virtualmethodB()=0;};然后我实现接口(interface):classAImplementation:publicIInterface{//etc...implementationhere}当我在应用程序中使用接口(interface)时,最好创建具体类AImplementation的实例。例如。intmain(){AImplementation*ai=newAIImplementation();

c++ - 使用隐式转换而不是 QueryInterface() 进行向上转换是否合法且具有多重继承?

假设我有一个实现两个或多个COM接口(interface)的类(与here完全一样):classCMyClass:publicIInterface1,publicIInterface2{};QueryInterface()必须为同一接口(interface)的每个请求返回相同的指针(需要显式向上转换才能正确调整指针):if(iid==__uuidof(IUnknown)){*ppv=static_cast(this);//callAddref(),returnS_OK}elseif(iid==__uuidof(IInterface1)){*ppv=static_cast(this);/
12