草庐IT

sonata_type_datetime_picker

全部标签

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

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

c# - 将 Xamarin Forms 中的 DateTime 格式化为设备格式字符串

在运行PCLXamarin.Forms项目并且我的部署目标包括iOS、Android和Windows时,如何将DateTime对象格式化为设备默认日期时间格式的字符串。根据此thread,DateTime.ToShortString()无法按照MSDN要求工作还有这个bug.是否有任何基于表单的解决方案,或者我是否需要从特定于平台的项目中获取它?对于Android,我可以使用DI从native项目执行以下操作:Stringformat=Settings.System.GetString(this.context.ContentResolver,Settings.System.DateF

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# - 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# - DateTime.ParseExact 具有 7 位数字/一位或两位数字的月份

到现在为止,我认为我会理解DateTime.ParseExact的工作原理,但这令人困惑。为什么下一行返回false?DateTime.TryParseExact("2013122","yyyyMdd",CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None,outlastUpdate)月份也可以有两位数。我认为它应该能够理解它意味着2013年1月22日。为什么我走错了路?我是否遗漏了什么或者是否有简单的解决方法?与此同时,我正在使用这个不是很优雅但有效的解决方法:publicstaticDateTim

c# - 使用 Interlocked 的线程安全 DateTime 更新。*

我可以使用Interlocked.*同步方法来更新DateTime变量吗?我希望在内存中保留最后一次触摸时间戳。多个http线程将更新最后一次触摸DateTime变量。我很欣赏DateTime变量是被替换而不是更新的值类型。我能想到的最好的方法是将时间戳记作为一个long中的总滴答数classx{long_lastHit;voidTouch(){Interlocked.Exchange(ref_lastHit,DateTime.Now.Ticks);}} 最佳答案 选项1:使用带有Interlocked和DateTime.ToBin

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

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