【c#-业务对象更改时自动刷新UI】教程文章相关的互联网学习教程文章

c# – NHibernate:删除的对象将通过级联重新保存.替换对象并删除旧对象【代码】

我试图替换ProgramItem上的TimeBlock对象,然后删除旧的TimeBlock对象.删除部分给我带来了问题.我有一些’相对’简单的nHibernate问题删除旧的TimeBlock对象. 例外:已删除的对象将通过级联重新保存(从关联中删除已删除的对象)[* .Mode.TimeBlock#15]15是oldTimeBlock的Id 我在解决这类问题时没有遇到任何问题我只是尝试了以下任何用法:oldTimeBlock.ProgramItems = new List<ProgramItem>(); programItem.TimeBlock = null;以任何...

c# – 使用EF和WebApi将父/子对象序列化【代码】

我在实体框架中有以下模型:public class Customer { [XmlIgnore] public virtual ICollection<Customer> Children { get; set; }public string Name { get; set; } }现在我尝试使用web api序列化它:public class CustomerController:ApiController {public HttpResponseMessage GetAll(){using (var tc = new DataContext()){List<Customer> allCustomers = tc.Customers.ToList();return Request.CreateResponse(HttpStatusCode...

c# – 如何在GC完成列表中列出所有对象?

我的程序崩溃,它是VS的可视化工具,因此,调试它非常困难,我试图进行转储并使用WinDbg来研究它,但它不成功. 所以,现在我尝试以编程方式将手放在该列表上,但我不知道如何.谢谢.解决方法:我不认为有办法通过.NET的托管框架类库(FCL)进入终结队列.我怀疑如果你想以编程方式而不是debugging with WinDbg这样做,你(就像WinDbg和类似的工具)将需要使用CLR的非托管调试&为此目的分析API. 看看ICORDebugGCReferenceEnum COM interface.您可以...

谈谈C#文件监控对象FileSystemWatcher使用感受

谈谈C#文件监控对象FileSystemWatcher使用感受 2017年07月07日 14:52:32 savagelin 阅读数:3530 最近在项目中有这么个需求,就是得去实时获取某个在无规律改变的文本文件中的内容。首先想到的是用程序定期去访问这个文件,因为对实时性要求很高,间隔不能超过1S,而且每次获取到文本内容都要去分发给WEB服务器做别的操作,而那个文本的写入有时候会频繁,1秒可能多次,但是也有可能在相当长一段时间内是没有任何写入的。 这样一来...

c# – 如何返回依赖于using语句链的对象?【代码】

我想写一个类似于这个的方法:C Make() {using (var a = new A())using (var b = new B(a)){return new C(b);} }这很糟糕,因为当方法返回时,c保持对已处置对象的引用. 注意: >一个实现IDisposable.> B实现IDisposable.> C确实如此因为C的作者声明C,所以不实现IDisposable没有b的所有权.解决方法:您的情况与我在查询数据库时看到的情况非常相似.在尝试分离逻辑时,您有时会看到如下代码:var reader = ExecuteSQL("SELECT ..."); wh...

c# – Azure Mobile Service TableController不返回内部对象【代码】

我正在创建一个基本(我的第一个)带有表存储的Azure移动服务来控制一个简单的事件应用程序.我的DataObjects由2个对象类型组成:Coordinator和Event,我希望Coordinators是一个单独的表,用于存储我不希望它在Events中被非规范化的特定信息,但是Events还有一个内部对象Location来存储事件的详细信息位置,但我想存储非规范化,因为我不想将此细节与事件分开维护. 这是我到目前为止的目标:DataObjests:public class Coordinator : Entit...

c# – 将2个字典项聚合成一个对象【代码】

我有一本包含评估答案的字典,如下所示:{{"question1", "7"},{"question1_comment", "pretty difficult"},{"question2", "9"},{"question2_comment", ""},{"question3", "5"},{"question3_comment", "Never on time"}, }但是我需要将得分项和评论项组合成一个对象,如下所示{{"question1", "7", "pretty difficult"},{"question2", "9", ""},{"question3", "5", "Never on time"}, }我想我需要使用Aggregate方法来解决这个问题,但我...

c# – nsubstitute收到调用特定对象参数【代码】

我有一个看起来像这样的类:public myArguments {public List<string> argNames {get; set;} }在我的测试中,我这样做:var expectedArgNames = new List<string>(); expectedArgNames.Add("test");_mockedClass.CheckArgs(Arg.Any<myArguments>()).Returns(1);_realClass.CheckArgs();_mockedClass.Received().CheckArgs(Arg.Is<myArguments>(x => x.argNames.Equals(expectedArgNames));但测试失败并显示以下错误消息:NSubstitut...

c# – 我可以阻止一个类被非抽象对象继承吗?【代码】

考虑以下类:public abstract class Planet {protected abstract Material Composition { get; } }public abstract class TerrestrialPlanet : Planet {protected override Material Composition{get{return Type.Rocky;}} } public abstract class GasGiant : Planet {protected override Material Composition{get{return Type.Gaseous;}} }有没有办法阻止非抽象对象直接从类Planet继承? 换句话说,我们可以强制执行任何直接从Pl...

c# – 如何在生成的JSON中省略/忽略/跳过空对象文字?【代码】

我正在使用Json.NET将复杂的C#对象图转换为JSON.由于忽略了对象中具有默认值的属性,我通常在输出中得到空对象文字,我想省略它. 例如:public class Sample {public int Value { get; set; }public string Name { get; set; } }public class ParentSample {// this property should never be null, hence the initializerpublic Sample Sample { get; } = new Sample(); }..var obj = new ParentSample(); // settings for indentat...

C#映射两个复杂的对象【代码】

我有四节课:public class Customer {public string FirstName { get; set; }public string LastName { get; set; }public List<Product> Product { get; set; } }public class Product {public int ProductNumber { get; set; }public string ProductColor { get; set; } }///////////////////////////////////////////////public class Customer_ {public string FirstName { get; set; }public string LastName { get; set; }pu...

c# – 在ICompareable中对接口引用对象的列表进行排序【代码】

我在使用list.Sort()时遇到了指向不同类型的接口引用列表的问题,但问题Sort a list of interface objects提供了以下解决方案解决方案interface IFoo : IComparable<IFoo> { int Value { get; set; } }class SomeFoo : IFoo {public int Value { get; set; }public int CompareTo(IFoo other){// implement your custom comparison here...} }在我的原始代码而不是IFoo从IComparable中获取我的课程从IFoo和ICompareable中获取,即i...

c# – Automapper:将JSON转换为对象列表【代码】

源对象(JSON,如果重要的话,使用JSON.NET):{"conum" : 1001,"name" : "CLN Industries Corporation","agencyName" : "Murphy, Holmes & Associates, LLC","sAA" : [{"code" : 247,"description" : "Mechanic\u0027s lien - Bond to Discharge - Fixed penalty - where principal has posted Performance and Pa"}, {"code" : 277,"description" : "Mechanic\u0027s lien - Bond to Discharge - Open Penalty - where principal has...

c# – 使用集合初始值设定项初始化WebControl对象的Attributes属性【代码】

我想初始化WebControl对象,内联,但对于某些字段,这有点棘手.例如,当我尝试初始化TextBox对象的Attributes属性时,如下所示:using System.Web.UI.WebControls; Panel panel = new Panel() { Controls = { new TextBox() { Attributes = { { "key", "value" } } } } };我收到错误:Cannot initialize type ‘07001’ with a collectioninitializer because it does not implement‘System.Collections.IEnumerable’知道在这种情况下...

c# – Json.Net:将属性序列化/反序列化为值,而不是对象【代码】

在另一个类中使用时,如何实现Id类的以下JSON表示?class Car {public StringId Id { get; set; }public string Name { get; set; } }class StringId {public string Value { get; set; } }// ---------------------------------------------// Desired representation { "Id": "someId", "Name": "Ford" }// Default (undesired) representation { "Id" : { "Value": "someId" }, "Name": "Ford" }解决方法:您可以为StringId添加Ty...