/// <summary> /// Creates a new instance of the <see cref="Spring.IO.AssemblyResource"/> class. /// <para/> /// Uses the specified <paramref name="type"/> to obtain the assembly and namespace for the resource. /// </summary> /// <param name="fileName">The name of the file in the assembly.</param> /// <param name="type">The type to determine the assembly and the namespace.</param> public AssemblyResource(string fileName, Type type) { ArgumentUtils.AssertHasText(fileName, "resourceName"); ArgumentUtils.AssertNotNull(type, "type"); this.Initialize(fileName, type.Namespace, type.Assembly); }
/// <summary> /// Creates a new instance of <see cref="MediaType"/> for the given primary type, subtype and parameters. /// </summary> /// <param name="type">The primary type.</param> /// <param name="subtype">The subtype.</param> /// <param name="parameters">The parameters, may be null.</param> public MediaType(string type, string subtype, IDictionary <string, string> parameters) { ArgumentUtils.AssertHasText(type, "type"); ArgumentUtils.AssertHasText(subtype, "subtype"); // TODO: check type (http://tools.ietf.org/html/rfc2616#section-2.2) this.type = type.ToLower(CultureInfo.InvariantCulture); // TODO: check subtype (http://tools.ietf.org/html/rfc2616#section-2.2) this.subtype = subtype.ToLower(CultureInfo.InvariantCulture); // TODO: check parameters (http://tools.ietf.org/html/rfc2616#section-2.2) this.parameters = new Dictionary <string, string>(parameters, StringComparer.OrdinalIgnoreCase); }
/// <summary> /// Creates a new instance of the <see cref="Spring.IO.FileResource"/> class. /// </summary> /// <param name="resourceName">The name of the file system resource.</param> public FileResource(string resourceName) { ArgumentUtils.AssertHasText(resourceName, "resourceName"); // Remove protocol (if any) string fileName = GetResourceNameWithoutProtocol(resourceName); // Remove extra slashes used to indicate that resource is local (handle the case "/C:/path1/...") if (fileName.Length > 2 && fileName[0] == '/' && fileName[2] == ':') { fileName = fileName.Substring(1); } this.fileInfo = new FileInfo(fileName); this.fileUri = new Uri(this.fileInfo.FullName); }
/// <summary> /// Creates a new instance of the <see cref="Spring.IO.AssemblyResource"/> class /// with the specified resource name. /// </summary> /// <param name="resourceName"> /// The resource name that must follow the format 'assembly://assemblyName/namespace/resourceName'. /// </param> /// <exception cref="System.UriFormatException"> /// If the supplied <paramref name="resourceName"/> did not conform to the expected format. /// </exception> /// <exception cref="System.IO.FileNotFoundException"> /// If the assembly specified in the supplied <paramref name="resourceName"/> could not be found. /// </exception> public AssemblyResource(string resourceName) { ArgumentUtils.AssertHasText(resourceName, "resourceName"); string[] info = GetResourceNameWithoutProtocol(resourceName).Split('/'); if (info.Length != 3) { throw new UriFormatException(String.Format( "Invalid resource name. Name has to be in 'assembly://<assemblyName>/<namespace>/<resourceName>' format.", resourceName)); } Assembly assembly = Assembly.Load(info[0]); if (assembly == null) { throw new FileNotFoundException(String.Format( "Unable to load assembly [{0}].", info[0])); } this.Initialize(info[2], info[1], assembly); }