.net-4.0

What's the non-deprecated alternative to XmlDataDocument and XslTransform?

不羁的心 提交于 2020-01-12 15:52:36
问题 I am modifying some legacy code to try to eliminate warnings. XmlDataDocument and XslTransform both generate warnings that they are obsolete. In the case of XslTransform the suggested replacement is XslCompiledTransform , but no replacement is suggested for XmlDataDocument . How can I change this code to eliminate warnings in .NET 4: var xmlDoc = new System.Xml.XmlDataDocument(myDataSet); var xslTran = new System.Xml.Xsl.XslTransform(); xslTran.Load(new XmlTextReader(myMemoryStream), null,

What's the non-deprecated alternative to XmlDataDocument and XslTransform?

走远了吗. 提交于 2020-01-12 15:52:05
问题 I am modifying some legacy code to try to eliminate warnings. XmlDataDocument and XslTransform both generate warnings that they are obsolete. In the case of XslTransform the suggested replacement is XslCompiledTransform , but no replacement is suggested for XmlDataDocument . How can I change this code to eliminate warnings in .NET 4: var xmlDoc = new System.Xml.XmlDataDocument(myDataSet); var xslTran = new System.Xml.Xsl.XslTransform(); xslTran.Load(new XmlTextReader(myMemoryStream), null,

Entity Framework 5 - Enum based Discriminator for derived classes

孤者浪人 提交于 2020-01-12 14:34:09
问题 I have the following (abbreviated for clarity) - an enum, a base class with that enum, and two derived classes that set the enum to a specific value. public enum MyEnum { Value1, Value2 } public class MyBaseClass { public MyEnum { get; protected set; } } public class DerivedOne: MyBaseClass { public DerivedOne { MyEnum = MyEnum.Value1; } } public class DerivedTwo: MyBaseClass { public DerivedTwo { MyEnum = MyEnum.Value2; } } What I want to do, is have Entity Framework 5 automatically

Regular expression that matches all valid format IPv6 addresses

≡放荡痞女 提交于 2020-01-12 13:48:09
问题 At first glance, I concede that this question looks like a duplicate of this question and any other related to it: Regular expression that matches valid IPv6 addresses That question in fact has an answer that nearly answers my question, but not fully. The code from that question which I have issues with, yet had the most success with, is as shown below: private string RemoveIPv6(string sInput) { string pattern = @"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F

How to empty a BlockingCollection

≡放荡痞女 提交于 2020-01-12 13:34:10
问题 I have a thread adding items to a BlockingCollection . On another thread I am using foreach (var item in myCollection.GetConsumingEnumerable()) If there is a problem I want to break out of my foreach and my method and clear whatever is left in the BlockingCollection however I can't find a way to do it. Any ideas? 回答1: Possibly use the overload of GetConsumingEnumerable that takes a CancellationToken ; then, if anything goes wrong from the producing side, it can cancel the consumer. 回答2: I'm

BinaryFormatter can't find 'Assembly' upon deserialize in c#

放肆的年华 提交于 2020-01-12 08:49:09
问题 I have a program that serializes and deserializes calls, and when I try to attach my DLL to another program, it says: Unable to find assembly 'ASCOM.BHOProxy.Connector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=74643865492aa2e6'. I could understand if this was a reference problem or something, but the problem is that the code that throws the exception is in ASCOM.BHOProxy.Connector . I've thought of going with some kind of third party Serializer, but I'm not quite sure what to use. The

static constructors and BeforeFieldInit?

坚强是说给别人听的谎言 提交于 2020-01-12 08:43:14
问题 If a type has no static constructor, field initializers will execute just prior to the type being used— or anytime earlier at the whim of the runtime Why this code : void Main() { "-------start-------".Dump(); Test.EchoAndReturn("Hello"); "-------end-------".Dump(); } class Test { public static string x = EchoAndReturn ("a"); public static string y = EchoAndReturn ("b"); public static string EchoAndReturn (string s) { Console.WriteLine (s); return s; } } yields : -------start------- a b Hello

Item spacing in WPF ItemsControl

*爱你&永不变心* 提交于 2020-01-12 04:30:32
问题 I'm displaying a List<string> collection in an ItemsControl. The problem is that there is no spacing between the list items such as TheyAreAllNextToEachOther . How can I create some spacing between the items? <ItemsControl Grid.Column="2" Grid.ColumnSpan="2" ItemsSource="{Binding Path=ShowTimes}" BorderThickness="0"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel IsItemsHost="True" Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> 回答1: I'd

How to support async methods in a TransactionScope with Microsoft.Bcl.Async in .NET 4.0?

允我心安 提交于 2020-01-12 04:12:32
问题 I have a method similar to: public async Task SaveItemsAsync(IEnumerable<MyItem> items) { using (var ts = new TransactionScope()) { foreach (var item in items) { await _repository.SaveItemAsync(item); } await _repository.DoSomethingElse(); ts.Complete(); } } This of course has issues because TransactionScope doesn't play nice with async/await. It fails with an InvalidOperationException with the message: "A TransactionScope must be disposed on the same thread that it was created." I read about

How to support async methods in a TransactionScope with Microsoft.Bcl.Async in .NET 4.0?

主宰稳场 提交于 2020-01-12 04:12:06
问题 I have a method similar to: public async Task SaveItemsAsync(IEnumerable<MyItem> items) { using (var ts = new TransactionScope()) { foreach (var item in items) { await _repository.SaveItemAsync(item); } await _repository.DoSomethingElse(); ts.Complete(); } } This of course has issues because TransactionScope doesn't play nice with async/await. It fails with an InvalidOperationException with the message: "A TransactionScope must be disposed on the same thread that it was created." I read about