예제 #1
0
        private IComponent constructComponent(Type componentType, dynamic[] args, ComponentProperties properties)
        {
            Type[] argTypes = new Type[args.Length];
            for (int argIndex = 0; argIndex < args.Length; argIndex++)
            {
                argTypes[argIndex] = args[argIndex].GetType();
            }

            object componentObj = componentType.GetConstructor(argTypes).Invoke(args);

            properties?.ForEach(propPair =>
            {
                PropertyInfo propInfo = componentType.GetProperty(propPair.Key, BindingFlags.Public | BindingFlags.Instance);
                propInfo?.TakeIf(_ => _.CanWrite)?.SetValue(componentObj, propPair.Value, null);
            });

            return((IComponent)componentObj);
        }