PageRenderTime 21ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/core/Builders/InlineDataPointProvider.cs

#
C# | 40 lines | 28 code | 7 blank | 5 comment | 4 complexity | 8606ce09c17a394746c5cb0679b3a287 MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // Copyright 2008, Charlie Poole
  3. // This is free software licensed under the NUnit license. You may
  4. // obtain a copy of the license at http://nunit.org.
  5. // ****************************************************************
  6. using System;
  7. using System.Reflection;
  8. using System.Collections;
  9. using NUnit.Core.Extensibility;
  10. namespace NUnit.Core.Builders
  11. {
  12. public class InlineDataPointProvider : IDataPointProvider
  13. {
  14. private static readonly string ParameterDataAttribute = "NUnit.Framework.ParameterDataAttribute";
  15. private static readonly string GetDataMethod = "GetData";
  16. #region IDataPointProvider Members
  17. public bool HasDataFor(ParameterInfo parameter)
  18. {
  19. return Reflect.HasAttribute(parameter, ParameterDataAttribute, false);
  20. }
  21. public IEnumerable GetDataFor(ParameterInfo parameter)
  22. {
  23. Attribute attr = Reflect.GetAttribute(parameter, ParameterDataAttribute, false);
  24. if (attr == null) return null;
  25. MethodInfo getData = attr.GetType().GetMethod(
  26. GetDataMethod,
  27. new Type[] { typeof(ParameterInfo) });
  28. if ( getData == null) return null;
  29. return getData.Invoke(attr, new object[] { parameter }) as IEnumerable;
  30. }
  31. #endregion
  32. }
  33. }