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: http://wiert.wordpress.com/2010/08/06/rdp-to-vmware-host-running-an-xp-guest-invisible-mouse-cursor-on-text-editors/

 

Solution

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

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

SSIS error: Column "…" cannot be found or is not specified for query (13865)

When I refreshed a SSIS package OLE DB Source, I got the error: column "test" cannot be found or is not specified for query (13865).

This was caused by the fact, that the query contained a column that did not exist anymore in de database.

Removing the column name in the SqlCommand resolved this error.

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]
go
-- 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
for
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
begin
print 'Setting recovery model to Simple for database [' + @databaseName + ']'
exec('alter database [' + @databaseName + '] set recovery Simple')
print 'Shrinking logfile for database [' + @databaseName + ']'
exec('
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
-- End loop and clean up
close databaseCursor
deallocate databaseCursor
go

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:

image

 

 

Tutorial

 

  • Generate your OneNote 2010 like this:

image

  • Apply heading styling to your chapters and paragraphs:

image

 

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

image

  • Open the document in Word 2010:

image

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

image

  • Click on Heading 1 to apply formatting

image

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

image

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.