草庐IT

first-class-functions

全部标签

c# - CA2104 警告 : Is there any way to mark a class as `Immutable` to suppress it?

考虑下面的代码,它触发了CA2104:Donotdeclarereadonlymutablereferencetypes.publicclassTest{//ThisprovokesCA2104:"Donotdeclarereadonlymutablereferencetypes".protectedreadonlyImmutableClassImmutableMember;}publicclassImmutableClass{}有谁知道以一种可以抑制警告CA2104的方式将类标记为不可变的方法吗?我尝试用[ImmutableObject(true)]装饰MutableClass没有成

c# - 为什么 EF4 Code First 在存储对象时这么慢?

我目前正在研究db4o存储在我的Web应用程序中的使用情况。我很高兴db4o工作起来如此简单。因此,当我读到CodeFirst方法时,我有点喜欢它,因为使用EF4CodeFirst的方式与使用db4o非常相似:创建您的域对象(POCO),将它们扔到db4o中,然后永不回头。但是当我进行性能比较时,EF4慢得可怕。我不知道为什么。我使用以下实体:publicclassRecipe{privateList_RecipePreparations;publicintID{get;set;}publicStringName{get;set;}publicStringDescription{get

c# - FileLoadException 在 InitializeComponent 或 x :Class=

我在InitializeComponent方法中遇到文件加载器异常(第一次机会),或者调试器在多个WPF的xaml-root的x:Class属性处中断用户控制。尽管异常会大大降低导航速度,但一切正常。这是异常信息:Couldnotloadfileorassembly'Company.Solution.UserInterface,Version=0.1.5568.25577,Culture=neutral,PublicKeyToken=45069ab0c15881ce'oroneofitsdependencies.Thelocatedassembly'smanifestdefinitio

c# - 为什么具有 "where T : class"约束的 Generic<T> 方法接受接口(interface)

我有这个interface:publicinterfaceITestInterface{intTestInt{get;set;}}和这个通用方法(带有T:class约束):publicvoidTest()whereT:class{//DoSomething}这个电话:Test();一切都编译并运行,同时interface不是class(或者是吗?)。为什么会这样?我第一次看到这个是在我的WCF代理类上:publicpartialclassTestServiceClient:System.ServiceModel.ClientBase,TestNamespace.ITestService

c# - 代码契约(Contract) : Why are some invariants not considered outside the class?

考虑这个不可变类型:publicclassSettings{publicstringPath{get;privateset;}[ContractInvariantMethod]privatevoidObjectInvariants(){Contract.Invariant(Path!=null);}publicSettings(stringpath){Contract.Requires(path!=null);Path=path;}}这里需要注意两点:有一个保证Path属性永远不会为null的契约不变量构造函数检查path参数值以遵守先前的契约不变量此时,Setting实例永远不能有n

c# - 如何更改 EF Code First 中主键的名称?

我有一个场景,我想更改实体中的主键名称并能够运行update-database-force。请参阅下面的代码和尝试时出现的错误。实体是:publicclassTeam{[Key][HiddenInput(DisplayValue=false)]publicvirtualintId{get;set;}[Display(Name="FullName:")]publicvirtualstringName{get;set;}}实体更改为:publicclassTeam{[Key][HiddenInput(DisplayValue=false)]publicvirtualintTeamId{ge

c# - FirstOrDefault/First 和 OrderByDescending 是否比 LastOrDefault/Last 和 OrderBy 更快?

这个问题在这里已经有了答案:OrderBy().Last()orOrderByDescending().First()performance(6个答案)关闭9年前。我有一个LINQ问题,想知道是否有人知道答案。通常,如果我想查找按特定字段排序的记录,例如“最新添加的人”,我会这样写:MyCollection.OrderByDescending(x=>x.AddedDate).FirstOrDefault();最近我从团队中另一个喜欢写的开发人员那里接了一些工作:MyCollection.OrderBy(x=>x.AddedDate).LastOrDefault();所以我的问题是,按降

c# - Visual Studio express : free class diagram tool

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。关闭8年前。Improvethisquestion我正在使用c#express并希望使用免费工具来设计我的类图。您有什么推荐的免费工具?

c# - Entity Framework 5 Code First 自引用关系

如何在EntityFramework5中映射以下关系?publicclassItem{publicintId{get;set;}publicint?ParentItemId{get;set;}publicstringValue{get;set;}publicItemParentItem{get;set;}publicListChildItems{get;set;}}我已经试过了:protectedoverridevoidOnModelCreating(DbModelBuildermodelBuilder){base.OnModelCreating(modelBuilder);model

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