You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
782 B

5 years ago
5 years ago
5 years ago
5 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace IPA.Utilities
  7. {
  8. /// <summary>
  9. /// A class providing various extension methods.
  10. /// </summary>
  11. public static class Extensions
  12. {
  13. /// <summary>
  14. /// Gets the default value for a given <see cref="Type"/>.
  15. /// </summary>
  16. /// <param name="type">the <see cref="Type"/> to get the default value for</param>
  17. /// <returns>the default value of <paramref name="type"/></returns>
  18. public static object GetDefault(this Type type)
  19. {
  20. if (type.IsValueType)
  21. {
  22. return Activator.CreateInstance(type);
  23. }
  24. return null;
  25. }
  26. }
  27. }