What do you do with the books you don’t want anymore?

I have lots of books. I buy lots of them, but I don’t want to keep all of them.
Some have already done their job – as the ones I bought to study towards certification. Others are simply bad books.
What do you do with the books you don’t want anymore?
Keep them anyway? Give them away? Sell them? How do you sell them?

Global.asax event handling internals (part 1 of 3)

Some days ago I and another project member were seeing the best way to catch unhandled exceptions in ASP.NET.
We found the Global.Application_Error method in Global.asax which them.
Besides Application_Error, Visual Studio creates some other methods for handling events in Global.asax:
 
protected void Application_Start(Object sender, EventArgs e)
{
}
protected void Session_Start(Object sender, EventArgs e)
{
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
}
protected void Application_Error(Object sender, EventArgs e)
{
}
protected void Session_End(Object sender, EventArgs e)
{
}
protected void Application_End(Object sender, EventArgs e)
{
}
 
All the methods have a signature compatible with the EventHandler delegate but none of the events are declared in Global or HttpAppliaction.
So how are the methods bound to the events?
If you ask it to Doug Purdy (the Remoting’s father e one of the fathers of Indigo), he would probably answer that it is magic as he did when answering a question of mine about Remoting. But I (whom am not the father of Indigo or Remoting and started studying ASP.NET a couple of weeks ago) will answer:
It does the binding during application initialization using a lot of Reflection.
Handed with my debugger (Visual Studio) and .NET Reflector, I found an internal class called HttpApplicationFactory which is who initializes the application.
But before instantiating an object from Global (in fact a class derived from Global created automatically), HttpApplicationFactory enumerates all Global’s methods within the ReflectOnApplicationType method and with ReflectOnMethodInfoIfItLooksLikeEventHandler() inserts every method that has as name that looks like an event handler in a list.
This list will be enumerated by HttpApplicaton. HookupEventHandlersForAppplicationAndModules to find events whose name is “compatible” with the methods found in Global.
When a compatible name is found, Reflection is used again to bind the method to the event.
As a piece of code worth more than “ new Regex(@"((w+)s)*").Matches(milPalavras).Count” words, follow to the next post.
 
PS.: This is due to the fact that MSN Spaces has a limit on the post’s sizes.

Databinding: Web Forms vs. Windows Forms

In Windows Forms, all data binding done by the designer is saved as code in the choosen language: C# or VB.NET:

 

//

// dataGrid1

//

this.dataGrid1.DataMember = "Customers";

this.dataGrid1.DataSource = this.dataSet11;

 

On Web Forms, it’s somewhat different, because when binding a DataGrid to a DataTable via designer, the binding isn’t saved as code; instead it’s saved as markup:

 

<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 32px" runat="server" DataSource="<%# dataSet11 %>" DataKeyField="CustomerID" DataMember="Customers" AutoGenerateColumns="False" EnableViewState="False">

      // Column definition

</asp:DataGrid>