1818// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919// THE SOFTWARE.
2020using System ;
21+ using System . Globalization ;
2122using System . Runtime . InteropServices ;
2223
2324namespace SharpDX . Multimedia
@@ -26,7 +27,7 @@ namespace SharpDX.Multimedia
2627/// A FourCC descriptor.
2728/// </summary>
2829[ StructLayout ( LayoutKind . Sequential , Size = 4 ) ]
29- public struct FourCC : IEquatable < FourCC >
30+ public struct FourCC : IEquatable < FourCC > , IFormattable
3031{
3132/// <summary>
3233/// Empty FourCC.
@@ -175,6 +176,48 @@ public override int GetHashCode()
175176return ( int ) value ;
176177}
177178
179+ /// <summary>
180+ /// Provides a custom string representation of the FourCC descriptor.
181+ /// </summary>
182+ /// <remarks>
183+ /// The general format "G" is equivalent to the parameterless.
184+ /// <see cref="FourCC.ToString()"/>. The special format "I" returns a
185+ /// string representation which can be used to construct a Media
186+ /// Foundation format GUID. It is equivalent to "X08".
187+ /// </remarks>
188+ /// <param name="format">The format descriptor, which can be "G" (empty
189+ /// or <c>null</c> is equivalent to "G"), "I" or any valid standard
190+ /// number format.</param>
191+ /// <param name="formatProvider">The format provider for formatting
192+ /// numbers.</param>
193+ /// <returns>The requested string representation.</returns>
194+ /// <exception cref="System.FormatException">In case of
195+ /// <paramref name="format"/> is not "G", "I" or a valid number
196+ /// format.</exception>
197+ public string ToString ( string format , IFormatProvider formatProvider )
198+ {
199+ if ( string . IsNullOrEmpty ( format ) )
200+ {
201+ format = "G" ;
202+ }
203+ if ( formatProvider == null )
204+ {
205+ formatProvider = CultureInfo . CurrentCulture ;
206+ }
207+
208+ switch ( format . ToUpperInvariant ( ) )
209+ {
210+ case "G" :
211+ return this . ToString ( ) ;
212+
213+ case "I" :
214+ return this . value . ToString ( "X08" , formatProvider ) ;
215+
216+ default :
217+ return this . value . ToString ( format , formatProvider ) ;
218+ }
219+ }
220+
178221public static bool operator == ( FourCC left , FourCC right )
179222{
180223return left . Equals ( right ) ;