18
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
// THE SOFTWARE.
20
20
using System ;
21
+ using System . Globalization ;
21
22
using System . Runtime . InteropServices ;
22
23
23
24
namespace SharpDX . Multimedia
@@ -26,7 +27,7 @@ namespace SharpDX.Multimedia
26
27
/// A FourCC descriptor.
27
28
/// </summary>
28
29
[ StructLayout ( LayoutKind . Sequential , Size = 4 ) ]
29
- public struct FourCC : IEquatable < FourCC >
30
+ public struct FourCC : IEquatable < FourCC > , IFormattable
30
31
{
31
32
/// <summary>
32
33
/// Empty FourCC.
@@ -175,6 +176,48 @@ public override int GetHashCode()
175
176
return ( int ) value ;
176
177
}
177
178
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
+
178
221
public static bool operator == ( FourCC left , FourCC right )
179
222
{
180
223
return left . Equals ( right ) ;
0 commit comments