public static void RegisterWindowType(Type windowType) { if (!windowType.GetInterfaces().Contains(typeof(IPersistableWindow))) { throw new Exception(); } object[] foundAttributes = windowType.GetCustomAttributes(typeof(WindowTypeNameAttribute), true); if (foundAttributes.Length == 0) { throw new Exception(); } WindowTypeNameAttribute typeNameAttribute = foundAttributes[0] as WindowTypeNameAttribute; if (typeNameAttribute == null) { throw new Exception(); } string typeName = typeNameAttribute.TypeName; if (!registeredTypes.ContainsKey(typeName)) { registeredTypes.Add(typeName, windowType); } }
public static void RegisterWindowType <TWindow>() where TWindow : IPersistableWindow { Type windowType = typeof(TWindow); WindowTypeNameAttribute typeNameAttribute = windowType.GetAttribute <WindowTypeNameAttribute>(); if (typeNameAttribute == null) { throw new Exception(); } string typeName = typeNameAttribute.TypeName; if (!registeredTypes.ContainsKey(typeName)) { registeredTypes.Add(typeName, windowType); } }