How to mix generic classes in a generic list in C#

If you create a class like Setting<T>, you might think you can create a generic list, like:

List<Setting<T>> List = new List<Setting<T>>();

,but this is not possible in .Net 4.0. If you want objects of type Setting<int> mixed with objects of type  Setting<bool> in one List<T> you must define a none generic base class Setting, like:

public class Setting { private string _name; public string Name { get { if (string.IsNullOrEmpty(_name)) {

throw new ApplicationException("Property [Name] in class [Setting] is null or empty"); } return _name; } set { _name = value; } } } [Serializable] public class Setting<T> : Setting { private T _value; public T Value { get { return _value; } set { _value = value; } } public Type Type { get { return typeof(T); } } /// <summary> /// Define a default constructor for serialization purposes /// </summary> public Setting() { } }

Then you can mix generic types in the generic list like:

List<Setting> list = new List<Setting>
    new Setting<int>{Name = "Timeout", Value = 1000},
    new Setting<bool>{Name = "ImportEnabled", Value = true}

You can get an element of this list by using the method:

public T GetSetting<T>(string name, List<Setting> list)
{     T result;
    Setting<T> setting = (Setting<T>)Convert.ChangeType(
                         list.Single(s => s.Name.Equals(name)), typeof(Setting<T>), null); result = setting.Value; return result; }

To call the method use:

int timeout = GetSetting<int>("Timeout", list);

Mouse pointer disappears, when over textboxes or texteditor in VMWare

When I use a Windows 7 x64 computer and start a Remote Desktop session to a machine running Windows 7 x64 with VMWare 7. De mouse pointer disappears in the VMWare guest running Windows XP, when over textboxes or texteditors.

I found the solution at:



Change the mouse pointer scheme to "Windows Black (system scheme)"

Start > Control Panel > Mouse > Pointers > Windows Black (system scheme)

Change recovery model for all SQL server database to Simple, truncate and shrink log files with T-SQL

When you have many databases on a database development SQL server and these databases are re-creatable, you can save space by setting the recovery model for all databases to Simple, truncate and shrink the log files, with the following T-SQL script

    Only use this script for SQL Server development servers!
    Script must be executed as sysadmin
    This script will execute the following actions on all databases
        - set recovery model to [Simple]
        - trucate log file
        - shrink log file

use [master]

-- Declare container variabels for each column we select in the cursor
declare @databaseName nvarchar(128)

-- Define the cursor name
declare databaseCursor cursor
-- Define the dataset to loop
select [name] from sys.databases

-- Start loop
open databaseCursor

-- Get information from the first row
fetch next from databaseCursor into @databaseName

-- Loop until there are no more rows
while @@fetch_status = 0
    print 'Setting recovery model to Simple for database [' + @databaseName + ']'
    exec('alter database [' + @databaseName + '] set recovery Simple')
    print 'Shrinking logfile for database [' + @databaseName + ']'
    use [' + @databaseName + '];' +'
    declare @logfileName nvarchar(128);
    set @logfileName = (
        select top 1 [name] from sys.database_files where [type] = 1
    dbcc shrinkfile(@logfileName,1);
    -- Get information from next row
    fetch next from databaseCursor into @databaseName

-- End loop and clean up
close databaseCursor
deallocate databaseCursor

How to generate a table of contents for an OneNote 2010 exported to Word 2010

If you create all your software documentation in OneNote 2010 and want to export it to Word 2010, for a customer. You will miss a table of contents. You can automatically generate this table of contents during export, by using the OneNote export api, but this post shows you how to do it manually.


Result of the OneNote 2010 export to Word 2010:






  • Generate your OneNote 2010 like this:


  • Apply heading styling to your chapters and paragraphs:



  • Export OneNote section to Word 2010: File > Save As > Section > Word Document (*.docx) > Save As > Save


  • Open the document in Word 2010:


  • Set cursor on the text "Chapter 1", click on Home > Select > Select All Text With Similar Formatting (No Data)


  • Click on Heading 1 to apply formatting


  • Do the same for Paragraph 2.2 and 2.2.1
  • Create table of contents: References > Table of Contents


New features in ASP .NET 4.0 that I use

After doing some projects for customers with ASP .NET 4.0, what are the new features that I used in the real world?

  • SQL cache invalidation: this means that when the result set from SQL Server changes, the output cache is triggered to change, and the end user always sees the latest result set. The data presented is never stale
  • ASP.NET 4 provides 64-bit support. This means that you can run your ASP.NET applications on 64-bit
    Intel or AMD processors.
  • ADO .NET Entity Framework, used for business entity- and data layer.
  • ASP.NET Dynamic Data, used for generating the administration pages of an web application.
  • WCF Data Services, to create, update and delete data in the database, via a RESTful service
  • Health monitoring system, used in addition to SCOM to monitor the health of the system. (log: application starts and stops, failed logins, unhandled exceptions etc.)
  • WebConfigurationManager, to read and write to the web.config, changing settings.