예제 #1
0
        public static void IsValid <T>(string paramName, T paramValue, IValueValidator <T> validator)
        {
            Argument.IsNotNull("validator", validator);

            IsValid(paramName, paramValue, validator.IsValid(paramValue));
        }
예제 #2
0
        public static void IsNotOfOneOfTheTypes(string paramName, object instance, Type[] notRequiredTypes)
        {
            Argument.IsNotNull("instance", instance);

            IsNotOfOneOfTheTypes(paramName, instance.GetType(), notRequiredTypes);
        }
예제 #3
0
        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
        public static void ImplementsOneOfTheInterfaces(string paramName, object instance, Type[] interfaceTypes)
        {
            Argument.IsNotNull("instance", instance);

            ImplementsOneOfTheInterfaces(paramName, instance.GetType(), interfaceTypes);
        }
예제 #5
0
        public static void IsNotOfType(string paramName, object instance, Type notRequiredType)
        {
            Argument.IsNotNull("instance", instance);

            IsNotOfType(paramName, instance.GetType(), notRequiredType);
        }
예제 #6
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);
 }
예제 #7
0
        public static void ImplementsInterface(string paramName, object instance, Type interfaceType)
        {
            Argument.IsNotNull("instance", instance);

            ImplementsInterface(paramName, instance.GetType(), interfaceType);
        }
        /// <summary>
        /// Initializes the specified service locator.
        /// </summary>
        /// <param name="serviceLocator">The service locator.</param>
        public void Initialize(IServiceLocator serviceLocator)
        {
            Argument.IsNotNull(() => serviceLocator);

            // Register services here
        }
예제 #9
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));
                }
            }
        }
        /// <summary>
        /// Initializes the specified service locator.
        /// </summary>
        /// <param name="serviceLocator">The service locator.</param>
        public void Initialize(IServiceLocator serviceLocator)
        {
            Argument.IsNotNull(() => serviceLocator);

            serviceLocator.RegisterType <IProxyFactory, ProxyFactory>();
        }
예제 #11
0
        /// <summary>
        /// Gets the region name.
        /// </summary>
        /// <param name="this">
        /// The <see cref="DependencyObject"/> instance.
        /// </param>
        /// <returns>
        /// The region name.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="this"/> is <c>null</c>.
        /// </exception>
        public static string GetRegionName(this DependencyObject @this)
        {
            Argument.IsNotNull("@this", @this);

            return(RegionManager.GetRegionName(@this));
        }
예제 #12
0
            /// <summary>
            /// Initializes a new instance of the <see cref="RegionInfo"/> class.
            /// </summary>
            /// <param name="dependencyObject">
            /// The dependency object.
            /// </param>
            /// <exception cref="System.ArgumentNullException">
            /// The <paramref name="dependencyObject"/> is <c>null</c>.
            /// </exception>
            public RegionInfo(DependencyObject dependencyObject)
            {
                Argument.IsNotNull("dependencyObject", dependencyObject);

                _dependencyObject = dependencyObject;
            }
예제 #13
0
        /// <summary>
        /// Gets the service of the specified type.
        /// </summary>
        /// <typeparam name="T">Type of the service.</typeparam>
        /// <param name="this">The instance.</param>
        /// <param name="tag">The tag.</param>
        /// <returns>Service object or <c>null</c> if the service is not found.</returns>
        /// <exception cref="System.ArgumentNullException">The <paramref name="this"/> is <c>null</c>.</exception>
        public static T GetService <T>(this IViewModel @this, object tag = null)
        {
            Argument.IsNotNull("@this", @this);

            return(@this is ViewModelBase ? (@this as ViewModelBase).GetService <T>(tag) : (T)ServiceLocator.Default.ResolveType(typeof(T), tag));
        }
예제 #14
0
        /// <summary>
        /// Initializes the specified service locator.
        /// </summary>
        /// <param name="serviceLocator">The service locator.</param>
        public void Initialize(IServiceLocator serviceLocator)
        {
            Argument.IsNotNull(() => serviceLocator);

            serviceLocator.RegisterType <IJsonSerializer, JsonSerializer>();
        }