草庐IT

non-matching

全部标签

c# - 挣扎于最小起订量 : The following setups were not matched

我是第一次使用Moq,我正在努力让测试正常运行。我正在尝试最小化服务层的Save()方法。publicvoidSave(UserViewModelviewModel){//todo:thisstilldoesn'taddressupdatingapassword.TheUserViewModeldoesn'tcontainanyPassworddata.if(viewModel.Id!=Guid.Empty){//TheUserIdisnotempty,we'reeitherupdatinganexistinguser//orwe'reinsertinganewuserviasyncv

c# - 数字必杀技 : Where does a callvirt of a non-existent method end up?

我在其基类中标记为抽象的库类上调用属性集访问器。现在在运行时我force应用程序针对另一个版本的库运行,其中类仅实现基类的底层接口(interface),但不是从它派生的。有趣的是,.NET将运行代码,但设置该属性没有任何效果。幕后发生了什么?违规代码:MyDbParameterparam=newMyDbParameter();param.ParameterName="p";Console.Out.WriteLine("ParameterName:"+param.ParameterName);库2.0(已编译)publicsealedclassMyDbParameter:System.

c# - Lazy<T> 延迟加载错误 : A field initializer cannot reference the non-static field, 方法或属性

我第一次尝试使用延迟加载来初始化我的类中的进度对象。但是,我收到以下错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.privateLazym_progress=newLazy(()=>{longtotalBytes=m_transferManager.TotalSize();returnnewProgress(totalBytes);});在.NET2.0中,我可以执行以下操作,但我更愿意使用更新的方法:privateProgressm_progress;privateProgressPro

c# - Regex.Matches c# 双引号

我在下面得到了这段适用于单引号的代码。它找到单引号之间的所有单词。但是我该如何修改正则表达式以使用双引号呢?关键字来自表单帖子所以keywords='peace"thisworld"wouldbe"andthen"some'//MatchallquotedfieldsMatchCollectioncol=Regex.Matches(keywords,@"'(.*?)'");//Copygroupstoastring[]arraystring[]fields=newstring[col.Count];for(inti=0;i 最佳答案

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# - NHibernate 3.1 NHibernate.Linq.NhRelinqQueryParser 异常 "Sequence contains more than one matching element"

我正在使用Nhibernate3.1/FluentNhibernate1.2当我使用CTRL+F5在Release模式下工作时,我没有遇到任何异常。但是在使用F5的Debug模式下会发生以下异常:此代码的控制台应用程序:_Session.Query().Where(x=>x.Bar=="bar").FirstOrDefault()异常(exception):System.TypeInitializationExceptionwasunhandledMessage=Thetypeinitializerfor'NHibernate.Linq.NhRelinqQueryParser'thre

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# - 枚举 MatchCollection 时,为什么 var 结果是 Object 类型而不是 Match 类型?

我注意到下面的代码有些奇怪:MatchCollectionmc=Regex.Matches(myString,myPattern);foreach(varmatchinmc)Console.WriteLine(match.Captures[0]);//变量match的类型是Object而不是Match。我习惯于使用var枚举集合,没有这样的问题。为什么MatchCollection不同? 最佳答案 MatchCollection是在.NET2之前编写的,所以它只是实现了IEnumerable而不是IEnumerable.但是,您可以

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# - 低级差异 : non-static class with static method vs. 静态类与静态方法

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