草庐IT

human-interface-guidelines

全部标签

c# - 在不考虑泛型类型参数的情况下检查类型是否实现了泛型接口(interface)

我有一个界面publicinterfaceMyInterface{}实现无关紧要。现在我想检查给定类型是否是该接口(interface)的实现。此方法失败publicclassMyClass:MyInterface{}但是我不知道怎么检查。publicvoidCheckIfTypeImplementsInterface(Typetype){varresult1=typeof(MyInterface).IsAssignableFrom(type);-->falsevarresult2=typeof(MyInterface).IsAssignableFrom(type);-->true}我

c# - C# 接口(interface)的非公共(public)成员

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭5年前。Improvethisquestion在C#中,当您实现一个接口(interface)时,所有成员都是隐式公开的。如果我们可以指定可访问性修饰符(protected、internal,当然private除外),那不是更好吗?或者我们应该只使用一个抽象类代替?

c# - C# 接口(interface)的非公共(public)成员

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭5年前。Improvethisquestion在C#中,当您实现一个接口(interface)时,所有成员都是隐式公开的。如果我们可以指定可访问性修饰符(protected、internal,当然private除外),那不是更好吗?或者我们应该只使用一个抽象类代替?

c# - 为什么在 C# 接口(interface)名称前加上 “I”

此命名约定背后的基本原理是什么?我没有看到任何好处。额外的前缀只会污染API。我的想法与Konrad的一致response与此相关question;选择answer其中大部分是我在这里要求的。 最佳答案 它完全相反,命名约定清楚地标识了一个接口(interface)。例如,如果您有:publicclassDog:IPet,IMammal{....仅通过阅读,我就可以有把握地假设IPet和IMammal可能是接口(interface)。.NETCLR允许单类继承。所以,如果我有一个基类……我只能从它继承一个类。让我们将IPet接口(i

c# - 为什么在 C# 接口(interface)名称前加上 “I”

此命名约定背后的基本原理是什么?我没有看到任何好处。额外的前缀只会污染API。我的想法与Konrad的一致response与此相关question;选择answer其中大部分是我在这里要求的。 最佳答案 它完全相反,命名约定清楚地标识了一个接口(interface)。例如,如果您有:publicclassDog:IPet,IMammal{....仅通过阅读,我就可以有把握地假设IPet和IMammal可能是接口(interface)。.NETCLR允许单类继承。所以,如果我有一个基类……我只能从它继承一个类。让我们将IPet接口(i

c# - 获取类实现的泛型接口(interface)的类型参数

我有一个通用接口(interface),比如IGeneric。对于给定的类型,我想找到一个类通过IGeneric实现的泛型参数。这个例子更清楚:ClassMyClass:IGeneric,IGeneric,IDontWantThis{...}Typet=typeof(MyClass);Type[]typeArgs=GetTypeArgsOfInterfacesOf(t);//Atthispoint,typeArgsmustbeequalto{typeof(Employee),typeof(Company)}GetTypeArgsOfInterfacesOf(Typet)的实现是什么?注

c# - 获取类实现的泛型接口(interface)的类型参数

我有一个通用接口(interface),比如IGeneric。对于给定的类型,我想找到一个类通过IGeneric实现的泛型参数。这个例子更清楚:ClassMyClass:IGeneric,IGeneric,IDontWantThis{...}Typet=typeof(MyClass);Type[]typeArgs=GetTypeArgsOfInterfacesOf(t);//Atthispoint,typeArgsmustbeequalto{typeof(Employee),typeof(Company)}GetTypeArgsOfInterfacesOf(Typet)的实现是什么?注

C#接口(interface)方法歧义

考虑以下示例:interfaceIBase1{intPercentage{get;set;}}interfaceIBase2{intPercentage{get;set;}}interfaceIAllYourBase:IBase1,IBase2{}classAllYourBase:IAllYourBase{intpercentage;intPercentage{get{returnpercentage;}set{percentage=value;}}}voidFoo(){IAllYourBaseiayb=newAllYourBase();intpercentage=iayb.Perce

C#接口(interface)方法歧义

考虑以下示例:interfaceIBase1{intPercentage{get;set;}}interfaceIBase2{intPercentage{get;set;}}interfaceIAllYourBase:IBase1,IBase2{}classAllYourBase:IAllYourBase{intpercentage;intPercentage{get{returnpercentage;}set{percentage=value;}}}voidFoo(){IAllYourBaseiayb=newAllYourBase();intpercentage=iayb.Perce

c# - 异常(exception)是 : InvalidOperationException - The current type, 是一个接口(interface),无法构造。您是否缺少类型映射?

在我的Bootstrap中:namespaceConduit.Mam.ClientServices.Common.Initizliaer{publicstaticclassInitializer{privatestaticboolisInitialize;privatestaticreadonlyobjectLockObj=newobject();privatestaticIUnityContainerdefaultContainer=newUnityContainer();staticInitializer(){Initialize();}publicstaticvoidInitia