Exemple #1
0
 /// <summary>
 /// Gets the type or default.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TDefault">The type of the default.</typeparam>
 /// <param name="type">The type.</param>
 /// <param name="generic">The generic.</param>
 /// <param name="objName">Name of the obj.</param>
 /// <returns></returns>
 public static T GetTypeOrDefault <T, TDefault>(TypeElement type, Type generic, string objName) where TDefault : T, new()
 {
     if (type == null || string.IsNullOrEmpty(type.ClassType))
     {
         return(new TDefault());
     }
     return(GetType <T>(type, generic, objName));
 }
Exemple #2
0
        public static Type LoadType(TypeElement type, string objName)
        {
            if (type == null)
            {
                throw new ArgumentException("Parameter 'type' could not be null.'");
            }

            return(LoadType(type.ClassType, objName));
        }
Exemple #3
0
        /// <summary>
        /// Gets the type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type">The type.</param>
        /// <param name="objName">Name of the obj.</param>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        public static T GetType <T>(TypeElement type, string objName, params object[] args)
        {
            if (type == null)
            {
                throw new ArgumentException("Parameter 'type' could not be null.'");
            }

            return(GetType <T>(type.ClassType, type.Method, objName, args));
        }
Exemple #4
0
        /// <summary>
        /// Gets the type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type">The type.</param>
        /// <param name="generic">The generic.</param>
        /// <param name="objName">Name of the obj.</param>
        /// <returns></returns>
        public static T GetType <T>(TypeElement type, Type generic, string objName)
        {
            if (type == null)
            {
                throw new ArgumentException("Parameter 'type' could not be null.'");
            }

            if (generic == null)
            {
                throw new ArgumentException("Parameter 'genereic' could not be null.'");
            }

            var genericIndex = type.ClassType.LastIndexOf("]]", StringComparison.Ordinal);

            if (genericIndex < 0)
            {
                genericIndex = 0;
            }

            var index    = type.ClassType.IndexOf(',', genericIndex);
            var assembly = Assembly.Load(type.ClassType.Substring(index + 1));

            object obj;

            try
            {
                obj = assembly.CreateInstance(string.Format(CultureInfo.InvariantCulture, "{0}`1[[{1}]]",
                                                            type.ClassType.Substring(0, index),
                                                            generic.AssemblyQualifiedName));
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, ConfigurationError, objName, type), ex);
            }

            if (obj == null)
            {
                throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, ConfigurationError, objName, type.ClassType));
            }

            return((T)obj);
        }
Exemple #5
0
 /// <summary>
 /// Gets the type or default.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TDefault">The type of the default.</typeparam>
 /// <param name="type">The type.</param>
 /// <param name="objName">Name of the obj.</param>
 /// <param name="args">The args.</param>
 /// <returns></returns>
 public static T GetTypeOrDefault <T, TDefault>(TypeElement type, string objName, params object[] args) where TDefault : T, new()
 {
     return(type != null?GetTypeOrDefault <T, TDefault>(type.ClassType, objName, args) : new TDefault());
 }