static LevelObjectFactory() { // Get object property types from the attributes that are assigned to the enum fields var fields = typeof(ObjectProperty).GetFields(); // default(ObjectParameter) is necessary otherwise an exception will be thrown // Reflection really sucks dick when it comes to enums var info = fields.Select(i => new KeyValuePair <int, Type>((int)i.GetValue(default(ObjectProperty)), i.GetCustomAttribute <ObjectPropertyTypeAttribute>()?.Type)); propertyTypeInfo = new Dictionary <int, Type>(); foreach (var i in info) { propertyTypeInfo.TryAdd(i.Key, i.Value); } // I added those 5 lines of code only to realize that I actually do not necessarily need them, hopefully they'll turn out any useful in the near future:tm: // For the time being there is no reason to change them at all objectTypes = typeof(GeneralObject).Assembly.GetTypes().Where(t => typeof(GeneralObject).IsAssignableFrom(t)).ToArray(); objectTypeDictionary = new ObjectTypeInfoDictionary(); foreach (var t in objectTypes.Select(t => ObjectTypeInfo.GetInfo(t))) { if (t != null) { objectTypeDictionary.Add((IFirstWideDoubleKeyedObject <int?, Type>)t); } } }
static GeneralObject() { // Get object property types from the attributes that are assigned to the enum fields var fields = typeof(ObjectParameter).GetFields(); // default(ObjectParameter) is necessary otherwise an exception will be thrown // Reflection really sucks dick when it comes to enums var info = fields.Select(i => new KeyValuePair <int, Type>((int)i.GetValue(default(ObjectParameter)), i.GetCustomAttribute <ObjectParameterTypeAttribute>()?.Type)); propertyTypeInfo = new Dictionary <int, Type>(); foreach (var i in info) { propertyTypeInfo.TryAdd(i.Key, i.Value); } // I added those 5 lines of code only to realize that I actually do not necessarily need them, hopefully they'll turn out any useful in the near future:tm: objectTypes = typeof(GeneralObject).Assembly.GetTypes().Where(t => typeof(GeneralObject).IsAssignableFrom(t)).ToArray(); initializableObjectTypes = objectTypes.Select(t => ObjectTypeInfo.GetInfo(t)).ToArray(); }
static GeneralObject() { objectTypes = typeof(GeneralObject).Assembly.GetTypes().Where(t => typeof(GeneralObject).IsAssignableFrom(t)).ToArray(); initializableObjectTypes = objectTypes.Select(t => ObjectTypeInfo.GetInfo(t)).ToArray(); }