草庐IT

c# - 静态抛出类 : good or bad practice

抛出异常通常遵循以下模式:if(condition){throwexception;}你检查一个条件,如果条件满足,你抛出一个异常。所以,我想知道为它编写一个如下所示的静态类是否是个好主意:publicstaticclassThrow{publicstaticvoidIfNullOrEmpty(string@string,paramsobject[]parameters)whereT:Exception{Throw.If(string.IsNullOrEmpty(@string),parameters);}publicstaticvoidIfNullOrEmpty(IEnumerabl

c# - 在 C# 中抑制 "Member is never assigned to"警告

我有以下代码:ViewPortViewModel_Trochoid;publicViewPortViewModelTrochoid{get{return_Trochoid;}set{this.RaiseAndSetIfChanged(value);}}使用ReactiveUIINPC支持。编译器总是警告我Trochoid永远不会分配给并且永远为空。然而,由于RaiseAndSetIfChanged通过CallerMemberName支持执行的魔法,代码确实有效,但编译器是错误的。我如何干净地在我的代码中抑制这些警告? 最佳答案 Ho

c# - HttpClient : The uri string is too long

鉴于以下尝试将数据发布到生成PDF文件的Web服务,PDFrocket(顺便说一下,这很棒)。我收到错误消息无效的URI:uri字符串太长为什么有人会对POSTed数据强加任意限制?using(varclient=newHttpClient()){//Buildtheconversionoptionsvaroptions=newDictionary{{"value",html},{"apikey",ConfigurationManager.AppSettings["pdf:key"]},{"MarginLeft","10"},{"MarginRight","10"}};//THISLI

c# - 序列化异常 : Type is not resolved for member "..."

我一直在尝试将程序集动态加载到AppDomain。我需要这样做是因为我想动态调用一个方法,但在我的应用程序运行时不要保留DLL的句柄,以便在需要时可以替换它。但我收到此SerializationException异常:类型未解析成员“...”这是我的代码:AppDomaindomain=AppDomain.CreateDomain("TempAppDomain",null,AppDomain.CurrentDomain.SetupInformation);try{objectobj=domain.CreateInstanceFromAndUnwrap(dllPath,typeName)

c# - 新手 LINQ 问题 : Is Paging in LINQ Queries Possible?

是否可以在Linq查询中使用“分页”功能?假设我有一些这样的XML:ChoiceOneChoiceTwoChoiceThree...ChoiceForty-EightChoiceForty-NineChoiceFifty如果我想实现分页功能,我是否能够为LINQ查询提供一个偏移量,以便我可以从第11个元素开始并在第20个元素结束?如果是这样,如果数据是对象列表而不是XML,查询会有什么不同吗? 最佳答案 varq=fromXinChoices.Skip((page-1)*pageSize).Take(pageSize)selectX

C# 字符串.IsNullOrEmpty : good or bad?

在工作中我误用String.IsNullOrEmpty和Session变量后,我的一位同事现在拒绝接受我对String.IsNullOrEmpty的使用。经过一些研究,显然在MSDN(link)上为IsNullOrEmpty列出了一个错误(阅读底部的注释):AsofApril4,2006,thereisabug(possibleintheJIT)thatmakesthismethodfailwhenoptimizationsareturnedon.ItisknowntoaffectbothC#andVB.可以在此处找到更多信息(link)。微软这个错误“应该”在Orcas后修复,但不幸

c# - 公开课 - "is inaccessible due to its protection level. Only public types can be processed."

我正在做一个测试项目来了解对象的XML序列化,但我遇到了一个奇怪的运行时错误:namespaceSerializeTest{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidserializeConnection(Connconnection){XmlSerializerserializer=newXmlSerializer(typeof(Conn));TextWritertextWrit

c# - 无法加载文件或程序集 ':This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded

我在我的解决方案中有3个项目:BL、DL和UI。这三个项目的目标框架都是>NET4;我通过查看每个项目的属性页仔细检查了这一点。当我尝试在托管环境中运行网站时收到以下错误消息,但在本地运行时却没有。Couldnotloadfileorassembly'BL'oroneofitsdependencies.Thisassemblyisbuiltbyaruntimenewerthanthecurrentlyloadedruntimeandcannotbeloaded.提前致谢! 最佳答案 -转到IIS。-DefaultWebSite->Y

c# - 有没有办法将参数传递给 is 运算符?

我正在尝试找到以下替代方法,以便我可以利用is运算符。publicboolIsOfType(Typetype){returnthis._item.GetType()==type;}类似于下面的内容,无法编译。publicboolIsOfType(Typetype){returnthis._itemistype;} 最佳答案 我认为您正在寻找Type.IsAssignableFrom:publicboolIsOfType(Typetype){return_item!=null&&type.IsAssignableFrom(_item.

c# - 使用 FtpWebRequest 上传期间 "Requested URI is invalid"

我正在尝试将文件上传到FTP服务器上的目录。我将此方法与FtpWebRequest一起使用。我想将一个文件上传到该用户的主目录,但我总是收到以下错误消息:TherequestedURIisinvalidforthisFTPcommand.有什么问题?我试过关闭被动模式,但还是一样。staticvoidFtpUpload(){//Gettheobjectusedtocommunicatewiththeserver.FtpWebRequestrequest=(FtpWebRequest)WebRequest.Create("ftp://12.22.44.45");request.Metho