Skip to main content

Posts tagged with 'csharp'

Put some C# on Github!

May 05, 2014 mgroves 0 Comments
Tags: csharp git

Read GitHub language trends and the fragmenting landscape.

Here's a quote from that article: 

Both C# and Objective-C are unsurprisingly almost invisible, because they’re both ecosystems that either don’t encourage or actively discourage open-source code

I don't know if I could agree that either are being "actively discourage[d]" (certainly Jeremy Miller has some thoughts on the matter).

BUT, what I want to tell you today is: put your C# code on to GitHub today! Even if you don't think it's very good, it might help someone, it might help you get some more experience with git and GitHub, and it will certainly help bump up that C# graph.

Welcome to another "Weekly Concerns". This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.

If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.

One of my favorite VS extensions is SmartPaster. Often when I'm pasting something into Visual Studio, I'm pasting it into C# source code. It could be a long directory name, a JSON string, or some sort of template that's going into a StringBuilder. Doing this with plain copy/paste can be tedious because you need to escape certain characters, and often times VS or ReSharper can be uncooperative.

Instead, just install SmartPaster. You'll get a new right-click menu option: "Paste As", which lets you paste text as a literal string, a comment, or as a StringBuilder.

Screenshot of SmartPaster in Visual Studio

Here's an example of Paste As -> StringBuilder. Notice that it even does the string escaping for you (see the double quotes around "Paste As").

It's not useful every day, but it's a huge time saver when it is.

Based on a Twitter conversation with Seth Petry-Johnson about mocking/faking SqlException objects in .NET, I decided to go ahead and put what I had written into an open-source project on GitHub. I didn't spend much time on the name: I thought about Sharp Stick and Pointy Stick, but those repo names have already been taken! So, I thought about "stick" some more and remembered the famous line from Lady Macbeth: "screw your courage to the sticking place". Well, I guess I don't have much of a future in professional naming.

Since I was creating a repo anyway, I thought I'd throw a couple of other helpers in there. I put in some of my favorite ASP.NET / ASP.NET MVC helpers and an obscure little string helper. I'm not trying to remake PGK Extensions or anything--just putting some stuff out there that might help someone.

I should also note that the SqlExceptionHelper stuff isn't entirely original: I borrowed some code from a 2006 blog post by Rido, and just updated the reflection code since the private constructor has changed since then (and could possibly change again, since it's a private constructor in a sealed class).

Anyway, go check out Sticking Place on GitHub and let me know what you think.

I first used MvvmCross with Windows Phone 8, and XAML has a pretty good data-binding syntax already in place.

Switching over to Android, though, and the data binding didn't seem as straightforward. I was struggling just to bind a Button to an IMvxCommand.

So I checked out the MvvmCross documentation on Databinding (which, by the way, makes it seem like databinding is still very much a work in progress in MvvmCross), and I came across the idea of "Fluent Databinding" (as opposed to "Swiss Databinding", I guess). Instead of doing the binding in the AXML Android view markup, I could just do it in C# in the Android activity. Here's an example of binding a Button click event to an IMvxCommand in the viewmodel:

Note that the .For("Click") clause is actually optional, since "Click" seems to be the "default view property". But I chose to be explicit, especially for this example.

Matthew D. Groves

About the Author

Matthew D. Groves lives in Central Ohio. He works remotely, loves to code, and is a Microsoft MVP.

Latest Comments

Twitter