TimeConverterAttribute.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. namespace Bmp.Core.FFMpeg.CsCorePorts;
  2. /// <summary>
  3. /// Specifies which <see cref="TimeConverter"/> to use.
  4. /// </summary>
  5. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, AllowMultiple = false)]
  6. public sealed class TimeConverterAttribute : Attribute
  7. {
  8. /// <summary>
  9. /// Gets the type of the <see cref="TimeConverter"/> to use.
  10. /// </summary>
  11. public Type TimeConverterType { get; private set; }
  12. /// <summary>
  13. /// Gets or sets the arguments to pass to the constructor of the <see cref="TimeConverter"/>. For more information, see <see cref="Activator.CreateInstance(Type,object[])"/>.
  14. /// </summary>
  15. public object[] Args { get; set; }
  16. /// <summary>
  17. /// Gets or sets a value indicating whether a new instance of the specified <see cref="TimeConverter"/> should be created each time the <see cref="TimeConverterFactory"/> queries the <see cref="TimeConverter"/>.
  18. /// The default value is false.
  19. /// </summary>
  20. public bool ForceNewInstance { get; set; }
  21. /// <summary>
  22. /// Initializes a new instance of the <see cref="TimeConverterAttribute"/> class based on the type of the <see cref="TimeConverter"/> to use.
  23. /// </summary>
  24. /// <param name="timeConverterType">Type of the <see cref="TimeConverter"/> to use.</param>
  25. /// <exception cref="ArgumentNullException">timeConverterType</exception>
  26. /// <exception cref="ArgumentException">Specified type is no time converter.;timeConverterType</exception>
  27. public TimeConverterAttribute(Type timeConverterType)
  28. {
  29. if (timeConverterType == null)
  30. throw new ArgumentNullException("timeConverterType");
  31. if (!typeof(TimeConverter).IsAssignableFrom(timeConverterType))
  32. throw new ArgumentException("Specified type is no time converter.", "timeConverterType");
  33. TimeConverterType = timeConverterType;
  34. }
  35. }