草庐IT

protected_class_method

全部标签

c# - 测试和模拟私有(private)/ protected 方法。许多帖子,但仍然无法使一个示例起作用

我看过很多关于“Mockingaprivatemethod”的帖子和问题,但仍然无法让它工作,也没有找到真正的答案。让我们忘记代码的味道,你不应该这样做等等......据我所知,我做了以下事情:1)创建了一个类库“MyMoqSamples”2)添加了对Moq和NUnit的引用3)编辑AssemblyInfo文件并添加[装配:InternalsVisibleTo(“DynamicProxyGenAssembly2”)][程序集:InternalsVisibleTo("MyMoqSamples")]4)现在需要测试一个私有(private)方法。因为它是一个私有(private)方法,所以

c# - 如何修复 'compiler error - cannot convert from method group to System.Delegate' ?

publicMainWindow(){CommandManager.AddExecutedHandler(this,ExecuteHandler);}voidExecuteHandler(objectsender,ExecutedRoutedEventArgse){}错误1​​参数2:无法从“方法组”转换为“System.Delegate” 最佳答案 我猜有多个具有不同签名的ExecuteHandler。只需将您的处理程序转换为您想要的版本:CommandManager.AddExecuteHandler(this,(Action)

c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge

C# "Method not found"未使用反射的运行时异常

我在获取上述异常时遇到问题。我有一个相对简单的结构,分为两个dll。第一个包含一个IEntityService,IEntity,具有基本的实现。第二个包含实际的实现和接口(interface)。所以有一个实现IEntityService的IMachine服务和实现IEntityService和EntityService的MachineService。结果集合(实体加服务)也会发生类似的情况。此外,服务(机器和结果)是部分类/接口(interface),其中一个类是自动生成的。现在,在其中一台ResultMachine中,我试图获得一台机器,如果它不存在,我将创建它并保存。但是,当我尝试

c# - 声明 protected 成员的静态类

我正在看书"C#Language",然后点击VladimirReshetnikov的这张便条:Ifastaticclassdeclaresaprotectedorprotectedinternalmember,acompile-timeerroroccurs(CS1057).我可以知道为什么吗?具有protected成员的静态类有什么问题?静态类可以有私有(private)成员,所以我猜这个CS1057错误不是由于可访问性引起的,但也许是由于编译问题引起的?作为protected成员可以在子类中被覆盖...但我不明白为什么。 最佳答案

c# - 通过反射仅获取当前类(class)成员

假设这段代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Reflection;namespaceTestFunctionality{classProgram{staticvoidMain(string[]args){//System.Reflection.Assembly.GetExecutingAssembly().LocationAssemblyassembly=Assembly.LoadF

C#/N 休眠 : Association references unmapped class

几个小时以来,我一直在努力解决这个NHibernate问题。我在网络和NHibernate文档上进行了广泛的研究,但我无法理解这个问题。我对NHibernate比较陌生,但很喜欢它。不过,在那种情况下,它让我发疯。我正在为网站编写一个小型“投票”模块。我有几个类(Poll、PollVote和PollAnswer)。主要的Poll是导致问题的原因。这就是类的样子:publicclassPoll{publicvirtualintId{get;set;}publicvirtualSiteSite{get;set;}publicvirtualstringQuestion{get;set;}pu

c# - cs0030 :Unable to generate a temporary class

我有一个Web服务,当我尝试生成它的对象时出现以下错误。"Unabletogenerateatemporaryclass(result=1).errorCS0030:Cannotconverttype'ShortSell.ShortSellRQOriginDestinationInformationFlightSegment[]'to'ShortSell.ShortSellRQOriginDestinationInformationFlightSegment'errorCS0030:Cannotconverttype'ShortSell.ShortSellRSOriginDestina

c# - 公共(public)静态字符串 MyFunc() 上的 "Expected class, delegate, enum, interface or struct"错误。什么 's an alternative to "字符串”?

当我尝试使用以下静态函数时出现错误。错误:Expectedclass,delegate,enum,interface,orstruct函数(和类):namespaceMyNamespace{publicclassMyClass{//SomeotherstaticmethodsthatuseClasses,delegates,enums,interfaces,orstructspublicstaticstringMyFunc(stringmyVar){stringmyText=myVar;//DosomestuffwithmyTextandmyVarreturnmyText;}}}这导致

c# - 简单 QueryOver : Unrecognised method call

我有一个简单的QueryOvervarq=SessionInstance.QueryOver().Where(p=>p.Number.Equals(number));Number字段类型为int。此查询因此消息而出现运行时错误:Unrecognisedmethodcall:System.Int32:BooleanEquals(Int32) 最佳答案 ==运算符生成一个BinaryExpression可以将其转换为SQL并且.Equals()方法生成MethodCallExpression这显然没有转换为SQL。通常二元运算符在Que