示例#1
0
        public EntityComponent GetEntityComponent(string componentKey)
        {
            if (!_entityComponentConfigurations.ContainsKey(componentKey))
            {
                throw new KeyNotFoundException($"The Component with the Key: {componentKey} was not found");
            }

            EntityComponentConfiguration config = _entityComponentConfigurations[componentKey];

            return((EntityComponent)GetEntityComponentInstance(config));
        }
示例#2
0
        private object GetEntityComponentInstance(EntityComponentConfiguration config)
        {
            try
            {
                Type t = Type.GetType(config.FullyQualifiedName);

                if (t == null)
                {
                    throw new Exception($"The fully qualified name: \"{config.FullyQualifiedName}\" was not valid.");
                }

                if (config.Args == null)
                {
                    return(Activator.CreateInstance(t));
                }

                //We want to speak in int32's and not int64's
                for (int i = 0; i < config.Args.Length; i++)
                {
                    if (config.Args[i] is long)
                    {
                        config.Args[i] = Convert.ToInt32(config.Args[i]);
                    }
                }

                return(Activator.CreateInstance(t, config.Args));
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(config.FullyQualifiedName);
                Console.WriteLine();
                Console.WriteLine($"Exception: {ex}");
                return(null);
            }
        }