草庐IT

TYPE_CLASS_DATETIME

全部标签

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

c# - 如何在 C# 中减去两个通用对象 (T - T)(示例 : DateTime - DateTime)?

我写了一个通用类:publicclassIntervalwhereT:IComparable//forcheckingthatStart我将此类与DateTime、int等一起使用。我需要一个返回持续时间的Duration属性:publicobjectDuration{get{returnEnd-Start;}}但是当这个属性包含在我的类中时,编译器会在-运算符上引发一个逻辑错误。我该怎么做才能正常实现这个目标,或者我应该忽略它? 最佳答案 尝试这样的事情:staticvoidMain(string[]args){Tuplevalu

c# - 如何将两个字符串(日期和时间)合并为一个 DateTime

我有两个字符串:stringone="13/02/09";stringtwo="2:35:10PM";我想将这两者结合起来并转换为DateTime。我尝试了以下但它不起作用:DateTimedt=Convert.ToDateTime(one+""+two);DateTimedt1=DateTime.ParseExact(one+""+two,"dd/MM/yyHH:mm:sstt",CultureInfo.InvariantCulture);我该怎么做才能使这项工作成功? 最佳答案 这样试试;stringone="13/02/09"

c# - 如果没有可空 DateTime 的隐式运算符,为什么 C# 隐式转换为可空 DateTime?

这是一个关于C#语言或至少该语言在VisualStudio中是如何实现的问题。假设有一个Foo类,它为System.DateTime定义了一个隐式运算符publicstaticimplicitoperatorDateTime(Fooitem)考虑以下代码:Foofoo=SomeMethodWhichCanReturnNull();DateTime?dtFoo=foo;我的期望:编译失败提示没有从Foo到DateTime?的转换。我的发现:编译器实际上调用了从Foo到DateTime的已定义隐式运算符,并在传递null(它是转换器可以响应null的唯一方式)。当然,work-around

c# - DateTime.Parse 日期格式

我有一个用字符串表示的日期20130116154407我为此调用了DateTime.Parse,但它失败了。如何将其转换为DateTime?顺便说一句,时区是CET。编辑目前提供的解决方案非常有用,但似乎不支持24小时制,仍在寻找支持的解决方案。编辑2正确的格式是DateTime.ParseExact(str,"yyyyMMddHHmmss",CultureInfo.InvariantCulture)谢谢,萨钦 最佳答案 您需要指定格式:DateTime.ParseExact(str,"yyyyMMddHHmmss",Culture

c# - 通过反射仅获取当前类(class)成员

假设这段代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Reflection;namespaceTestFunctionality{classProgram{staticvoidMain(string[]args){//System.Reflection.Assembly.GetExecutingAssembly().LocationAssemblyassembly=Assembly.LoadF

c# - 从仅给定 Type 实例的 MEF 容器中获取导出

我有一个场景,我必须从我的CompositionContainer实例中导出,但我只有一个Type可以使用;我在编译时不知道类型,因此我无法以正常的通用方式检索导出的对象。通常你会这样做:_container.GetExportedObject();但就我而言,我有这个:TypesomeType=...;_container.HowDoIGetTheExport(someType);有什么想法吗? 最佳答案 找到答案:varexport=_container.GetExports(someType,null,null).FirstO

c# - 使用 System.Type 进行转换 - c#

是否可以使用System.Type?作为引用将对象转换为所需的类型?我进行了搜索,普遍的共识是否定的,尽管我希望C#4.0中引入的一些帮助可以帮助我。即以下将不起作用,但伪代码是我想要的。objecto=null;vart=typeof(string);...stringfoo=(t)o;编辑:我需要使用XmlSerializer来重构/反序列化为存储在t中的类型 最佳答案 看看:varfoo=Convert.ChangeType(o,typeof(string)) 关于c#-使用Sys