Class FormatHandlerAttribute
Specifies that a class can be used to decode a particular file type.
Inheritance
System.Object
System.Attribute
FormatHandlerAttribute
Inherited Members
System.Attribute.Equals(System.Object)
System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type)
System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Module)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Boolean)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type)
System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.GetHashCode()
System.Attribute.IsDefaultAttribute()
System.Attribute.IsDefined(System.Reflection.Assembly, System.Type)
System.Attribute.IsDefined(System.Reflection.Assembly, System.Type, System.Boolean)
System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type)
System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type, System.Boolean)
System.Attribute.IsDefined(System.Reflection.Module, System.Type)
System.Attribute.IsDefined(System.Reflection.Module, System.Type, System.Boolean)
System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type)
System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type, System.Boolean)
System.Attribute.Match(System.Object)
System.Attribute.TypeId
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Mars.Common.Compat
Assembly: Mars.Common.dll
Syntax
public abstract class FormatHandlerAttribute : Attribute
Constructors
| Improve this Doc View SourceFormatHandlerAttribute(String)
Initializes a new instance of the FormatHandlerAttribute class.
Declaration
public FormatHandlerAttribute(string extension)
Parameters
Type | Name | Description |
---|---|---|
System.String | extension |
Properties
| Improve this Doc View SourceExtension
Gets or sets the file extension that this format decoder applies to (i.e. "wav").
Declaration
public string Extension { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceGetHandler<TInterface, TAttribute>(String, Dictionary<String, Type>, Dictionary<String, TInterface>)
Finds a file handler that can process the given normalized file extension.
Declaration
public static TInterface GetHandler<TInterface, TAttribute>(string fileExtension, Dictionary<string, Type> handlerTypes, Dictionary<string, TInterface> cache)
where TInterface : class where TAttribute : FormatHandlerAttribute
Parameters
Type | Name | Description |
---|---|---|
System.String | fileExtension | The normalized file extension (GetNormalizedExtension(String). |
System.Collections.Generic.Dictionary<System.String, System.Type> | handlerTypes | The handler types. |
System.Collections.Generic.Dictionary<System.String, TInterface> | cache | The cache of already instantiated handler types. |
Returns
Type | Description |
---|---|
TInterface |
A file decoder or encoder implementing the TInterface interface, or null if none have
been found.
|
Type Parameters
Name | Description |
---|---|
TInterface | The type of the the handler to be found (e.g. IImageDecoder or IAudioDecoder). |
TAttribute | The type of the attribute to be found (e.g. FormatDecoderAttribute or FormatEncoderAttribute). |
GetNormalizedExtension(String)
Extracts and normalizes a file extension in the same format that is used when
specifying which formats are supported by each decoder (e.g. "file.wav" would
become "WAV", "image.png" would become "PNG", etc).
Declaration
public static string GetNormalizedExtension(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName |
Returns
Type | Description |
---|---|
System.String |
PopulateDictionaryWithHandlersFromAllAssemblies<TInterface, TAttribute>(Dictionary<String, Type>)
Populates the dictionary with available decoders of a particular category by
inspecting types from all referenced assemblies. Note: calling this method
will force all referenced assemblies to be loaded into the current AppDomain.
Declaration
public static void PopulateDictionaryWithHandlersFromAllAssemblies<TInterface, TAttribute>(Dictionary<string, Type> dictionary)
where TAttribute : FormatHandlerAttribute
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.Dictionary<System.String, System.Type> | dictionary | The dictionary where the found decoders will be stored. |
Type Parameters
Name | Description |
---|---|
TInterface | The base type for the decoders. This should be an interface such as IImageDecoder or IAudioDecoder. |
TAttribute | The type of the attribute to be found (e.g. FormatDecoderAttribute or FormatEncoderAttribute). |