You can find the full code for this post here: http://www.puzzleframework.com/Roger/GenericMath.cs.txt The .NET framework lacks support for calculating with generic types. There is no way to ensure that a generic type supports operations like Add, Sub, Div and Mul etc. More about the problem can be found here: http://www.thescripts.com/forum/thread278230.html “They are not. There have been…More
Linq Expressions – Access private fields
In this post I will show how you can use Linq Expressions to access private(or public) class fields instead of using Reflection.FieldInfo. Normally when you want to access a field by its name on a type you have to resort to reflection. You will end up with something like this: FieldInfo field = MyType.GetField(“someField”,BindingFlags.NonPublic | ….…More
Linq to NPersist to MS Access
I’ve finally seen my own Linq support Live :-P Untill now I’ve only been emitting NPath quereis and verified that NPath is correct. The reason I havent tested it live untill now is that I only have my gaming machine to develop on atm. the dev machine is dead. Anyway, I’m trying it against NWind…More
Typed factories in C#3 – V2
This is a follow up on my previous post: http://rogeralsing.com/2008/02/21/typed-factories-in-c3-managed-new/ I’ve added support for property and field initializers. This makes it possible to call your factory like this: Person person = MyFactory.Create(() => new Person(“Roger”, “Alsing”) { Age = 32, SomeIntField = 4, SomeIntArray = new int[]{1,2,3} }); You can find the…More
Typed factories in C#3 – Managed “new”
One thing that always bothered me with factory methods in earlier versions of C# is that the only way to make a generic factory method, you have to pass in all the constructor args as an object array. A normal factory method might look something like this: public T Create<T>(params object[] args) … And you…More