草庐IT

cross-references

全部标签

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# - 如何为 "T must be a reference type"编写单元测试?

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

c# - 使用 C# Cross Threading 设置标签值

我需要帮助来设置/更改我的C#程序中的标签值,每当我尝试它时都会发生错误,提示我需要将其全部交叉。任何人都可以编写一些代码来帮助我吗?我的代码是:intnumber=0;intrepeats=Convert.ToInt32(textBox2.Text);while(number谁能帮帮我?谢谢。 最佳答案 尝试以下更新值label5.Invoke((MethodInvoker)(()=>label5.Text="Requested"+repeats+"Times"));Invoke方法(来自Control.Invoke)将导致传入的

c# - 什么位置安装文件 - Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5

请耐心等待,我会尽量解释清楚。我开始了一个新项目(类库),目标是4.5而不是客户端配置文件4.5。我添加了一个引用“System.Runtime.Serialization”,属性表明它位于“C:\ProgramFiles(x86)\ReferenceAssemblies\Microsoft\Framework.NETFramework\v4.5\System.Runtime.Serialization”位置。dll”在我的电脑上,它可以通过使用msbuild的构建脚本正常编译。在使用teamcity的构建服务器上-它会提示errorCS0012:Thetype'System.Obje

c# - SOAP 错误 : "Server was unable to process request" "Object reference not set to an instance of an object"

当我向本地IIS中的服务发送SOAP请求时,一切正常。当我向在另一台主机上的IIS上运行的同一服务发送SOAP请求时,一切正常。但是当另一个程序员向我的服务发送SOAP请求时,他通常会得到正确的响应,除了返回服务中的一个方法:soap:ServerServerwasunabletoprocessrequest.--->Objectreferencenotsettoaninstanceofanobject.我需要了解他收到此错误的原因。他的SOAP请求与SOAP请求完全相同,但我的有效,而他的无效。 最佳答案 如果您不确切知道错

c# - 为什么这不触发 "Ambiguous Reference Error"?

publicclassA{publicvirtualstringGo(stringstr){returnstr;}}publicclassB:A{publicoverridestringGo(stringstr){returnbase.Go(str);}publicstringGo(IListlist){return"list";}}publicstaticvoidMain(string[]args){varob=newB();Console.WriteLine(ob.Go(null));}http://dotnetpad.net/ViewPaste/s6VZDImprk2_CqulF

c# - 未找到类型或命名空间 "are you missing assembly reference"而所有引用都正确

我正在尝试使用MSBuildWorkspaceclass.我的项目中有所有程序集引用。当我在对象浏览器中打开引用时,我看到了namespace和我尝试使用的类。但是在我接下来的using语句中,使用Microsoft.CodeAnalysis.MSBuild我得到一个Thetypeornamespacename'MSBuild'doesnotexistinthenamespace'Microsoft.CodeAnalysis'(areyoumissinganassemblyreference?)但有趣的是,语法高亮器识别类型名称,这是编译器的提示这是构建日志1>c:\windows\M

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# - 未经授权的访问异常 : Invalid cross-thread access in Silverlight application (XAML/C#)

C#相对较新,想尝试使用它来使用一些第三方Web服务API。这是XAML代码这是C#代码privatevoidButton_Click(objectsender,RoutedEventArgse){HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create("http://api.twitter.com/1/users/show/keykoo.xml");request.Method="GET";request.BeginGetResponse(newAsyncCallback(twitterCallback),request);}p

c# - OOPS 概念 : What is the difference in passing object reference to interface and creating class object in C#?

我有一个类CustomerNew和一个接口(interface)ICustomer:publicclassCustomerNew:ICustomer{publicvoidA(){MessageBox.Show("Classmethod");}voidICustomer.A(){MessageBox.Show("Interfacemethod");}publicvoidB(){MessageBox.Show("ClassMethod");}}publicinterfaceICustomer{voidA();}我对这两行代码很困惑。ICustomerobjnew=newCustomerNe