Exemplo n.º 1
0
        /// <summary>Initializes a new instance of the <see cref="AssemblyScope"/> struct.</summary>
        /// <param name="filePath">The file path to the assembly.</param>
        /// <param name="namespaceText">The namespace text.</param>
        /// <param name="name">The name.</param>
        public AssemblyScope(string filePath, string namespaceText, string name) : this()
        {
            if (!string.IsNullOrEmpty(filePath))
            {
                Assembly assembly = Assembly.LoadFile(filePath);

                Location = filePath;
                Root     = assembly.ResolveRootNamespace();

                if (string.IsNullOrEmpty(namespaceText))
                {
                    if (!Root.Equals(name))
                    {
                        namespaceText = Root;
                    }
                }

                string comboPath = NamespaceScope.CombineNamespacePaths(namespaceText, name);
                NamespaceInformation = new NamespaceScope(filePath, comboPath);

                if (NamespaceInformation.IsNamespace)
                {
                    if (!string.IsNullOrEmpty(NamespaceInformation.FullPath))
                    {
                        TypeInfo = assembly.GetType(NamespaceInformation.FullPath);
                    }
                    else
                    {
                        TypeInfo = null;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>Resolves the specified input to a <see cref="Type"/>.</summary>
        /// <param name="assembly">The assembly.</param>
        /// <param name="namespacePath">The namespace path.</param>
        /// <param name="typeName">Name of the type.</param>
        /// <returns>The <see cref="Type"/>.</returns>
        public static Type ResolveType(Assembly assembly, string namespacePath, string typeName)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentNullException(nameof(typeName), @"The type name cannot be null or empty when resolving a Type.");
            }

            // Combine the path
            string fullPath = NamespaceScope.CombineNamespacePaths(namespacePath, typeName);

            // Resolve the type
            Type type = assembly.GetType(fullPath);

            return(type);
        }