Search This Blog

Sunday, April 30, 2017

.NET built in function to convert string to into Title Case

Although a simple task, I was exposed today (here) to a built in function in the framework that does the job.


string title = "war and peace";

TextInfo textInfo = new CultureInfo("en-US"false).TextInfo;
title = textInfo.ToTitleCase(title); //War And Peace

Wednesday, April 26, 2017

Wednesday, March 8, 2017

Adding a property to a json object (either at the beginning or at the end) using Newtonsoft

Somewhere in my app I receive a JSON object, and I needed to add to it a couple of additional properties. Appending them turned out to be pretty straightforward. To add them to the beginning was not that quick.

Here's the code that does both:

string json = @"
{
    a: '123',
    b: 'avraham',
    c: { c1: 1111, c2: 'dada' }
}
"
;


var jsObject = JObject.Parse(json);
jsObject.Add("newProp", JToken.FromObject("I am a form title"));

Console.WriteLine(jsObject.ToString(Newtonsoft.Json.Formatting.Indented));
Console.WriteLine("------------- Adding property to the beginning of JSON  -----------------");

/* ------ does not work ------*/
//jsObject.AddFirst(JToken.FromObject("{formTitle: 'aaaaa'}"));
//jsObject.AddFirst("d2d2d2");
//jsObject.AddAfterSelf(JToken.FromObject("{formTitle: 'aaaaa'}"));

JObject newJObject = new JObject
(
    new JProperty("formTitle""I am a form title"),
    jsObject.Properties()
);
Console.WriteLine(newJObject.ToString(Newtonsoft.Json.Formatting.Indented));
Console.WriteLine("--------- Merging two JObjects (if the properties exist, they will be replaced/overwritten, if not, added ----------");

JObject jObjII = JObject.Parse("{x: 'x Value'}");
jObjII.Merge(jsObject);

Console.WriteLine(jObjII.ToString(Newtonsoft.Json.Formatting.Indented));

Output:


Sunday, March 5, 2017

Stop Hot Keys for Input Language Automatic Changing/Resetting

Windows 10 introduced a very annoying "feature": automatically reset your hot keys for input languages.

And the solution is not at all intuitive. Here's what you need to do (solution taken from here):



  1. Region and Language Settings
  2. Additional Date, Time & Region Settings
  3. Change input methods (under Language)
  4. Advanced Settings (Left menu/options)

Then click on "Apply language settings to the welcome screen, system accounts and new user accounts", under section "Override for Windows diplay language".

Sorry providing the walkthrough in a textual way. Too much screens to screenshot this time...

Thursday, February 23, 2017

At-First-Glance Comparison between Xamarin and React-Native

I am nothing more than a beginner in mobile development, but I am leaving here my impressions after being assigned the task of setting up a dev environment in both Xamarin and React-Native and share what it felt like to create a hello world app and play a bit with the source.



Wednesday, February 22, 2017

Setting up a React-Native dev environment in Windows 10

After days trying, alternating sighs with enthusiastic exclamation marks, I... formatted my computer, threw all my coins in the fountain, and was set to try it for one last time.

This time heavenly miracles agreed to intercede in my favor, so I ended up running the Hello World app.

This post has one sole objective (apart from occasionally hinting that you should only try mobile development (I was assigned the task in my company to try Xamarin before) if you have given up all your dreams about computer science):

Following the official docs instructions should be enough to get you there (the time frame required is, on purpose, not mentioned, neither in their docs nor here. Otherwise no one will ever try it).
You will run into config problems, missing environment variables, but you should be able to get around.

The thing is: the only real successful setting that worked for me is:
  1. Running the app not from another command prompt, as suggested by the docs, but from Android Studio itself. When asked, pick the emulator of your choice
  2. Opening a command prompt, and running react-native start...  and... it works ! (All right, it does not crash fits better)
  3. To "develop", "simply" edit the project's android.js file. 
  4. After editing your js sources, you do not have to shut the emulator, rebuild the app with Android Studio, re-start react-native packager... you can leave all up and running - just hit R + R after focusing in the emulator so the app is rebuilt and refreshed.
Congratulations, we are now on the same boat.
You are welcome to leave a comment advising leading where to.

(I like the complete appocalipytic tone of this post. It came to life after some highly frustrated days :)

Wednesday, February 15, 2017

Why Edit and Continue is not working even though it is marked in Visual Studio ?

Because it is supported only in projects that has framework versions greater or equal to 4.5.1 (from here).

AND - your scenario is likely one of the following: