草庐IT

protected_class_method

全部标签

c# - 如何使用反射获得重载的私有(private)/ protected 方法

usingSystem;usingSystem.Reflection;namespaceReflection{classTest{protectedvoidmethodname(inti){Console.WriteLine(("intheworldofthereflection-onlyi"));Console.Read();}protectedvoidmethodname(inti,intj){Console.WriteLine(("intheworldofthereflectioni,j"));Console.Read();}}classProgram{staticvoidMai

c# - 有没有办法从派生类型到达另一个对象的 `protected` 成员?

classMyBase{protectedobjectPropertyOfBase{get;set;}}classMyType:MyBase{voidMyMethod(MyBaseparameter){//Iamlookingfor:objectp=parameter.PropertyOfBase;//errorCS1540:Cannotaccessprotectedmember'MyBase.PropertyOfBase'viaaqualifieroftype'MyBase';thequalifiermustbeoftype'MyType'(orderivedfromit)}}有没有

c# - OOPS 概念 : What is the difference in passing object reference to interface and creating class object in C#?

我有一个类CustomerNew和一个接口(interface)ICustomer:publicclassCustomerNew:ICustomer{publicvoidA(){MessageBox.Show("Classmethod");}voidICustomer.A(){MessageBox.Show("Interfacemethod");}publicvoidB(){MessageBox.Show("ClassMethod");}}publicinterfaceICustomer{voidA();}我对这两行代码很困惑。ICustomerobjnew=newCustomerNe

c# - 将 ILMerge 与 log4net 一起使用会导致 "inaccessible due to protection level"错误

我为我的log4net日志记录对象的初始化创建了一个包装类,以便更容易地在ThreadContext中建立自定义属性。这发生在我与许多其他有用函数一起建立的类库中。为了加入所有不同的库,我还使用“/internalize”开关向ILMerge添加了一个AfterBuild目标。ILMerge所针对的库内对此初始化方法的所有引用似乎都工作正常。但是,当我在其他地方引用这个合并库时。我的实现会引发保护级别错误。我已尝试向可选的排除(/internalize:excludes.txt)文件中添加各种内容,但这似乎不起作用。excludes.txt示例:log4net.Configlog4ne

c# - protected 内部

这个问题在这里已经有了答案:HowtomakeapropertyprotectedANDinternalinC#?(8个答案)关闭9年前。MSDN上的C#语言引用将“protected内部”定义为“访问仅限于当前程序集或从包含类派生的类型”。但从语义的角度来看,“protected内部”对我来说听起来像是“既protected又内部”,这意味着该成员只能由同一程序集中的那些派生类访问。是否有具有相同含义的访问修饰符?

c# - ASP.net Web API : change class name when serializing

我有一个产品的数据传输对象类publicclassProductDTO{publicGuidId{get;set;}publicstringName{get;set;}//Otherproperties}当Asp.net序列化JSON(使用JSON.NET)或XML中的对象时,它会生成ProductDTO对象。但是,我想在序列化期间更改名称,从ProductDTO到Product,使用某种属性:[Name("Product")]publicclassProductDTO{[Name("ProductId")]publicGuidId{get;set;}publicstringName{

C# 设计 : Why is new/override required on abstract methods but not on virtual methods?

为什么抽象方法需要new/override而虚方法不​​需要?示例1:abstractclassShapesClass{abstractpublicintArea();//abstract!}classSquare:ShapesClass{intx,y;publicintArea()//Error:missing'override'or'new'{returnx*y;}}编译器会显示这个错误:要使当前成员覆盖该实现,请添加override关键字。否则添加新关键字示例2:classShapesClass{virtualpublicintArea(){return0;}//itisvirt

c# - 低级差异 : non-static class with static method vs. 静态类与静态方法

我想知道使用具有静态方法的非静态类与具有相同静态方法的静态类的一般好处(或缺点)是什么,除了我不能使用非静态类中的静态方法作为扩展方法。例如:classNonStaticClass{publicstaticstringGetData(){return"Thiswasinvokedfromanon-staticclass.";}}与此相比:staticclassStaticClass{publicstaticstringGetData(){return"Thiswasinvokedfromastaticclass.";}}使用一种方法优于另一种方法对性能/内存有何影响?注意:假设我不需要

c# - 使用 Assembly.GetType ("MyCompany.Class1.Class2") 返回 null

我正在尝试使用Assembly.GetType("MyCompany.Class1.Class2")从字符串中动态获取类型。Assembly.GetType("MyCompany.Class1");按预期工作。如果我将一个类嵌入到另一个类中,例如:namespaceMyCompany{publicclassClass1{//.....publicclassClass2{//.....}}}并尝试获取类型Class2Assembly.GetType("MyCompany.Class1.Class2")将返回一个空值。我正在使用.NETFrameworks3.5SP1有谁知道我做错了什么以

c# - Resharper 中的警告 "Return value of pure method is not used"

我有一个快速的问题,关于我正在工作的c#项目中从VisualStudio中的Resharper收到的警告。警告是:"ReturnValueofpuremethodisnotused"发生这种情况的方法如下:privatestaticboolFilePathHasInvalidChars(stringuserInputPath){try{//thisiswherethewarningoccurs:Path.GetFullPath(userInputPath);}catch(Exceptione){Log.Error(String.Format("TheProgramfailedtorun