.net-4.5

Replacing words in a string with values from Dictionary in c#

别等时光非礼了梦想. 提交于 2020-03-23 02:27:24
问题 I have a simple dictionary like this: var fruitDictionary = new Dictionary<string, string> {Apple,Fruit}, {Orange, Fruit}, {Spinach, Greens} and I have a string like var fruitString = Apple Orange Spinach Orange Apple Spinach How to replace all occurrences of the particular word in that sentence with the matching-word from the dictionary? (i.e.) The above sentence should read Fruit Fruit Greens Fruit Fruit Fruit ? Any ideas is much appreciated. EDIT: I tried something like this: var

Directory.GetCurrentDirectory() returns different results based on command line arguments

纵饮孤独 提交于 2020-02-23 10:39:28
问题 I'm hoping someone can explain why Directory.GetCurrentDirectory() returns different results based on how I pass my command line arguments to the application (running with args vs dragging a folder over the app.exe) To jump right into it consider this piece of code: public class Program { static void Main(string[] args) { Console.WriteLine("The current directory is {0}", Directory.GetCurrentDirectory()); if(args != null && args.Any()) Console.WriteLine("Command line arguments are {0}", String

Workflow Foundation 4.5 “Expression Activity type 'CSharpValue`1' requires compilation in order to run.”

試著忘記壹切 提交于 2020-02-03 08:08:28
问题 I am working through the Getting Started Tutorial for WF45 and have run into a problem that looks to have been experience by other people, but not in the same way that I am experiencing it. I am hoping that someone else has a solution for me. When I work through the Tutorial, all is good till I have to run it from the workflow host. At that point the instantiation of the workflow fail and returns the following message. "Expression Activity type 'CSharpValue`1' requires compilation in order to

System.Tuple defined in multiple assemblies

烂漫一生 提交于 2020-02-03 05:29:05
问题 I just installed VS 11 within Windows 8. When I got the latest of a solution built with VS 2010, then built it, I'm getting this error (in VS 11): The predefined type 'System.Tuple' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll' I haven't been able to find an answer via Google. And I don't know what the "global alias" is. Those words are too generic to find via a

GCHandle.FromIntPointer does not work as expected

痴心易碎 提交于 2020-02-01 04:53:25
问题 Here's a very simple (complete) program for exercising the use of GCHandle.FromIntPointer: using System; using System.Runtime.InteropServices; namespace GCHandleBugTest { class Program { static void Main(string[] args) { int[] arr = new int[10]; GCHandle handle = GCHandle.Alloc(arr, GCHandleType.Pinned); IntPtr pointer = handle.AddrOfPinnedObject(); GCHandle handle2 = GCHandle.FromIntPtr(pointer); } } } Note that this program is essentially a transliteration of the procedure described in

ClickOnce Setup instantly stops executing

这一生的挚爱 提交于 2020-01-25 10:58:07
问题 I've got a problem with a ClickOnce Setup and have absolutely no idea what I'm doing wrong... I'm trying to publish a VSTO AddIn for Outlook 2013 using VS2012. However when I click on the Setup.exe created by the ClickOnce Publish the Setup shows the small installation window for about half a second and then instantly disappears again. This without showing any error message or generating any event log entries at all. The ClickOnce manifest is signed with a test certificate (self-signed

What do I need to change to implement SOLID design correctly?

ぃ、小莉子 提交于 2020-01-24 09:25:10
问题 I'm trying to learn SOLID design and think I have made a mistake. I think that the IItem interface does not follow Liskov substitution principle within my Player class however, I can't work out how to fix this. If I add a new interface drawing from IItem I would have to change Player's method to add a case to handle it. I would like for the Player class to only need one method for equip so need help understanding what I have done wrong and how to do it correctly. Simplified version of my

LateBinding - how to use it?

无人久伴 提交于 2020-01-23 17:33:44
问题 Currently I'm try to understand some of aspects regarding programming in C#. Now I'm learning LateBinding . I understand how to create some simple program like the one below. class Program { static void Main(string[] args) { Console.WriteLine("Try to do something with late bindings"); Assembly a = null; try { a = Assembly.Load("CarLibrary"); Console.WriteLine("1"); } catch (FileNotFoundException ex) { Console.WriteLine(ex.Message); } if (a == null) { CreateUsingLateBinding(a); } Console

How to use SOAP in Windows 8.1 apps and in Windows Phone 8 apps?

余生长醉 提交于 2020-01-22 03:10:08
问题 Is there some methods to create SOAP-requests and to get SOAP-responses in .net-4.5? Which extentions I should to install, if it's necessary? 回答1: You can use SOAP services via the "Add Service Reference" function in Visual Studio. Behind the scenes, this will call svcutil to convert the .wsdl into .cs service prototypes. The .Net Framework includes both WCF, which is the newer and recommended network communication framework, as well as .Net Remoting, which is more compatible with some non-

Deserialize a property as an ExpandoObject using JSON.NET

被刻印的时光 ゝ 提交于 2020-01-21 04:06:32
问题 For example, there's an object like the next one: public class Container { public object Data { get; set; } } And it's used this way: Container container = new Container { Data = new Dictionary<string, object> { { "Text", "Hello world" } } }; If I deserialize a JSON string obtained from serializing the above instance, the Data property, even if I provide the ExpandoObjectConverter , it's not deserialized as an ExpandoObject : Container container = JsonConvert.Deserialize<Container>(jsonText,