C# 7.0 Pattern Matching. Part1

1
Comments
C# 7.0 Pattern Matching. Part1

Great news! You can already try new C# 7.0 features. All you need is Visual Studio 15 Preview. Let's start! Today we are going to talk about Pattern Matching and will look under the hood of this nice feature. Unfortunately, it is only partly available in VS 15. So we need to wait until next release. Or you can try to get latest Roslyn from GitHub. is operator The is operator is extended to test an expression against a pattern. With that you can replace this: object obj = "Hello, World!...

Read further...

C# 7.0 Local Functions

10
Comments
C# 7.0 Local Functions

C# 7.0 is coming! Even 6.0 is not released yet, you can already try new C# 7.0 features. To do that you need: Visual Studio 15 preview Set __DEMO__ and __DEMO_EXPERIMENTAL__ as Conditional compilation symbol in project settings. Not all of the new features available in current preview, but you can already play with some of them. But today we gonna look closer at Local Functions private static void Main(string[] args) { int LocalFunction(int arg) { return 42 * arg; } Console.WriteLine(LocalFuncti...

Read further...

[Unity3d] Serialize and Deserialize System.Guid using JsonUtility

2
Comments
[Unity3d] Serialize and Deserialize System.Guid using JsonUtility

Unity3d 5.3.0 introduced JsonUtility class which will help you with JSON serialization and deserialization. But this class has some limitation, and one of them: "You cannot serialize\deserialize System.Guid type" That's a pity, especially if you're using System.Guid in your DTO objects. But, there are solutions: You can change a data type, for example, use System.String or System.UInt32 instead of System.Guid. But if you have a lot of code which uses your DTO objects it might be painful to refac...

Read further...

[ASP.NET Core 1.0] Automatic Migrations in Entity Framework 7 (EF Core 1.0)

1
Comments
[ASP.NET Core 1.0] Automatic Migrations in Entity Framework 7 (EF Core 1.0)

There is no more public Configuration() { AutomaticMigrationsEnabled = false; } in Entity Framework Core 1.0 (formerly  EF 7.0) Now you can use extension Migrate method during database initialization. For example, you have custom DBInitializer class: public class DBInitialization { public static void Initialize() { using (var context = new DbContext()) { context.Database.Migrate(); // Other db initialization code. } } } There is also async version of this method. This method will apply any pendi...

Read further...

ZohoPeopleTimeLogger v1.3 - Show me the error

0
Comments
ZohoPeopleTimeLogger v1.3 - Show me the error

At Novility, we have  found that we cannot log working time anymore. You just press "Make me happy" button and nothing :( When ZohoPeopleTimeLogger tries to make you happy it needs information about current jobs from ZOHO. For example, if I try to log time for January 16 and there is no job for this date I will get an error. But user was not able to see that error. That is fixed in release v1.3. Download GitHub User will see message box with detailed description and nice instructions:

Read further...

[IoT] Connect Intel Galileo Gen 2 to Arduino Uno via nRF24L01

1
Comments
[IoT] Connect Intel Galileo Gen 2 to Arduino Uno via nRF24L01

Guys from Newark element14 have sent me a nice dev board - Intel Galileo Gen2. I was curious because before, Microsoft declared that Windows 10 IoT Core will run on this board. I planned to run my previous benchmark on this board to see if it can beat Raspberry PI 2. Unfortunately, with the latest release they removed this board from the compatibility list :( But this is not a big problem because I have some plans about home automation and I can use this board in it. I have couple nRF24L01 modul...

Read further...

Build and test ASP.NET 5 application using AppVeyor

1
Comments
Build and test ASP.NET 5 application using AppVeyor

For those who do not know, AppVeyor is Continuous Integration and Deployment service for .NET projects. It is free for open-source projects. Currently, AppVeyor supports latest DNX version (1.0.0-rc1-final) and I've recently migrated my pet project to this version. I will show you how easy it is to build and run all unit tests on CI server every time you commit to GitHub. Visual Studio project (MSBuild) In LearnWordsFast project we are using Visual Studio 2015 as a development environment, so in...

Read further...

[ASP.NET 5] Lazy DBContext initialization with Entity Framework 7

2
Comments
[ASP.NET 5] Lazy DBContext initialization with Entity Framework 7

I will show you how to do lazy db context initialization with Entity Framework 7. The idea is simple, we need an easy way to get database context in a request. If db context was used in the request we should call SaveChanges method and dispose used context if not we shouldn't do anything. For "client", code should look like this: public class SomeRepository { private readonly IDbContext _db; public SomeRepository(IDbContext db) { _db = db; } public void Add(Item item) { _db.Current.Items.Add(ite...

Read further...

[WPF][MVVM] TreeView: Scroll To Selected Item

0
Comments

Here is the MVVM way to bring selected TreeViewItem into a view. First we need an attached behavior. We cannot use regular behavior because we will attach this property through Style. public class BringSelectedItemIntoViewBehavior { public static readonly DependencyProperty IsBringSelectedIntoViewProperty = DependencyProperty.RegisterAttached( "IsBringSelectedIntoView", typeof (bool), typeof (BringSelectedItemIntoViewBehavior), new PropertyMetadata(default(bool), PropertyChangedCallbac...

Read further...