草庐IT

project_type

全部标签

c# - 如何为 "T must be a reference type"编写单元测试?

考虑:classMyClasswhereT:class{}在这种情况下,where子句强制执行MyClass只是引用类型的泛型的规范。理想情况下,我应该有一个测试此规范的单元测试。然而,这个单元测试显然行不通,但它解释了我想要完成的事情:[Test][DoesNotCompile()]publicvoidT_must_be_a_reference_type(){vartest=newMyClass();}如何测试通过不允许代码编译实现的规范?编辑:更多信息:好的,所以我这样做的理由(哈哈)是我一直在遵循TDD方法,在这种方法中,除非单元测试失败,否则您不能编写任何代码。假设您有这个:c

c# - 可访问性不一致 : return type is less accessible than method C#

好吧,这真的很奇怪。我有一个私有(private)成员,我想将它用于Form2。我创建了一个公共(public)静态方法,以便我可以将该成员放入Form2。这是我的代码:privatestaticAppControllerappController;privateBreadRepositorybreadRep;privateCakeRepositorycakeRep;privateSandwichRepositorysandwichRep;publicForm1(){InitializeComponent();breadRep=newBreadRepository();cakeRep=

c# - 在 C# 中,Type.FullName 何时返回 null?

MSDNforType.FullName说这个属性返回nullifthecurrentinstancerepresentsagenerictypeparameter,anarraytype,pointertype,orbyreftypebasedonatypeparameter,oragenerictypethatisnotagenerictypedefinitionbutcontainsunresolvedtypeparameters.我数了五种情况,发现一个比一个更不清楚。这是我尝试构建每个案例的示例。usingSystem;usingSystem.Collections.Gene

c# - "new"inside concrete type projection 只被调用一次

我有简单的Linq2Sql查询:varresult=fromtinMyContext.MyItemsselectnewMyViewModelClass(){FirstProperty=t,SecondProperty=newSomeLinq2SqlEntity()}问题是newSomeLinq2SqlEntity()似乎只对该序列执行一次,因此查询结果中MyViewModelClass的所有实例共享链接到一个对象。更新:这是我快速检查它的方法:result[0].SecondProperty.MyField=10;使用调试器,我可以检查MyField在所有情况下都设置为10。当我用fo

c# - 元素 <Import> 中的 ""属性的值 "Project"无效。 vs2012

尝试在visualstudio2012中加载一些项目时出现以下错误:G:\path\project.csproj:error:Thevalue""ofthe"Project"attributeinelementisinvalid.Parameter"path"cannothavezerolength.我正在尝试在svn结帐后重新启动机器。这些项目可以正确加载到其他机器上。有人可以帮我解决这个问题吗?Google没有给我答案,我希望它会。编辑这是csproj文件的相关部分。 最佳答案 你写的是从新开始的。我怀疑StyleCop没有安装

c# - Content-Type 字符集是否未从 HttpResponseMessage 公开?

我正在将一些代码从使用HttpWebRequest转换为HttpClient。我遇到的一个问题是从内容类型响应header获取字符集。使用HttpWebRequest时,字符集在HttpWebResponse.CharacterSet属性中公开,如下所示using(WebResponseresponse=awaitthis.webRequest.GetResponseAsync()){stringcharacterSet=((HttpWebResponse)response).CharacterSet;您还可以从WebResponse.ContentType属性或从HttpWebRes

c# - "Unable to cast object of type ' System.Net.Http.Formatting.JsonContractResolver ' to type ' Newtonsoft.Json.Serialization.DefaultContractResolver '."

我们有一个最近被转移到新服务器的WEBAPI项目。在对项目的有效负载进行一些添加后,我正在运行我的项目,但它突然抛出以下错误:Unabletocastobjectoftype'System.Net.Http.Formatting.JsonContractResolver'totype'Newtonsoft.Json.Serialization.DefaultContractResolver'.有问题的代码行在global.asax中:protectedvoidApplication_Start(){GlobalConfiguration.Configure(WebApiConfig.R

c# project-wide 使用别名指令

C#有一个叫做Usingaliasdirectives的特性.他们允许你做一个像这样的类型的别名:usingCustomerId=MyComp.MyProject.Core.EntityKey;然而,此功能仅适用于每个文件。我正在寻找一种方式-任何方式-在整个项目甚至整个解决方案范围内执行此操作。我想这样做的原因是因为我想删除像EntityKey这样的文字的冗长,EntityKey等。我喜欢避免在每个文件中定义这些别名。EntityKey是struct,所以我无法创建派生类。 最佳答案 不,那不存在。别名严格针对每个文件。

c# - ASP.NET MVC : Views using a model type that is loaded by MEF can't be found by the view engine

我正在尝试创建一个框架,以允许将Controller和View动态导入到MVC应用程序中。到目前为止,它是这样工作的:我正在使用.NET4、ASP.NETMVC3RC和RazorViewEngine每个项目都使用MEF导出和导入Controller-我将给定项目中的一组Controller和View称为“模块”BuildManager使用应用前启动方法和BuildManager.AddReferencedAssembly动态引用使用MEF发现的程序集。使用构建事件将二进制文件(来自导出项目)和View复制到目标项目的文件夹结构中使用自定义Controller工厂选择Controller

c# - 为什么这段代码会提示 "the arity of the generic type definition"?

我有一个通用类型:classDictionaryComparer:IEqualityComparer>还有一个工厂方法,它将(应该)为给定的字典类型创建此类的实例。privatestaticIEqualityComparerCreateDictionaryComparer(){Typedef=typeof(DictionaryComparer);Debug.Assert(typeof(T).IsGenericType);Debug.Assert(typeof(T).GetGenericArguments().Length==2);Typet=def.MakeGenericType(ty