草庐IT

int-type

全部标签

c# - 使用 XmlSerializer 反序列化 List<int> 导致额外的项目

我注意到XmlSerializer和通用列表(特别是List)有一个奇怪的行为。我想知道是否有人以前见过这个或知道发生了什么。看起来序列化工作正常,但反序列化想要向列表中添加额外的项目。下面的代码演示了这个问题。可序列化类:publicclassListTest{publicint[]Array{get;set;}publicListList{get;set;}publicListTest(){Array=new[]{1,2,3,4};List=newList(Array);}}测试代码:ListTestlistTest=newListTest();Debug.WriteLine("I

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# - 为什么逗号在具有 InvariantCulture 的 int.Parse() 和 decimal.Parse() 中表现不同?

为什么:decimal.Parse("1,2,3,45",CultureInfo.InvariantCulture)返回小数12345,然而:int.Parse("1,2,3,45",CultureInfo.InvariantCulture)抛出异常?我希望逗号在相同的文化中得到相同的对待。如果decimal.Parse返回12345,为什么int.Parse不返回12345? 最佳答案 SeeNumberStylesint的默认NumberStyles是Integer:IntegerIndicatesthattheAllowLea

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# 和 SQL Server 中 int 到 guid 的不同转换

在C#和SQLServer中将int转换为guid时,我得到不同的值。在C#中我使用这个方法publicstaticGuidInt2Guid(intvalue){byte[]bytes=newbyte[16];BitConverter.GetBytes(value).CopyTo(bytes,0);returnnewGuid(bytes);}Console.Write(Int2Guid(1000).ToString());//writes000003e8-0000-0000-0000-000000000000在我使用的SQLServer中selectcast(cast(1000asva

c# - "The binary operator Add is not defined for the types ' System.String ' and ' System.String '."-- 真的吗?

尝试运行以下代码时:Expression>stringExpression=Expression.Lambda>(Expression.Add(stringParam,Expression.Constant("A")),newList(){stringParam});stringAB=stringExpression.Compile()("B");我收到标题中提到的错误:“二元运算符Add没有为类型‘System.String’和‘System.String’定义。”真的是这样吗?显然在C#中它有效。在C#中执行strings="A"+"B"是表达式编译器无法访问的特殊语法糖吗?

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

C#:将 '0' 转换为 int

我看到了这样一段代码:privatereadonlyobject[]m_Values={(int)0,(int)0};将0转换为int的想法是什么?它不是“默认”的int吗? 最佳答案 没有必要。我假设程序员以前被咬过。我会把它作为一个谜题发布,在这个程序中将调用哪个重载?usingSystem;classProgram{staticvoidMain(string[]args){Foo.Bar(0);Console.ReadLine();}}classFoo{publicstaticvoidBar(bytearg){Console.