/// <summary> /// load text from specified assembly /// </summary> /// <param name="asm"></param> /// <param name="name"></param> /// <returns></returns> public static string LoadTextFromAssembly(Assembly asm, string name) { AssertUtils.ArgumentNotNull(asm, "asm"); AssertUtils.ArgumentHasText(name, "name"); return(Encoding.UTF8.GetString(LoadBufferFromAssembly(asm, name))); }
/// <summary> /// Registers an alias for the supplied <see cref="System.Type"/>. /// </summary> /// <param name="alias"> /// The alias for the supplied <see cref="System.Type"/>. /// </param> /// <param name="type"> /// The <see cref="System.Type"/> to register the supplied <paramref name="alias"/> under. /// </param> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="type"/> is <see langword="null"/>; or if /// the supplied <paramref name="alias"/> is <see langword="null"/> or /// contains only whitespace character(s). /// </exception> public static void RegisterType(string alias, Type type) { AssertUtils.ArgumentHasText(alias, "alias"); AssertUtils.ArgumentNotNull(type, "type"); lock (types.SyncRoot) { types[alias] = type; } }
/// <summary> /// Registers an alias for the specified <see cref="System.Type"/>. /// </summary> /// <remarks> /// <p> /// This overload does eager resolution of the <see cref="System.Type"/> /// referred to by the <paramref name="typeName"/> parameter. It will throw a /// <see cref="System.TypeLoadException"/> if the <see cref="System.Type"/> referred /// to by the <paramref name="typeName"/> parameter cannot be resolved. /// </p> /// </remarks> /// <param name="alias"> /// A string that will be used as an alias for the specified /// <see cref="System.Type"/>. /// </param> /// <param name="typeName"> /// The (possibly partially assembly qualified) name of the /// <see cref="System.Type"/> to register the alias for. /// </param> /// <exception cref="System.ArgumentNullException"> /// If either of the supplied parameters is <see langword="null"/> or /// contains only whitespace character(s). /// </exception> /// <exception cref="System.TypeLoadException"> /// If the <see cref="System.Type"/> referred to by the supplied /// <paramref name="typeName"/> cannot be loaded. /// </exception> public static void RegisterType(string alias, string typeName) { AssertUtils.ArgumentHasText(alias, "alias"); AssertUtils.ArgumentHasText(typeName, "typeName"); Type type = ObjectUtils.ResolveType(typeName); if (type.IsGenericTypeDefinition) { alias += ("`" + type.GetGenericArguments( ).Length); } RegisterType(alias, type); }
/// <summary> /// Resolves the supplied <paramref name="alias"/> to a <see cref="System.Type"/>. /// </summary> /// <param name="alias"> /// The alias to resolve. /// </param> /// <returns> /// The <see cref="System.Type"/> the supplied <paramref name="alias"/> was /// associated with, or <see lang="null"/> if no <see cref="System.Type"/> /// was previously registered for the supplied <paramref name="alias"/>. /// </returns> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="alias"/> is <see langword="null"/> or /// contains only whitespace character(s). /// </exception> public static Type ResolveType(string alias) { AssertUtils.ArgumentHasText(alias, "alias"); return(( Type )types[alias]); }