Ark-kun uses generics to generate unique types at compile time. With a common type, any static elements are unique to this particular closed generic type. Thus, it is processed as quickly as the standard search for static elements.
The above use is equivalent to something like this:
public static class MyDict_String { public static string Value { get; set; } } public static class MyDict_Int32 { public static int Value { get; set; } } MyDict_String.Value = MyDict_Int32.Value.ToString();
AFAIK, types are "static" (in that you cannot define more than one of this path), so I don’t know a way to spoof this and maintain the same performance as a statically compiled element search.
It is best (in other words, I think) to create a generic instance type that wraps its own vocabulary that uses System.Type for its keys and System.Object for its values, which you must do boxing / casting when inserting / retrieving values.
EDIT: here's a simple implementation carrying a dictionary:
public class MyTypedDict { private Dictionary<Type, object> Values = new Dictionary<Type, object>(); public T Get<T>() { object untypedValue; if (Values.TryGetValue(typeof(T), out untypedValue)) return (T)untypedValue; return default(T); } public void Set<T>(T value) { Values[typeof(T)] = value; } }
Thinking more about this, one could get more syntax similar to a property using ExpandoObject ( http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject.aspx ) through some stupidity, but I feel that it would be rather offensive, and I can only assume terribly prone to runtime errors. (plus this will not give you anything at compile time)
EDITx2: If you really want to have different sets of values, you can nest it in another generic type:
public static class ValueSets<T> { public static class MyDict<U> { public static U Value { get; set; } } }
Using for example:
ValueSets<int>.MyDict<string>.Value = "Hello "; ValueSets<bool>.MyDict<string>.Value = "World!"; string helloworld = ValueSets<int>.MyDict<string>.Value + ValueSets<bool>.MyDict<string>.Value; Console.WriteLine(helloworld);
But then the initial type int and bool in this case will become “magic” and without meaning, plus you will need to provide a unique type for a separate set of values that you would like to use. Also, you could not pass it and change it as an instance variable, rather, it would be statically available (if you have access to type T ). Therefore, perhaps you can declare minimally visible types whose names make sense and use them:
internal class MyFirstWords {} internal class MySecondWords {} ValueSets<MyFirstWords>.MyDict<string>.Value = "Hello "; ValueSets<MySecondWords>.MyDict<string>.Value = "World!"; string helloworld = ValueSets<MyFirstWords>.MyDict<string>.Value + ValueSets<MySecondWords>.MyDict<string>.Value; Console.WriteLine(helloworld);
Despite this, I think it's pretty stupid, and I would not recommend it.