Beispiel #1
0
        protected void AddCommandConstructor(FooCommandId commandId, Type commandType)
        {
            ConstructorInfo ci = commandType.GetConstructor(new Type[] { foo.GetType() });

            if (ci == null)
            {
                throw new Exception(string.Format(FooLocalizer.GetString(FooStringId.MessageAddCommandConstructorError), commandType));
            }
            commands.Add(commandId, ci);
        }
Beispiel #2
0
        protected void AddCommandConstructor(FooCommandId commandId, Type commandType)
        {
            ConstructorInfo ci = commandType.GetConstructor(ctorParameterTypes);

            if (ci == null)
            {
                throw new Exception(string.Format(errorFormat, commandType.ToString())); // avoid boxing
            }
            commands.Add(commandId, ci);
        }
Beispiel #3
0
        public Command CreateCommand(FooCommandId id)
        {
            switch (id)
            {
            case FooCommandId.SomeCommand:
                return(new FooCommand(foo));

            default:
                return(null);
            }
        }
Beispiel #4
0
        protected void AddCommandConstructor(FooCommandId commandId, Type commandType)
        {
            ConstructorInfo ci = commandType.GetConstructor(ctorParameterTypes);

            if (ci == null)
            {
                throw new Exception(string.Format(errorFormat, commandType.ToString()));
            }
            var ctorExp = Expression.New(ci, ctorParameter);

            initializers[(int)commandId] = Expression.Lambda <Func <Command> >(ctorExp).Compile();
        }
Beispiel #5
0
        public Command CreateCommand(FooCommandId id)
        {
            ConstructorInfo ci;

            return(commands.TryGetValue(id, out ci) ? ci.Invoke(ctorParams) as Command : null); // un-needed null-check
        }
Beispiel #6
0
        public Command CreateCommand(FooCommandId id)
        {
            ConstructorInfo ci;

            return((commands.TryGetValue(id, out ci) && ci != null) ? ci.Invoke(new object[] { foo }) as Command : null);
        }
Beispiel #7
0
 public Command CreateCommand(FooCommandId id)
 {
     return(initializers[(int)id].Invoke());
 }
Beispiel #8
0
        public Command CreateCommand(FooCommandId id)
        {
            Func <Command> initializer;

            return(initializers.TryGetValue(id, out initializer) ? initializer() : null);
        }