Wednesday, June 29, 2016

Component-oriented engine in C #

Independent components minimally know each other, who can perform only the goal - it's incredibly cool! On the initial sketches and ideas, I wrote in a previous post.

Since then, it happened to encounter new challenges, which forced to expand and modify the system.

All the advantages and disadvantages, as well as a small experience I will consider the example of a very simple 2D physics with gravity, forces and collisions. Welcome to a cat, my friends!

introduction

In his free time intensively engaged in his own project, which was created exclusively for the sake of learning, but because just teeming with bicycles. Probably the "engine" - one.

Note: of course, I understand that in the context of real problems it is advisable to take a ready-made solution and use it as the woodcutter takes the ax and chop wood to them. Just sometimes you want to understand how these axes, hell, are arranged.

Another way to implement a binding-computable properties in WPF

For example, there is a project in the WPF and the ViewModel in it, in which there are two properties of Price and Quantity, and computable property TotalPrice = Price * Quantity

Code
public class Order: BaseViewModel
    {
        private double _price;
        private double _quantity;
        public double Price
        {
            get {return _price; }
            set
            {
                if (_price == value)
                    return;
                _price = value;
                RaisePropertyChanged ( "Price");
            }
        }
        public double Quantity
        {
            get {return _quantity; }
            set
            {
                if (_quantity == value)
                    return;
                _quantity = value;
                RaisePropertyChanged ( "Quantity");
            }
        }
        public double TotalPrice {get {return Price * Quantity; }}
    }
    public class BaseViewModel: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void RaisePropertyChanged (string propertyName)
        {
            var propertyChanged = PropertyChanged;
            if (propertyChanged! = null)
                propertyChanged (this, new PropertyChangedEventArgs (propertyName));
        }
    }


If Price will be changed in the code, the price changes are automatically displayed in the View, because ViewModel View report of Price Change by calling the event RaisePropertyChanged ( «Price»). Computed TotalPrice did not change in the View, because no one is RaisePropertyChanged ( «TotalPrice»). You can call RaisePropertyChanged ( «TotalPrice») in the same places where called RaisePropertyChanged ( «Price») and RaisePropertyChanged ( «Quantity»), but do not want to spread over a plurality of information on places that TotalPrice depends on Price and Quantity, and I would like to store this information in one place. To this end, a variety of people write dependency management, but let's see what is the minimum code is actually needed for this.

Tuesday, June 28, 2016

Simply write a plugin for ReSharper

The goal: to write, test, and deploy a simple plug-in for R #, contains custom Quick-Fix and Context Action.

Article Plan:
Setting up the development environment
Example №1: the simplest extension stub
Installing the plugin
Debugging tips
Example №2: code modification using the R # API
Functional testing tools plugins R # API

Cast:
Visual Studio 2015
ReSharper Ultimate 10

I invite interested under the cut.

1. Setting up the development environment


The most simple and reliable implementation of the Dispose design pattern

It would seem that this pattern is not just easy, and very simple, not analyzed in detail in a well-known book.

However, so far, even within the same project, it can often be implemented in different ways, creating a zoo bicycles, crutches and leaks.

I would like to share their way of implementation, which is based on the minimization of the invention, a bike, a maximum reduction of the amount of code and increasing its expression and transparency.

Preconditions

No mixing managed and unmanaged resources

Monday, June 27, 2016

Chapter 2 Automatic calculation of the properties of computable representations of models in .NET

For example, to support the last-described relationship, the programmer must write a large number of routine code (the situation is even more complicated if there is a chain of dependence is not one, but several collections):

Subscribe to ObservableCollection changes (via INotifyCollectionChanged interface) representing Orders.
Subscribe to PropertyChanged each item in the collection (order) to monitor changes in the properties of Quantity.
Maintain the relevant subscription date: unsubscribe from the elements removed from the collection, and to subscribe to add, unsubscribe when you change an instance of the collection itself from an old collection, and to subscribe to the new event.

Automatic calculation of the properties of computable representations of models in .NET

Motivating the example representations of models for WPF UI

Start a discussion and get acquainted with the issues under discussion is offered as an example approach to architecture, user interfaces in WPF.

As you know, one of the main features WPF - bayndingov is a powerful system that allows easy enough to separate the model representation (the model) from the presentation (the View) as such. Typically, a programmer creates XAML to represent, bind properties of elements to the model in the same XAML by bayndingov and, in fact, forget about the View. This is possible because most UI-logic can be realized through the impact on the model and automatically prokinut on the UI by bayndingov. With this approach, the model plays the role of the state of View, as its proxy for a layer that implements the UI-logic. For example, changing the property of the model, we thereby change the corresponding property of the View (or its components). The latter occurs automatically thanks bayndingov system which tracks changes in the model and in View, synchronizing state at both ends as required. One of the ways in which the model can notify observers (whom in this case is baynding) of its change is throwing PropertyChanged event with the name of the changed property as parameter. This event belongs interface INotifyPropertyChanged, which, accordingly, must be implemented in the model.

Development on the .Net Solution Corp

Hello! The main speech will go about developing on .Net, that is, using Microsoft Visual Studio, ReSharper, Nuget and others.
I think many of you have developed great solutions (in msdn - solution), with many sub-projects. And in this case often becomes a problem of synchronization Nuget packages, build settings, etc. And, of ReSharper here to help little, except that he also begins to be confused in a variety of libraries.
To check the source code has been made an Open Source solution - SolutionCop, which is free to use.
For a start I will give a couple of examples of when not prevented verification of our solutions.

Example 1: The different versions Nuget libraries.

For example, there are three projects: exe, dll1 and dll2. exe refers to both libraries, each of which refers, for example, at RX. But dll1 uses RX 2.2.0, and dll2 - RX 2.2.5. In fact, you can not immediately get an error, because the function signature is more or less the same, moreover, MsBuild often collects projects at one and the same order. However, this configuration can lead to problems that appear after deployment'a when all the unit tests pass (as they refer only to your library), and when the result will prepare a set of files.