Posts Tagged C#

A Better INotifyPropertyChanged Implementation

The INotifyPropertyChanged-interface and companions are a well know citizens of the .NET-framework. How do you implement this interfaces?. Does it look similar to this? public class Person : INotifyPropertyChanged { private string firstname = “”; /* Other fields for the properties */ public event PropertyChangedEventHandler PropertyChanged; public string Firstname { get { return firstname; } [...]

Read complete post

,

No Comments

LINQ: cast-catch

In this post I’ll explain a little catch in LINQ, which may some beginners fall into: What’s the difference between those two queries? IEnumerable<Person> listOfEntities = LoadData(); // First version of the query var resultV1 = from p in listOfEntities where p.Name.Contains("a") select p; // Second version of the query var resultV2 = from Person [...]

Read complete post

, ,

2 Comments

Soap & Skin, My Pal Satan, Erlang and nullptr

My Pal Satan is a little comedy web-series about a Donna and her roommate, Satan. However there are only six episodes =( On infoq.com a talk from Joe Armstrong about fault-tolerant systems and Erlang is avaible. Maybe this doesn’t affect many developers today, but I think in the future more and more systems need some [...]

Read complete post

, , , ,

No Comments

Brian Beckman and Erik Meijer: Reactive Framework

This wonderful talk with Erik Meijer and Brian Beckman about reactive programming was published recently on channel 9. It starts of with simple and familiar things, the IEnumerable-Interface (or Iterable in Java). Then comes a little math, explained with a wild mix of Haskell, C# and fictional programming languages. And at the end the circle [...]

Read complete post

, , , , ,

No Comments

Mocks for internal interfaces

Maybe you’ve already seen an exception like this: Castle.DynamicProxy.Generators.GeneratorException: Type is not public, so a proxy cannot be generated. Type: SpielWiese.IReportSender …stack-trace… at SpielWiese.TestSomething.ExpectReportsSend() in Program.cs: line 64 What I’ve tried is to create a mock-object with Rhino-Mock. Since this interface is only intended for usage within the assembly it’s declared as internal interface. So [...]

Read complete post

, , ,

No Comments

Argument Validation Utility

A while ago I’ve found a nice way to implement argument validation on the Paint.Net-blog. Its a fluent-interface like this: public void CallMe(object sender,int size, string name) { Validate.Begin() .IsType<Guid>(sender, “sender”) .BiggerThan(size, 0, “size”) .IsNotEmpty(name, “name”) .Check(); /*IMPL */ } If only condition fails, CallMe(Guid.NewGuid(), 2, “”); you get a normal exception: System.ArgumentException: The argument [...]

Read complete post

,

No Comments

Why I can’t wait to get dynamic in C#

Just wrote again really ugly reflection based code. In such moments I really wish that the ‘dynamic’-type is already here. I wanted to make this statement, but replace the MyServiceResolvedAtRuntime and ArgumentTypeResolvedAtRuntime with type I only know at runtime. private static void BuildArgumentProvider(ContainerBuilder builder) { builder.Register<Provider<MyServiceResolvedAtRuntime, ArgumentTypeResolvedAtRuntime>>( ctx => argument => ctx.Resolve<MyServiceResolvedAtRuntime>(new[] { new NamedPropertyParameter(“param”, [...]

Read complete post

,

No Comments

db4o object database

I’ve looked for a small embedded, easy to use data store for implementing my small software-engineering course project. Of course I’ve looked at MS SQL Server, which works great together with LINQ and the .NET world. However it isn’t small and lightweight. I’ve also tried Hibernate.NET, however the .NET version is way behind the Java-Version [...]

Read complete post

, ,

1 Comment

FxCop

I’m a fan of static analysis because whem I’m writing code in a statically typed language I want to get the most of it. So I’m a huge fan of IntelliJ IDEA’s code analysis and quick-fixes. Also FindBugs is useful and also open source. Of course there are even more sophisticated analyses, but it catches [...]

Read complete post

, , , ,

No Comments