Contents tagged with C#
-
Ninja Coding: Composition over Inheritance–Even when Overriding
Ashic shows a trick that can make overriding more flexible, specially when stubbing for tests.
-
Anonymous Types are Internal, C# 4.0 Dynamic Beware!
This article explains why C# 4.0's dynamic features don't seem to work when evaluating instances of anonymous types returned from a public method of a different assembly.
-
Fetching a Property Value via Reflection
This is a very simple introduction on using reflection to access the value of a named property on an object using Reflection.Note: Cross posted from Heartysoft.com.
Permalink -
How to Send Emails from .Net [example uses GMail SMTP]
We frequently see questions about sending emails using .Net in the asp.net forums. The process of sending mail is the same for Windows apps and asp.net websites as the same .Net classes are used. The process can be slightly shortened by specifying default SMTP settings in the web.config or app.config file. Here, I’m showing the full version of the code and it does not rely on any configuration settings. The code also specifies unicode encoding for the subject and body.
-
How to use Session values in an HttpHandler
When writing a custom HttpHandler, by default you have no access to the Session object. Doing something like HttpContext.Current.Session also returns null. The workaround is quite simple:
-
HTML Comments, Other Comments and Some VS Tips
-
Memorystream Not Expandable: Invalid Operation Exception
There's a little gotcha with the MemoryStream class that I just found out. It has 7 constructors. The default constructor has the stream set as expandable, with an initial capacity of 0. The ctors that take the capacity set the capacity to the param, but also keeps the stream expandable. If, however, you use a ctor with the byte[] param, it initializes the stream with the contents of the buffer, but the stream becomes non-expandable.