posts - 19 , comments - 8 , trackbacks - 0

C#

Wpf TreeView MVVM view model

You can find my implementation of an MVVM TreeView model for WPF on github.

Link: https://github.com/rob-blackbourn/JetBlack.WpfTreeView.

Posted On Tuesday, May 19, 2015 9:34 AM | Comments (0) | Filed Under [ C# .Net MVVM TreeView WPF ]

Indexing a one dimensional array by n dimensions

There's an example on how to index a 1-dimensional array by n-dimensions on github.

Link: https://github.com/rob-blackbourn/JetBlack.ArrayIndexing.

Posted On Tuesday, May 19, 2015 9:31 AM | Comments (0) | Filed Under [ C# .Net Array Indexing ]

Network programming with reactive extensions

I've written some examples of using reactive extensions for network communication. You can find the project on github.

Link: https://github.com/rob-blackbourn/JetBlack.Network.

Posted On Tuesday, May 19, 2015 9:28 AM | Comments (0) | Filed Under [ C# Reactive Extensions rx .Net Network Socket Select TcpClient TcpListener ]

Monads in C#

I've written some example moands with practical examples. Checkout the github project.

Link: https://github.com/rob-blackbourn/JetBlack.Monads.

Posted On Tuesday, May 19, 2015 9:25 AM | Comments (0) | Filed Under [ C# .Net Monads ]

A timeout dictionary in C#
Overview My use case was a authentication system which stored user details. Fetching this information was expensive, so it was decided to only do this if the record was older than 15 minutes. The following code implements a dictionary were the values "timeout" after a given time period. The timeout dictionary The following code implements the dictionary. The constructor takes a date time provider which you can find in a previous post. This allows me to pass in a faster implementation of DateTime, ......

Posted On Friday, December 19, 2014 9:17 AM | Comments (1) | Filed Under [ C# TimeoutDictionary ]

Testing code with time dependency in C#
Introduction Testing code that is date or time dependent is clearly problematic! The first step is to create an interface which we will use instead of accessing the DateTime object itself. The interface using System; namespace JetBlack.Common.Timers { public interface IDateTimeProvider { DateTime Today { get; } DateTime Now { get; } long Ticks { get; } } } A native date time provider We can wrap up the standard date time object with the following code. using System; namespace JetBlack.Common.Timers ......

Posted On Thursday, December 18, 2014 4:55 PM | Comments (0) | Filed Under [ C# DateTime Testing ]

Array pooling in C#
Introduction The following class reduces garbage collection by maintaining a pool of allocated arrays. DisposableValue I wanted a simple way to manage the lifetime of the arrays. To do this I have borrowed an idea from reactive extensions using System; namespace JetBlack.Common { public class DisposableValue<T> : IDisposable { private readonly Action _dispose; public DisposableValue(T value, Action dispose) { _dispose = dispose; Value = value; } public T Value { get; private set; } public void ......

Posted On Thursday, December 18, 2014 3:57 PM | Comments (1) | Filed Under [ C# array ArrayPool ]

A Generic Assert Class for C#
Overview The following code provides a mechanism for creating asserts which throw a generic exception. My initial motivation was to express in a more concise way common argument and result checking code. For example the following code: public string Read(Stream stream, Encoding encoding, int count) { if (stream == null) throw new ArgumentNullException("stre... "The stream must be created."); if (encoding == null) throw new ArgumentNullException("enco... "The encoding must be specified."); if ......

Posted On Thursday, December 4, 2014 1:25 PM | Comments (0) | Filed Under [ C# Assert Generic ]

A Rational Number Class in C#
Overview The following code implements a rational number. The code I have split the code into partial classes to keep the functionality distinct.For the underlying types I have decided to use longs throughout as the main problem with rational numbers is overflow. Furthermore I have chosen to always reduce the fraction. This adds an overhead on each computation, but contains overflow problems. AlgorithmsThe first task is to write the greatest common divisor function. From my previous post I have established ......

Posted On Friday, November 14, 2014 11:02 AM | Comments (2) | Filed Under [ C# rational fraction ]

Evaluating the Greatest Common Divisor function in C#
Available Routines There are a number of basic routines. Two that are attributable to Euclid are the subtraction and modulus method. There is another routine be Stein which uses binary arithmatic. Lastly there is the "trial and error" version which is useful as a check on validity. The algorithms The algorithms are provided in the code below. using System; namespace JetBlack.Common { public static class GreatestCommonDivisor { public enum Algorithm { TrialAndError, EuclidModulus, EuclidModulusShort, ......

Posted On Friday, November 14, 2014 10:56 AM | Comments (0) | Filed Under [ C# GCD greatest common divisor ]

Full C# Archive

Powered by: