AssemblyInstaller.Install expects a System.Collections.IDictionary.
Am I right to be 'allergic' to using non-generic collections such as Hashtable or should I get over myself?!
e.g.
using System.Collections.Generic;
using System.Configuration.Install;
using System.Reflection;
using AssemblyWithInstaller;
namespace InstallerDemo
{
class InstallerDemo
{
static void Main(string[] args)
{
var savedState = new Dictionary<object, object>();
// i.e. as opposed to something that implements IDictionary:
//var savedState = new System.Collections.Hashtable()
var assembly = Assembly.GetAssembly(typeof (MyInstaller));
var ai = new AssemblyInstaller(assembly, new[] {"/LogFile=install.log"});
ai.Install(savedState);
ai.Commit(savedState);
}
}
}
Additionally the compiler has no issue with this decalration:
var savedState = new Dictionary<string, object>();
But will anything bad happen at runtime if someone uses something other than strings as keys?
Update [Reflector to the rescue]
var savedState = new Dictionary<string, object>();
Confirming what Jon says, Dictionary implements IDictionary as follows:
void IDictionary.Add(object key, object value)
{
Dictionary<TKey, TValue>.VerifyKey(key);
Dictionary<TKey, TValue>.VerifyValueType(value);
this.Add((TKey) key, (TValue) value);
}
...so in verifying the key it will throw an exception when the type of the key doesn't match that used when declaring the particular specialization of the generic Dictionary (and likewise for the type of the value):
private static void VerifyKey(object key)
{
if (key == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
}
if (!(key is TKey))
{
ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
}
}