コード例 #1
0
ファイル: Argument.cs プロジェクト: szogun1987/Catel
        public static void IsValid <T>(string paramName, T paramValue, IValueValidator <T> validator)
        {
            Argument.IsNotNull("validator", validator);

            IsValid(paramName, paramValue, validator.IsValid(paramValue));
        }
コード例 #2
0
ファイル: Argument.cs プロジェクト: szogun1987/Catel
        public static void IsNotOfOneOfTheTypes(string paramName, object instance, Type[] notRequiredTypes)
        {
            Argument.IsNotNull("instance", instance);

            IsNotOfOneOfTheTypes(paramName, instance.GetType(), notRequiredTypes);
        }
コード例 #3
0
ファイル: Argument.cs プロジェクト: szogun1987/Catel
        public static void IsValid <T>(string paramName, T paramValue, Func <T, bool> validation)
        {
            Argument.IsNotNull("validation", validation);

            IsValid(paramName, paramValue, validation.Invoke(paramValue));
        }
コード例 #4
0
ファイル: Argument.cs プロジェクト: szogun1987/Catel
        public static void IsNotOfType(string paramName, object instance, Type notRequiredType)
        {
            Argument.IsNotNull("instance", instance);

            IsNotOfType(paramName, instance.GetType(), notRequiredType);
        }
コード例 #5
0
ファイル: Argument.cs プロジェクト: szogun1987/Catel
        public static void ImplementsOneOfTheInterfaces(string paramName, object instance, Type[] interfaceTypes)
        {
            Argument.IsNotNull("instance", instance);

            ImplementsOneOfTheInterfaces(paramName, instance.GetType(), interfaceTypes);
        }
コード例 #6
0
ファイル: Argument.cs プロジェクト: szogun1987/Catel
        public static void ImplementsInterface(string paramName, object instance, Type interfaceType)
        {
            Argument.IsNotNull("instance", instance);

            ImplementsInterface(paramName, instance.GetType(), interfaceType);
        }
コード例 #7
0
 /// <summary>
 /// Writes the specified message as debug message.
 /// </summary>
 /// <param name="this">
 /// The log
 /// </param>
 /// <param name="priority">
 /// The priority
 /// </param>
 /// <param name="messageFormat">
 /// The message format.
 /// </param>
 /// <param name="args">
 /// The formatting arguments.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// The <paramref name="messageFormat"/> is <c>null</c>.
 /// </exception>
 /// <exception cref="System.ArgumentNullException">
 /// The <paramref name="this"/> is <c>null</c>.
 /// </exception>
 public static void Debug(this ILog @this, Priority priority, string messageFormat, params object[] args)
 {
     Argument.IsNotNull("@this", @this);
     Argument.IsNotNull("messageFormat", messageFormat);
     @this.Debug(string.Format(PriorityPrefixPattern, priority) + " " + messageFormat, args);
 }
コード例 #8
0
        /// <summary>
        /// Creates a command using a naming convention with the specified gesture.
        /// </summary>
        /// <param name="commandManager">The command manager.</param>
        /// <param name="containerType">Type of the container.</param>
        /// <param name="commandNameFieldName">Name of the command name field.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="commandManager"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="containerType"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="commandNameFieldName"/> is <c>null</c>.</exception>
        public static void CreateCommandWithGesture(this ICommandManager commandManager, Type containerType, string commandNameFieldName)
        {
            Argument.IsNotNull("commandManager", commandManager);
            Argument.IsNotNull("containerType", containerType);
            Argument.IsNotNullOrWhitespace("commandNameFieldName", commandNameFieldName);

            Log.Debug("Creating command '{0}'", commandNameFieldName);

            // Note: we must store bindingflags inside variable otherwise invalid IL will be generated
            var bindingFlags     = BindingFlags.Public | BindingFlags.Static;
            var commandNameField = containerType.GetFieldEx(commandNameFieldName, bindingFlags);

            if (commandNameField == null)
            {
                throw Log.ErrorAndCreateException <InvalidOperationException>("Command '{0}' is not available on container type '{1}'",
                                                                              commandNameFieldName, containerType.GetSafeFullName(false));
            }

            var commandName = (string)commandNameField.GetValue(null);

            if (commandManager.IsCommandCreated(commandName))
            {
                Log.Debug("Command '{0}' is already created, skipping...", commandName);
                return;
            }

            InputGesture commandInputGesture = null;
            var          inputGestureField   = containerType.GetFieldEx(string.Format("{0}InputGesture", commandNameFieldName), bindingFlags);

            if (inputGestureField != null)
            {
                commandInputGesture = inputGestureField.GetValue(null) as InputGesture;
            }

            commandManager.CreateCommand(commandName, commandInputGesture);

            var commandContainerName = string.Format("{0}CommandContainer", commandName.Replace(".", string.Empty));

            var commandContainerType = (from type in TypeCache.GetTypes(allowInitialization: false)
                                        where string.Equals(type.Name, commandContainerName, StringComparison.OrdinalIgnoreCase)
                                        select type).FirstOrDefault();

            if (commandContainerType == null)
            {
                Log.Debug("Couldn't find command container '{0}', you will need to add a custom action or command manually in order to make the CompositeCommand useful", commandContainerName);
                return;
            }

            Log.Debug("Found command container '{0}', registering it in the ServiceLocator now", commandContainerType.GetSafeFullName(false));

            var serviceLocator = commandManager.GetServiceLocator();

            if (!serviceLocator.IsTypeRegistered(commandContainerType))
            {
                var typeFactory      = serviceLocator.ResolveType <ITypeFactory>();
                var commandContainer = typeFactory.CreateInstance(commandContainerType);
                if (commandContainer != null)
                {
                    serviceLocator.RegisterInstance(commandContainer);
                }
                else
                {
                    Log.Warning("Cannot create command container '{0}', skipping registration", commandContainerType.GetSafeFullName(false));
                }
            }
        }