Ok so to give you all some background. I always write my data access with a repository pattern in c#. Now I often use dapper, however I’d guess this problem would also apply with Entity framework.
In C# there are two kinds of types…Value and reference…
What are Reference Types?
Reference types in C# are mostly objects and strings. These are types when placed on a stack refer to a memory address in the heap.
What are Value Types?
Value types make up the bulk of types in c#. These include int, float, double, long, bool, etc. These types values are only stored in the stack.
Stack? Heap? What’s the difference?
To put it short, the stack is a series of memory blocks (like a scratch pad) that is used for the current thread. The stack is used for basic property data access. Accessing the stack is very rapid, as its only used for trivial data. The heap is an area of memory for dynamic memory allocation. The heap is used to store things in data that are not value types, usually objects and strings. The heap is slower to access, but larger in size.
Reference type tripping points
Reference types are basically pointers. These pointers can trip you up in interesting ways. For example suppose you have an object called MyObjectName:
var MyObjectName = new SomeClass();
and you decide to make someone else’s object name the same as you’re name
var OtherObjectName = MyName;
When you change MyName to be something else, you will also change OtherName.
This is because objects are a reference type. On the stack the object is a pointer reference to the heap. When you make OtherName equal you are pointing it to the same memory address as MyName. You can see this in action here
1 2 3 4
var MyName = new SomeClass(); var OtherName = MyName; MyName = MyName.Name = "Joe"; //OtherName will now equal Joe
This is also the same for array’s if you make 1 array equal another, you will not have 2 array’s with the same value. You will have 2 variables that point to the same array.
So the same must work for value types right?
If you have 2 ints and assign one int to equal the other. The value on the stack will be copied to that int, and since the stack value is the actual value they will be independent of each other.
Boxing and Un-Boxing
When you have a value type and you want it on the heap you must convert it to an object. This is called boxing
var val = 3; var x = (object)val;
However once you do this, the two variables will be independent from each other. So if you change x you won’t change val and vice-versa.
To get the object back on the stack you must cast it back into an int. This is called un-boxing
To do custom error pages in Nancy you must implement an IStatusCodeHandler. This class must provide 2 methods. HandlesStatusCode is a bool that basically should tell Nancy if this class will handle the status code. If this returns true then this class will be responsible for handling the request.
SquishIt is a content bundler and minification tool. The github documentation contains exaples how to install and use it, and a sample application is provided. However I had some issues getting it to work with razor so I figured I would share these pain points with you.
Interested in Interstital ads, but not banner? Thats ok, but I recommend your read my first post about banner ads. The first steps, installing Google Play Services, altering your permissions, adding to your manifests files, and reviewing my github demo are located in that tutorial.