草庐IT

explicit-implementation

全部标签

c# - 网络核心 : register implementation with multiple interfaces and lifestyle Singleton

考虑以下接口(interface)和类定义:publicinterfaceIInterface1{}publicinterfaceIInterface2{}publicclassMyClass:IInterface1,IInterface2{}有没有办法像这样用多个接口(interface)注册一个MyClass的实例:...services.AddSingleton();...并用像这样的不同接口(interface)解析MyClass的单个实例:IInterface1interface1=app.ApplicationServices.GetService();IInterface

c# - 网络核心 : register implementation with multiple interfaces and lifestyle Singleton

考虑以下接口(interface)和类定义:publicinterfaceIInterface1{}publicinterfaceIInterface2{}publicclassMyClass:IInterface1,IInterface2{}有没有办法像这样用多个接口(interface)注册一个MyClass的实例:...services.AddSingleton();...并用像这样的不同接口(interface)解析MyClass的单个实例:IInterface1interface1=app.ApplicationServices.GetService();IInterface

c# - 错误 "Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal"

我试图将一个类设置为私有(private)类,但出现此错误“命名空间中定义的元素无法显式声明为私有(private)、protected或protected内部”我明白了它的意思,但我想问一下为什么不允许这样做?所有的访问修改都不适用于类吗?为什么我不能将类设为私有(private)、protected或protected内部? 最佳答案 因为private意味着该成员仅在包含类中可见。由于顶级类没有包含它的类,因此它不能是私有(private)的(或protected)。(尽管内部或公共(public)是有效的修饰符)。您希望pr

c# - 错误 "Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal"

我试图将一个类设置为私有(private)类,但出现此错误“命名空间中定义的元素无法显式声明为私有(private)、protected或protected内部”我明白了它的意思,但我想问一下为什么不允许这样做?所有的访问修改都不适用于类吗?为什么我不能将类设为私有(private)、protected或protected内部? 最佳答案 因为private意味着该成员仅在包含类中可见。由于顶级类没有包含它的类,因此它不能是私有(private)的(或protected)。(尽管内部或公共(public)是有效的修饰符)。您希望pr

c# - 编译错误 : "The modifier ' public' is not valid for this item"while explicitly implementing the interface

我在类上创建public方法以显式实现interface时遇到此错误。我有一个解决方法:通过删除PrintName方法的显式实现。但我很惊讶为什么会收到此错误。任何人都可以解释错误吗?库代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceTest.Lib1{publicclassCustomer:i1{publicstringi1.PrintName()//ErrorHere...{returnthis.GetType().Name+"calledfromin

c# - 编译错误 : "The modifier ' public' is not valid for this item"while explicitly implementing the interface

我在类上创建public方法以显式实现interface时遇到此错误。我有一个解决方法:通过删除PrintName方法的显式实现。但我很惊讶为什么会收到此错误。任何人都可以解释错误吗?库代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceTest.Lib1{publicclassCustomer:i1{publicstringi1.PrintName()//ErrorHere...{returnthis.GetType().Name+"calledfromin

Multiple HTTP implementations were found on the classpath错误的解决方法

当我们的项目中集成了多个AWS相关Jar包时,有可能就会遇到这个错误:错误信息:ThereisanissuewiththeconnectorCode:InvalidInput.InvalidConnectorConfigurationMessage:Theconnectorconfigurationisinvalid.Message:MultipleHTTPimplementationswerefoundontheclasspath.Toavoidnon-deterministicloadingimplementations,pleaseexplicitlyprovideanHTTPclien

c# - 如何调用重写虚方法的 'base implementation'?

这个问题在这里已经有了答案:Isthereanywaytocalltheparentversionofanoverriddenmethod?(C#.NET)(8个答案)关闭6年前。给定以下代码,是否可以调用类A版本的方法X?classA{virtualvoidX(){Console.WriteLine("x");}}classB:A{overridevoidX(){Console.WriteLine("y");}}classProgram{staticvoidMain(){Ab=newB();//CallA.Xsomehow,notB.X...}

c# - 如何调用重写虚方法的 'base implementation'?

这个问题在这里已经有了答案:Isthereanywaytocalltheparentversionofanoverriddenmethod?(C#.NET)(8个答案)关闭6年前。给定以下代码,是否可以调用类A版本的方法X?classA{virtualvoidX(){Console.WriteLine("x");}}classB:A{overridevoidX(){Console.WriteLine("y");}}classProgram{staticvoidMain(){Ab=newB();//CallA.Xsomehow,notB.X...}

c# - TypeLoadException 说 'no implementation' ,但它已实现

我的测试机器上有一个非常奇怪的错误。错误是:System.TypeLoadException:程序集“ActiveViewers(...)”中类型“DummyItem”中的方法“SetShort”没有实现。我只是不明白为什么。SetShort位于DummyItem类中,我什至重新编译了一个写入事件日志的版本,以确保这不是部署/版本控制问题。奇怪的是调用代码甚至没有调用SetShort方法。 最佳答案 注意-如果此答案对您没有帮助,请花时间向下滚动浏览此后人们添加的其他答案。简答如果您将方法添加到一个程序集中的接口(interface