草庐IT

make_new_type

全部标签

c# - 在 C# 项目 : resolving type collisions 中包含 FSharp.Core

我正在使用C#中的某些F#类型(Matrix等),因此我需要在我的C#项目中引用FSharp.Core程序集。到目前为止,还不错。但是,显然有一些在mscorlib.dll(v4)中定义的类型在FSharp.Core(v2)中“重复”,例如System.Tuple和System.IObservable。我不明白为什么这是在.Net4中。MattEllisspecificallysaidtheywouldberemovedinhisMSDNarticle:Onelanguagesufferingthat[duplication]problemwasF#,whichpreviouslyha

c# - 通用约束 : Can I test Equality of generic that can be a reference or value type?

我想要一个通用类,它可以接受引用类型或值类型,并且只执行基于相等性测试的操作。考虑以下几点:publicclassPropertywhereTProp:struct,IEquatable{publicTPropValue;publicvoidSetValue(ObservableObjectowner,TPropvalue){if(!Value.Equals(value))//cannotuse!=onstructconstrainedTProp{//...settheproperty}}}publicclassByRefPropertywhereTProp:class//Dontwa

c# - 帮助我理解 "LINQ to Entities only supports casting Entity Data Model primitive types"

我有一个工作单元和一个使用EF4和POCO的存储库。由于EF在可以Skip()和Take()之前需要一个有序集,因此我添加了以下单元测试(没有模拟)只是为了提取一条记录以查看它是否有效。varmyList=UOW.EntityRepo.Get(orderbyLambda:p=>p.ID,page:1,pageSize:1);这导致表达式orderbyLambda={p=>Convert(p.ID)}和枚举期间的错误。ID是tinyint(Int16/短)那么为什么按ID排序失败呢?有关错误的更多信息Unabletocastthetype'System.Int16'totype'Syst

c# - 如何通过反射判断字段是否有 'new'修饰符?

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:HowdoIdetectthe"new"modiferonafieldusingreflection?有如下声明publicclassB:A{publicnewstringName;}我如何确定该字段的FieldInfo实例是否具有"new"修饰符?

c# - 通用类和 Type.GetType()

有点困惑,我有一个通用类publicabstractclassMyClass:UserControl{}我有一个这样的类型Typetype=Type.GetType("TypeFromDBasString",true,true);我想使用类型创建MyClass的实例...但这不起作用。MyClasscontrol=(MyClass)LoadControl("/UsercControl.ascx");有什么想法吗???? 最佳答案 像这样:TypetypeArgument=Type.GetType("TypeFromDBasStrin

c# - 温莎城堡 : Auto-register types from one assembly that implement interfaces from another

我使用CastleWindsor作为我的IoCcontainer.我有一个具有类似于以下结构的应用程序:MyApp.Services.dllIEmployeeServiceIContractHoursService...MyApp.ServicesImpl.dll员工服务:MyApp.Services.IEmployeeServiceContractHoursService:MyApp.Services.IContractHoursService...我使用XMLconfiguration目前,每次我添加一个新的IService/Service对时,我都必须向XML配置文件添加一个新组

c# - 接口(interface)继承和new关键字

我要:publicinterfaceIBase{MyObjectProperty1{get;set;}}publicinterfaceIBaseSub:IBase{newTProperty1{get;set;}}publicclassMyClass:IBaseSub{publicYourObjectProperty1{get;set;}}但这不能编译。它给出了错误://ThisclassmustimplementtheinterfacememberIBase.Property1任何人都可以阐明这一点吗?我认为它应该工作..谢谢 最佳答案

c# - 为什么在没有 new() 泛型类型约束的情况下允许 Activator.CreateInstance<T>() ?

在下面显示的示例代码中,“CompileError”方法不会编译,因为它需要whereT:new()CreateWithNew()中所示的约束方法。然而,CreateWithActivator()方法在没有约束的情况下编译得很好。publicclassGenericTests{publicTCompileError()//compileerrorCS0304{returnnewT();}publicTCreateWithNew()whereT:new()//buildsok{returnnewT();}publicTCreateWithActivator()//buildsok{ret

c# - 我可以做一个类型 "sealed except for internal types"

我想创建一个类型,该类型可以由同一程序集中的类型继承,但不能从程序集外部继承。我确实希望该类型在程序集之外可见。这可能吗? 最佳答案 您可以将构造函数设为内部:publicclassMyClass{internalMyClass(){}}每个派生自基类的类都必须在其构造函数中调用基类的构造函数。如果基类在不同的程序集中,则无法调用构造函数,因此派生类无法编译。 关于c#-我可以做一个类型"sealedexceptforinternaltypes",我们在StackOverflow上找到一

c# - 调试器可视化工具和 "Type is not marked as serializable"

我正在尝试创建一个调试器可视化工具,它会显示任何Control的控件层次结构。它已完成,但我收到异常“类型未标记为可序列化”。我该如何克服呢?控件是.NETWindows窗体框架类型,我无法将其标记为可序列化。 最佳答案 您还需要实现VisualizerObjectSource执行自定义序列化。例子:publicclassControlVisualizerObjectSource:VisualizerObjectSource{publicoverridevoidGetData(objecttarget,StreamoutgoingD