public ComponentMessage CreateComponentMessage(Int32 index) { ComponentFactoryCreateDelegate creator; if (ComponentFactories.TryGetCreator(index, out creator)) { ComponentMessage result = creator(); result.ComponentIndex = index; return(result); } return(null); }
public ComponentMessage CreateComponentMessage(Component obj) { Type type = obj.GetType(); Int32 index; ComponentMessage result; ComponentFactoryWrapDelegate wrapper; if (ComponentFactories.TryGetWrapper(type, out index, out wrapper)) { result = wrapper(obj); result.ComponentIndex = index; return(result); } List <Type> types = new List <Type>(); do { types.Add(type); type = type.BaseType; if (type == null) { throw new InvalidOperationException("Something went wrong."); } } while (!ComponentFactories.TryGetIndex(type, out index)); foreach (Type t in types) { ComponentFactories.Link(t, index); } wrapper = ComponentFactories.GetWrapper(index); result = wrapper(obj); result.ComponentIndex = index; return(result); }