Use new IDynamicTypeFactory extension method.

This commit is contained in:
Pieter-Jan Briers
2019-07-23 21:34:13 +02:00
parent 414bd95eb2
commit 040dc2445c
4 changed files with 6 additions and 6 deletions

View File

@@ -49,7 +49,7 @@ namespace Robust.Client.State
{
Logger.Debug($"Switching to state {type}");
var newState = (State)_typeFactory.CreateInstance(type);
var newState = _typeFactory.CreateInstance<State>(type);
var old = CurrentState;
CurrentState?.Shutdown();

View File

@@ -182,7 +182,7 @@ namespace Robust.Shared.GameObjects
{
throw new InvalidOperationException($"{componentType} is not a registered component.");
}
return (IComponent)_typeFactory.CreateInstance(types[componentType].Type);
return _typeFactory.CreateInstance<IComponent>(types[componentType].Type);
}
public T GetComponent<T>() where T : IComponent, new()
@@ -191,12 +191,12 @@ namespace Robust.Shared.GameObjects
{
throw new InvalidOperationException($"{typeof(T)} is not a registered component.");
}
return (T)_typeFactory.CreateInstance(types[typeof(T)].Type);
return _typeFactory.CreateInstance<T>(types[typeof(T)].Type);
}
public IComponent GetComponent(string componentName)
{
return (IComponent)_typeFactory.CreateInstance(GetRegistration(componentName).Type);
return _typeFactory.CreateInstance<IComponent>(GetRegistration(componentName).Type);
}
public IComponentRegistration GetRegistration(string componentName)

View File

@@ -93,7 +93,7 @@ namespace Robust.Shared.GameObjects
{
Logger.DebugS("go.sys", "Initializing entity system {0}", type);
//Force initialization of all systems
var instance = (IEntitySystem)_typeFactory.CreateInstance(type);
var instance = _typeFactory.CreateInstance<IEntitySystem>(type);
AddSystem(instance);
instance.RegisterMessageTypes();
instance.SubscribeEvents();

View File

@@ -291,7 +291,7 @@ namespace Robust.Shared.Prototypes
}
var prototypeType = prototypeTypes[type];
var prototype = (IPrototype)_dynamicTypeFactory.CreateInstance(prototypeType);
var prototype = _dynamicTypeFactory.CreateInstance<IPrototype>(prototypeType);
prototype.LoadFrom(node);
prototypes[prototypeType].Add(prototype);
var indexedPrototype = prototype as IIndexedPrototype;