草庐IT

interface-design

全部标签

c# - 使用反射查找实现的接口(interface)

我有以下情况:publicinterfaceIPerson{..}publicclassPerson:IPerson{..}publicclassUser:Person{..}现在;如果我有一个“用户”对象——我如何检查它是否使用反射实现了IPerson?更准确地说,我有一个对象可能有一个属性SomeUser,它应该是实现接口(interface)“IPerson”的某种类型。在我的例子中,我实际上有一个用户,但这是我想通过反射检查的。我不知道如何检查属性类型,因为它是一个“用户”,但我想检查它是否实现了IPerson...:varcontrol=_container.Resolve(

c# - JSON.NET:如何根据父(持有者)对象值反序列化接口(interface)属性?

我有这样的类(class)classHolder{publicintObjType{get;set;}publicListObjects{get;set;}}abstractclassBase{//...doesn'tmatter}classDerivedType1:Base{//...doesn'tmatter}classDerivedType2:Base{//...doesn'tmatter}使用WebAPI我想接收对象Holder并正确反序列化。基于ObjType我需要的值(value)Objects要反序列化的属性为List(ObjType==1)或List(ObjType==

c# - JSON.NET:如何根据父(持有者)对象值反序列化接口(interface)属性?

我有这样的类(class)classHolder{publicintObjType{get;set;}publicListObjects{get;set;}}abstractclassBase{//...doesn'tmatter}classDerivedType1:Base{//...doesn'tmatter}classDerivedType2:Base{//...doesn'tmatter}使用WebAPI我想接收对象Holder并正确反序列化。基于ObjType我需要的值(value)Objects要反序列化的属性为List(ObjType==1)或List(ObjType==

c# - 向 resource.resx 添加新字符串未反射(reflect)到 Designer.cs

我正在向我们的resource.resx添加两个新字符串,但这些新添加的资源(字符串)并未反射(reflect)到自动生成的Designer.cs文件中。我重建了项目并尝试清理+构建项目但没有运气!我还有其他资源文件来支持各种国际语言,我也需要这两个新的字符串资源请提出建议。 最佳答案 确保resx文件的Customtool属性设置为ResXFileCodeGenerator或PublicResXFileCodeGenerator。.Designer.cs文件应该在每次修改resx文件时重新生成;如果不是,您可以通过在resx文件的

c# - 向 resource.resx 添加新字符串未反射(reflect)到 Designer.cs

我正在向我们的resource.resx添加两个新字符串,但这些新添加的资源(字符串)并未反射(reflect)到自动生成的Designer.cs文件中。我重建了项目并尝试清理+构建项目但没有运气!我还有其他资源文件来支持各种国际语言,我也需要这两个新的字符串资源请提出建议。 最佳答案 确保resx文件的Customtool属性设置为ResXFileCodeGenerator或PublicResXFileCodeGenerator。.Designer.cs文件应该在每次修改resx文件时重新生成;如果不是,您可以通过在resx文件的

c# - 更多关于 C# 中的隐式转换运算符和接口(interface)(再次)

好的。我已阅读this后,我对它如何适用于我的示例(如下)感到困惑。classFoo{publicstaticimplicitoperatorFoo(IFooCompatiblefooLike){returnfooLike.ToFoo();}}interfaceIFooCompatible{FooToFoo();voidFromFoo(Foofoo);}classBar:IFooCompatible{publicFooToFoo(){returnnewFoo();}publicvoidFromFoo(Foofoo){}}classProgram{staticvoidMain(strin

c# - 更多关于 C# 中的隐式转换运算符和接口(interface)(再次)

好的。我已阅读this后,我对它如何适用于我的示例(如下)感到困惑。classFoo{publicstaticimplicitoperatorFoo(IFooCompatiblefooLike){returnfooLike.ToFoo();}}interfaceIFooCompatible{FooToFoo();voidFromFoo(Foofoo);}classBar:IFooCompatible{publicFooToFoo(){returnnewFoo();}publicvoidFromFoo(Foofoo){}}classProgram{staticvoidMain(strin

c# - 如何通过反射获取接口(interface)基类型?

publicinterfaceIBar{}publicinterfaceIFoo:IBar{}typeof(IFoo).BaseType==null如何获得IBar? 最佳答案 Type[]types=typeof(IFoo).GetInterfaces();编辑:如果你特别想要IBar,你可以这样做:Typetype=typeof(IFoo).GetInterface("IBar"); 关于c#-如何通过反射获取接口(interface)基类型?,我们在StackOverflow上找到

c# - 如何通过反射获取接口(interface)基类型?

publicinterfaceIBar{}publicinterfaceIFoo:IBar{}typeof(IFoo).BaseType==null如何获得IBar? 最佳答案 Type[]types=typeof(IFoo).GetInterfaces();编辑:如果你特别想要IBar,你可以这样做:Typetype=typeof(IFoo).GetInterface("IBar"); 关于c#-如何通过反射获取接口(interface)基类型?,我们在StackOverflow上找到

c# - 如何获取接口(interface)方法的MethodInfo,实现了类方法的MethodInfo?

我有一个接口(interface)方法的MethodInfo和一个实现的类的Type界面。我想找到实现接口(interface)方法的类方法的MethodInfo简单的method.GetBaseDefinition()不适用于接口(interface)方法。按名称查找也不起作用,因为当显式实现接口(interface)方法时,它可以有任何名称(是的,不是在C#中)。那么什么是正确的方法来覆盖所有的可能性? 最佳答案 好的,我找到了一个方法,使用GetInterfaceMap.varmap=targetType.GetInterfa