PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 40 lines | 28 code | 7 blank | 5 comment | 4 complexity | 8606ce09c17a394746c5cb0679b3a287 MD5 | raw file
 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
 7using System;
 8using System.Reflection;
 9using System.Collections;
10using NUnit.Core.Extensibility;
11
12namespace NUnit.Core.Builders
13{
14    public class InlineDataPointProvider : IDataPointProvider
15    {
16        private static readonly string ParameterDataAttribute = "NUnit.Framework.ParameterDataAttribute";
17
18        private static readonly string GetDataMethod = "GetData";
19
20        #region IDataPointProvider Members
21
22        public bool HasDataFor(ParameterInfo parameter)
23        {
24            return Reflect.HasAttribute(parameter, ParameterDataAttribute, false);
25        }
26                public IEnumerable GetDataFor(ParameterInfo parameter)
27        {
28            Attribute attr = Reflect.GetAttribute(parameter, ParameterDataAttribute, false);
29            if (attr == null) return null;
30
31            MethodInfo getData = attr.GetType().GetMethod(
32                GetDataMethod,
33                new Type[] { typeof(ParameterInfo) });
34            if ( getData == null) return null;
35            
36            return getData.Invoke(attr, new object[] { parameter }) as IEnumerable;
37        }
38        #endregion
39    }
40}