public void Construct()
		{
			string typeName = "MyType";
			string assemblyName = "MyAssembly";
			AssemblyQualifiedTypeName tn = new AssemblyQualifiedTypeName(typeName, assemblyName);

			Assert.AreEqual(typeName, tn.Type);
			Assert.AreEqual(assemblyName, tn.Assembly);
		}
Esempio n. 2
0
        /// <summary>
        /// Returns a <see cref="System.Type"/> from an already loaded Assembly or an
        /// Assembly that is loaded with a partial name.
        /// </summary>
        /// <param name="name">An <see cref="AssemblyQualifiedTypeName" />.</param>
        /// <param name="throwOnError"><see langword="true" /> if an exception should be thrown
        /// in case of an error, <see langword="false" /> otherwise.</param>
        /// <returns>
        /// A <see cref="System.Type"/> object that represents the specified type,
        /// or <see langword="null" /> if the type cannot be loaded.
        /// </returns>
        /// <remarks>
        /// Attempts to get a reference to the type from an already loaded assembly.  If the
        /// type cannot be found then the assembly is loaded using
        /// <see cref="Assembly.Load(string)" />.
        /// </remarks>
        public static System.Type TypeFromAssembly(AssemblyQualifiedTypeName name, bool throwOnError)
        {
            try
            {
                // Try to get the type from an already loaded assembly
                System.Type type = System.Type.GetType(name.ToString());

                if (type != null)
                {
                    return(type);
                }

                if (name.Assembly == null)
                {
                    // No assembly was specified for the type, so just fail
                    const string noAssembly = "Could not load type {0}. Possible cause: no assembly name specified.";
                    log.Warn(noAssembly, name);
                    if (throwOnError)
                    {
                        throw new TypeLoadException(string.Format(noAssembly, name));
                    }
                    return(null);
                }

                Assembly assembly = Assembly.Load(name.Assembly);

                if (assembly == null)
                {
                    log.Warn("Could not load type {0}. Possible cause: incorrect assembly name specified.", name);
                    return(null);
                }

                type = assembly.GetType(name.Type, throwOnError);

                if (type == null)
                {
                    log.Warn("Could not load type {0}.", name);
                    return(null);
                }

                return(type);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled())
                {
                    log.Error(e, "Could not load type {0}.", name);
                }
                if (throwOnError)
                {
                    throw;
                }
                return(null);
            }
        }
		public bool Equals(AssemblyQualifiedTypeName obj)
		{
			if (obj == null)
			{
				return false;
			}
			if (ReferenceEquals(this, obj))
			{
				return true;
			}
			return Equals(obj.type, type) && Equals(obj.assembly, assembly);
		}
 public bool Equals(AssemblyQualifiedTypeName obj)
 {
     if (obj == null)
     {
         return(false);
     }
     if (ReferenceEquals(this, obj))
     {
         return(true);
     }
     return(Equals(obj.type, type) && Equals(obj.assembly, assembly));
 }
        public override bool Equals(object obj)
        {
            AssemblyQualifiedTypeName other = obj as AssemblyQualifiedTypeName;

            if (other == null)
            {
                return(false);
            }

            return(string.Equals(type, other.type) &&
                   string.Equals(assembly, other.assembly));
        }
        /// <summary>
        /// Returns a reference to the Type.
        /// </summary>
        /// <param name="name">The name of the class or a fully qualified name.</param>
        /// <returns>The Type for the Class.</returns>
        /// <remarks>
        /// See <see cref="System.Type.GetType(System.String, System.Boolean)"/> for a full
        /// description of how this works. This method trims the <c>name</c> before passing
        /// it to GetType.
        /// </remarks>
        public static System.Type ClassForName(string name)
        {
            AssemblyQualifiedTypeName parsedName = AssemblyQualifiedTypeName.Parse(name,
                                                                                   Assembly.GetExecutingAssembly().FullName);

            System.Type result = TypeFromAssembly(parsedName);
            if (result == null)
            {
                throw new TypeLoadException("Could not load type '" + parsedName + "', check that type and assembly names are correct");
            }
            return(result);
        }
Esempio n. 7
0
			public ClassEntry(string extends, string className, string entityName, string assembly, string @namespace)
			{
				fullExtends = string.IsNullOrEmpty(extends) ? null : TypeNameParser.Parse(extends, @namespace, assembly);
				fullClassName = string.IsNullOrEmpty(className) ? null : TypeNameParser.Parse(className, @namespace, assembly);
				this.entityName = entityName;
				extendsEntityName = string.IsNullOrEmpty(extends) ? null : extends;
				unchecked
				{
					hashCode = (entityName != null ? entityName.GetHashCode() : 0);
					hashCode = (hashCode * 397) ^ (fullExtends != null ? fullExtends.GetHashCode() : 0);
					hashCode = (hashCode * 397) ^ (fullClassName != null ? fullClassName.GetHashCode() : 0);
				}
			}
        /// <summary>
        /// Returns a <see cref="System.Type"/> from an already loaded Assembly or an
        /// Assembly that is loaded with a partial name.
        /// </summary>
        /// <param name="name">An <see cref="AssemblyQualifiedTypeName" />.</param>
        /// <returns>
        /// A <see cref="System.Type"/> object that represents the specified type,
        /// or <c>null</c> if the type cannot be loaded.
        /// </returns>
        /// <remarks>
        /// Attempts to get a reference to the type from an already loaded assembly.  If the
        /// type cannot be found then the assembly is loaded using
        /// <see cref="Assembly.LoadWithPartialName(string)" />.
        /// </remarks>
        public static System.Type TypeFromAssembly(AssemblyQualifiedTypeName name)
        {
            if (name.Assembly == null)
            {
                name = new AssemblyQualifiedTypeName(name.Type, Assembly.GetExecutingAssembly().FullName);
            }

            try
            {
                // Try to get the types from an already loaded assembly
                System.Type type = System.Type.GetType(name.ToString());

                // If the type is null then the assembly is not loaded.
                if (type == null)
                {
                    // Use the partial name because we don't know the public key, version,
                    // culture-info of the assembly on the local machine.
                    Assembly assembly = Assembly.LoadWithPartialName(name.Assembly);

                    if (assembly != null)
                    {
                        type = assembly.GetType(name.Type);
                    }
                }

                return(type);
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(name + " could not be loaded.", e);
                }
                return(null);
            }
        }
Esempio n. 9
0
 public ClassEntry(string extends, string className, string assembly, string @namespace)
 {
     _fullExtends = extends == null ? null : TypeNameParser.Parse(extends, @namespace, assembly);
     _fullClassName = TypeNameParser.Parse(className, @namespace, assembly);
 }
Esempio n. 10
0
		public AssemblyQualifiedTypeName MakeGenericType(AssemblyQualifiedTypeName qualifiedName, bool isArrayType,
		                                                 AssemblyQualifiedTypeName[] typeArguments)
		{
			Debug.Assert(typeArguments.Length > 0);

			var baseType = qualifiedName.Type;
			var sb = new StringBuilder(typeArguments.Length * 200);
			sb.Append(baseType);
			sb.Append('[');
			for (int i = 0; i < typeArguments.Length; i++)
			{
				if(i>0)
				{
					sb.Append(",");
				}
				sb.Append('[').Append(typeArguments[i].ToString()).Append(']');
			}
			sb.Append(']');
			if(isArrayType)
			{
				sb.Append("[]");
			}
			return new AssemblyQualifiedTypeName(sb.ToString(), qualifiedName.Assembly);
		}
		/// <summary>
		/// Returns a <see cref="System.Type"/> from an already loaded Assembly or an
		/// Assembly that is loaded with a partial name.
		/// </summary>
		/// <param name="name">An <see cref="AssemblyQualifiedTypeName" />.</param>
		/// <returns>
		/// A <see cref="System.Type"/> object that represents the specified type,
		/// or <c>null</c> if the type cannot be loaded.
		/// </returns>
		/// <remarks>
		/// Attempts to get a reference to the type from an already loaded assembly.  If the 
		/// type cannot be found then the assembly is loaded using
		/// <see cref="Assembly.LoadWithPartialName(string)" />.
		/// </remarks>
		public static System.Type TypeFromAssembly( AssemblyQualifiedTypeName name )
		{
			if( name.Assembly == null )
			{
				name = new AssemblyQualifiedTypeName( name.Type, Assembly.GetExecutingAssembly().FullName );
			}

			try
			{
				// Try to get the types from an already loaded assembly
				System.Type type = System.Type.GetType( name.ToString() );

				// If the type is null then the assembly is not loaded.
				if( type == null )
				{
					// Use the partial name because we don't know the public key, version,
					// culture-info of the assembly on the local machine.
					Assembly assembly = Assembly.LoadWithPartialName( name.Assembly );
				
					if( assembly != null )
					{
						type = assembly.GetType( name.Type );
					}
				}

				return type;
			}
			catch( Exception e )
			{
				if( log.IsErrorEnabled )
				{
					log.Error( name + " could not be loaded.", e );
				}
				return null;
			}
		}
		public void ToStringEscaped()
		{
			AssemblyQualifiedTypeName tn = new AssemblyQualifiedTypeName("Escaped\\,Type", "Escaped\\,Assembly");
			Assert.AreEqual(tn.Type + ", " + tn.Assembly, tn.ToString());
		}
		public void ToStringComplex()
		{
			AssemblyQualifiedTypeName tn = new AssemblyQualifiedTypeName("MyType", "MyAssembly");
			Assert.AreEqual("MyType, MyAssembly", tn.ToString());
		}
		public void ToStringSimple()
		{
			AssemblyQualifiedTypeName tn = new AssemblyQualifiedTypeName("MyType", null);
			Assert.AreEqual("MyType", tn.ToString());
		}
Esempio n. 15
0
			public ClassEntry(string extends, string className, string assemblyName, string @namespace, string fileName, Assembly assembly)
			{
                _fullExtends = extends == null ? null : TypeNameParser.Parse(extends, @namespace, assemblyName);
                _fullClassName = TypeNameParser.Parse(className, @namespace, assemblyName);
				_fileName = fileName;
                _assembly = assembly;
			}
Esempio n. 16
0
        /// <summary>
        /// Returns a <see cref="System.Type"/> from an already loaded Assembly or an
        /// Assembly that is loaded with a partial name.
        /// </summary>
        /// <param name="name">An <see cref="AssemblyQualifiedTypeName" />.</param>
        /// <param name="throwOnError"><see langword="true" /> if an exception should be thrown
        /// in case of an error, <see langword="false" /> otherwise.</param>
        /// <returns>
        /// A <see cref="System.Type"/> object that represents the specified type,
        /// or <see langword="null" /> if the type cannot be loaded.
        /// </returns>
        /// <remarks>
        /// Attempts to get a reference to the type from an already loaded assembly.  If the 
        /// type cannot be found then the assembly is loaded using
        /// <see cref="Assembly.Load(string)" />.
        /// </remarks>
        public static System.Type TypeFromAssembly(AssemblyQualifiedTypeName name, bool throwOnError)
        {
            try
            {
                // Try to get the type from an already loaded assembly
                System.Type type = System.Type.GetType(name.ToString());

                if (type != null)
                {
                    return type;
                }

                if (name.Assembly == null)
                {
                    // No assembly was specified for the type, so just fail
                    string message = "Could not load type " + name + ". Possible cause: no assembly name specified.";
                    log.Warn(message);
                    if (throwOnError) throw new TypeLoadException(message);
                    return null;
                }

                Assembly assembly = Assembly.Load(name.Assembly);

                if (assembly == null)
                {
                    log.Warn("Could not load type " + name + ". Possible cause: incorrect assembly name specified.");
                    return null;
                }

                type = assembly.GetType(name.Type, throwOnError);

                if (type == null)
                {
                    log.Warn("Could not load type " + name + ".");
                    return null;
                }

                return type;
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Could not load type " + name + ".", e);
                }
                if (throwOnError) throw;
                return null;
            }
        }
        public override bool Equals(object obj)
        {
            AssemblyQualifiedTypeName other = obj as AssemblyQualifiedTypeName;

            return(Equals(other));
        }