草庐IT

non-passphrase-protected

全部标签

c# - 如何使用最小起订量测试调用 protected 助手的代码

我目前运行的测试如下所示://InBlah.cspublicclassClassUnderTest{publicboolMethodUnderTest(){//Doabunchofstuff...returnHelperMethod();}protectedvirtualboolHelperMethod(){boolsuccess=false;//ProprietaryHardwareAccess.//DatabaseCalls.//FileSystemModifications.returnsuccess;}}//InTestBlah.cspublicclassTestStub:Cl

c# - LINQ to SQL insert-if-non-existent

我想知道是否有更简单的方法来插入表中尚不存在的记录。我仍在努力培养我的LINQtoSQL技能。这是我得到的,但似乎应该有更简单的方法。publicstaticTEntityInsertIfNotExists(DataContextdb,Tabletable,Funcwhere,TEntityrecord)whereTEntity:class{TEntityexisting=table.SingleOrDefault(where);if(existing!=null){returnexisting;}else{table.InsertOnSubmit(record);//Can'tuse

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

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

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# - 声明 protected 成员的静态类

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

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# - 将 ILMerge 与 log4net 一起使用会导致 "inaccessible due to protection level"错误

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

c# - Entity Framework : Alternate solution to using non primary unique keys in an association

我知道EntityFramework不允许您使用非主唯一键作为外键关联从数据库生成模型。我可以手动修改EDMX吗?如果是这样,有人可以给我一个例子或引用吗?如果不是,还有其他可能吗?最简单的例子:这是表的DDL。您会注意到我有一个从PersonType.TypeCode到Person.TypeCode的外键CREATETABLE[dbo].[PersonType]([PersonTypeId][int]NOTNULL,[TypeCode][varchar](10)NOTNULL,[TypeDesc][varchar](max)NULL,CONSTRAINT[PK_PersonType]

c# - protected 内部

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