/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
- // ****************************************************************
- // Copyright 2008, Charlie Poole
- // This is free software licensed under the NUnit license. You may
- // obtain a copy of the license at http://nunit.org.
- // ****************************************************************
-
- using System;
- using System.Reflection;
- using System.Collections;
- using NUnit.Core.Extensibility;
-
- namespace NUnit.Core.Builders
- {
- public class InlineDataPointProvider : IDataPointProvider
- {
- private static readonly string ParameterDataAttribute = "NUnit.Framework.ParameterDataAttribute";
-
- private static readonly string GetDataMethod = "GetData";
-
- #region IDataPointProvider Members
-
- public bool HasDataFor(ParameterInfo parameter)
- {
- return Reflect.HasAttribute(parameter, ParameterDataAttribute, false);
- }
- public IEnumerable GetDataFor(ParameterInfo parameter)
- {
- Attribute attr = Reflect.GetAttribute(parameter, ParameterDataAttribute, false);
- if (attr == null) return null;
-
- MethodInfo getData = attr.GetType().GetMethod(
- GetDataMethod,
- new Type[] { typeof(ParameterInfo) });
- if ( getData == null) return null;
-
- return getData.Invoke(attr, new object[] { parameter }) as IEnumerable;
- }
- #endregion
- }
- }