Ejemplo n.º 1
0
        public static Type LoadGenericType(string typeName, Type[] argTypes, bool throwOnError = true, bool ignoreCase = false)
        {
            string[] names = typeName.Split(',');
            Assertion.IsTrue(names.Length == 1 || names.Length == 2, "Generic type name [{0}] not valid.", typeName);

            string genericName   = string.Format("{0}`{1}", names[0], argTypes.Length);
            string convertedName = (names.Length == 1) ? genericName : string.Format("{0},{1}", genericName, names[1]);

            Type generic = Type.GetType(convertedName, throwOnError, ignoreCase);

            if (generic == null)
            {
                if (throwOnError)
                {
                    ThrowHelper.ThrowDynamicLoad(typeName);
                }
                else
                {
                    return(null);
                }
            }

            Type result = generic.MakeGenericType(argTypes);

            return(result);
        }
Ejemplo n.º 2
0
        public static void SetStartupDirectory(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                SetStartupDirectory(Assembly.GetExecutingAssembly());
                return;
            }

            Assertion.IsTrue(Directory.Exists(path), "The directory [{0}] not exist.", path);
            _startupDir = path;
        }
Ejemplo n.º 3
0
 public static bool Implemented(this Type t, Type interfaceType)
 {
     Assertion.IsTrue(interfaceType.IsInterface, "{0} is not interface type", interfaceType.FullName);
     return(t.GetInterface(interfaceType.FullName, false) != null);
 }