Model View Presenters: Presenter to View Communication

Table of Contents: Introduction Presenter to View Communication View to Presenter Communication Composite Views Presenter / Application communication … Presenter to View Communication There are two styles utilised for populating the View with data from the Presenter and Model that I have used. The only difference between them is how tightly coupled you mind your View being to the Model. For the example of this, we will have the following as our Model:...

January 26, 2012 · 2 min

Working with XmlTextWriter

I was working on some code today that needs a lot of data writing into an XML document. The documents structure is not repetitive - it is loads of one time data, so templating the document is possible, but not the best route to go. To that end, it uses an XmlTextWriter. The problem I have with it is the way you must write sub-elements. If you just need a single value wrapped in a tag, you are catered for already:...

October 25, 2011 · 2 min

Noticing Changes

I work on a piece of software that has been around for about 6 years now, which looks something like this: The textboxes are validating that their contents, some as decimal, and some as integer. All the textboxes consider no-value to be invalid. I made a slight change to the control, which was to add a new row. Since adding that row, many users have sent in requests to have the validation changed on the textboxes, so that no-value is considered to be zero....

October 22, 2011 · 1 min

C# and Vb.Net Differences

So I have been doing some work that involves C# and VB libraries and apps using each other, and have noticed a lot of subtle differences between the two languages. Declaration of types inside an interface: Public Interface ITesting ReadOnly Property Test() As TestData Class TestData Public Sub New() StringProperty = "testing" IntProperty = 1234 End Sub Public Property StringProperty() As String Public Property IntProperty() As Integer End Class End Interface However in C#, you cannot declare types inside an interface, however it is quite happy to consume one create in a VB project:...

September 14, 2011 · 2 min

c# Enum casting

I am all for strong typing, and explicit casts, but some things in C# do seem to be a bit over-wordy. For instance, I would quite often have code that looks like the following in VB.Net: Public Enum Columns Name Value Action End Enum Private Sub InitialiseGrid(ByVal grid as SourceGrid.Grid) grid.ColumnCount = [Enum].GetValues(GetType(Columns)).Count grid.Columns(Columns.Name).AutoSizeMode = SourceGrid.AutoSizeMode.EnableAutoSizeView grid.Columns(Columns.Value).AutoSizeMode = SourceGrid.AutoSizeMode.EnableAutoSizeView | SourceGrid.AutoSizeMode.EnableStretch grid.Columns(Columns.Action).AutoSizeMode = SourceGrid.AutoSizeMode.None grid.Columns(Columns.Action).Width = 30 'etc... End Sub The problem arrives when you try to write the same in C#, specifically the part when accessing the Columns collection using the enum:...

August 9, 2011 · 2 min

Differences between Properties and Auto Properties

While writing some of the specs for ViewWeaver, I noticed that one was failing: When passed a type with one write only property it should return no mappings When I stepped through the code, it was indeed not filtering out the write only property. This is the code used to find all readable properties: var allProperties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public); var readableProperties = allProperties.Where(p => p.CanRead && !p.GetIndexParameters().Any()); For some reason CanRead was returning true, then I noticed how I had defined my class under test:...

July 11, 2011 · 1 min

(Miss)Use of Narrowing-Implicit Operators

I have covered a use of Narrowing/Implicit Operators before, but I was thinking the other day about use of Fluent Interfaces, and if it was possible to have one on a cache/repository type class, that would allow you to chain options together, but stop at any point and have the result. I gave it a go, and came up with this: public class Person { public string Name { get; set; } public int Age { get; set; } public Person(string name, int age) { this....

March 17, 2011 · 2 min

Expression Rules, Version 2

Recently I have written a rules engine for a very large menu system in an application I work on. Many of the rules apply many items, so I didn’t wish to have to express the same rule many times. To avoid this, the rule engine DSL was born: Concerns.When(item => /* rule of some sort */) .AppliesToAll() .Except(MenuItems.ToggleHidden, MenuItems.Refresh) And rules are rolled together, so a specific menu item must have all of its rules evaluating to true to be displayed....

February 9, 2011 · 2 min

Adding MSpec to your Git Bash

My workflow involves Visual Studio, Notepad++ and Git Bash. I don’t use much Visual Studio integration, and prefer to run most things from the command line. Now when it comes to testing projects, my tool of choice is MSpec (Machine.Specifications), which I decided would be nice if I could run from my Git Bash. $ mspec bin/project.specs.dll To do this, you need to write a Shell Script with the following contents:...

November 13, 2010 · 1 min

Databinding to a DataGridView - The order of columns

A while ago I was writing a small history grid in one of our applications at work. It has a single HistoryItem object, which is fairly straightforward, something like this: Class HistoryItem { public int ID { get{ return _id; } } public DateTime CreateDate { get { return _createDate; } } public String Creator { get { return _creatorName; } } public String Note { get { return _note; } } } This was populated into a List<HistoryItem> and bound to the DataGridView directly:...

October 20, 2010 · 2 min