Exemple #1
0
        /// <summary>
        /// Registers type
        /// </summary>
        /// <param name="typeId">Type identifier</param>
        public void RegisterType(string typeId, params object[] args)
        {
            if (args == null)
            {
                throw new TypeRegistrationException(string.Format("{0} is null (parameters required)", nameof(args)));
            }
            if (typeId == null)
            {
                throw new TypeRegistrationException(string.Format("{0} is null (type name required)", nameof(typeId)));
            }
            if (IsLocked)
            {
                throw new TypeRegistrationException(string.Format("{0} is not registered (container locked)", typeId));
            }
            var runtimeTypes = Parser.FindRuntimeTypes(typeId, ArrayExtensions.ToArray <string>(), Types.Values).ToArray();

            if (runtimeTypes.Length == 1)
            {
                var runtimeType = runtimeTypes[0];
                runtimeType.SetRuntimeInstance(RuntimeInstance.GetInstance);
                runtimeType.RegisterConstructorParameters(args.Length == 0 ? ArrayExtensions.ToArray <object>(runtimeType.Count) : args);
                return;
            }
            throw new TypeRegistrationException(string.Format("{0} is not registered (parameter type mismatch)", typeId));
        }
Exemple #2
0
 /// <summary>
 /// Creates the instance.
 /// </summary>
 /// <param name="type">The identifier.</param>
 /// <returns></returns>
 /// <exception cref="TypeInstantiationException"></exception>
 public object GetInstance(Type type) => GetInstance(ToString(type), ArrayExtensions.ToArray <object>());
Exemple #3
0
 /// <summary>
 /// Gets the type of the parameters.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <returns></returns>
 public static IEnumerable <Type> GetTypes(object[] args) => args == null || args.Length == 0 ? ArrayExtensions.ToArray <Type>() : args.Select(GetType);
Exemple #4
0
 /// <summary>
 /// Creates the instance.
 /// </summary>
 /// <param name="typeFullName">The identifier.</param>
 /// <returns></returns>
 /// <exception cref="TypeInstantiationException"></exception>
 public object GetInstance(string typeFullName) => GetInstance(typeFullName, ArrayExtensions.ToArray <object>());
Exemple #5
0
 /// <summary>
 /// Gets the full name of the parameters.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <returns></returns>
 public static IEnumerable <string> GetNames(string[] args) => args == null || args.Length == 0 ? ArrayExtensions.ToArray <string>() : args;