Ejemplo n.º 1
0
        private object GetProviderObjectFromMember(MemberInfo member)
        {
            object providerObject = null;
            object instance       = null;

            switch (member.MemberType)
            {
            case MemberTypes.Property:
                PropertyInfo providerProperty = member as PropertyInfo;
                MethodInfo   getMethod        = providerProperty.GetGetMethod(true);
                if (!getMethod.IsStatic)
                {
                    instance = ProviderCache.GetInstanceOf(providerType);
                }
                providerObject = providerProperty.GetValue(instance, null);
                break;

            case MemberTypes.Method:
                MethodInfo providerMethod = member as MethodInfo;
                if (!providerMethod.IsStatic)
                {
                    instance = ProviderCache.GetInstanceOf(providerType);
                }
                providerObject = providerMethod.Invoke(instance, null);
                break;

            case MemberTypes.Field:
                FieldInfo providerField = member as FieldInfo;
                if (!providerField.IsStatic)
                {
                    instance = ProviderCache.GetInstanceOf(providerType);
                }
                providerObject = providerField.GetValue(instance);
                break;
            }

            return(providerObject);
        }
Ejemplo n.º 2
0
        public System.Collections.IEnumerable GetDataFor(System.Reflection.ParameterInfo parameter)
        {
            ArrayList datapoints = new ArrayList();

            Type       parameterType = parameter.ParameterType;
            MemberInfo method        = parameter.Member;
            Type       fixtureType   = method.ReflectedType;

            foreach (FieldInfo field in fixtureType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
            {
                if (field.FieldType == parameterType && Reflect.HasAttribute(field, DatapointAttribute, true))
                {
                    datapoints.Add(field.GetValue(ProviderCache.GetInstanceOf(fixtureType)));
                }
                else if (field.FieldType.IsArray && field.FieldType.GetElementType() == parameterType &&
                         Reflect.HasAttribute(field, DatapointsAttribute, true))
                {
                    datapoints.AddRange((ICollection)field.GetValue(ProviderCache.GetInstanceOf(fixtureType)));
                }
            }

            return(datapoints);
        }
Ejemplo n.º 3
0
        public System.Collections.IEnumerable GetDataFor(System.Reflection.ParameterInfo parameter)
        {
            ArrayList datapoints = new ArrayList();

            Type parameterType = parameter.ParameterType;
            Type fixtureType   = parameter.Member.ReflectedType;

            foreach (MemberInfo member in fixtureType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
            {
                if (Reflect.HasAttribute(member, DatapointAttribute, true))
                {
                    if (GetTypeFromMemberInfo(member) == parameterType &&
                        member.MemberType == MemberTypes.Field)
                    {
                        FieldInfo field = member as FieldInfo;
                        if (field.IsStatic)
                        {
                            datapoints.Add(field.GetValue(null));
                        }
                        else
                        {
                            datapoints.Add(field.GetValue(ProviderCache.GetInstanceOf(fixtureType)));
                        }
                    }
                }
                else if (Reflect.HasAttribute(member, DatapointsAttribute, true))
                {
                    if (GetElementTypeFromMemberInfo(member) == parameterType)
                    {
                        object instance;

                        switch (member.MemberType)
                        {
                        case MemberTypes.Field:
                            FieldInfo field = member as FieldInfo;
                            instance = field.IsStatic ? null : ProviderCache.GetInstanceOf(fixtureType);
                            foreach (object data in (IEnumerable)field.GetValue(instance))
                            {
                                datapoints.Add(data);
                            }
                            break;

                        case MemberTypes.Property:
                            PropertyInfo property  = member as PropertyInfo;
                            MethodInfo   getMethod = property.GetGetMethod(true);
                            instance = getMethod.IsStatic ? null : ProviderCache.GetInstanceOf(fixtureType);
                            foreach (object data in (IEnumerable)property.GetValue(instance, null))
                            {
                                datapoints.Add(data);
                            }
                            break;

                        case MemberTypes.Method:
                            MethodInfo method = member as MethodInfo;
                            instance = method.IsStatic ? null : ProviderCache.GetInstanceOf(fixtureType);
                            foreach (object data in (IEnumerable)method.Invoke(instance, Type.EmptyTypes))
                            {
                                datapoints.Add(data);
                            }
                            break;
                        }
                    }
                }
            }

            if (datapoints.Count == 0)
            {
                if (parameterType == typeof(bool))
                {
                    datapoints.Add(true);
                    datapoints.Add(false);
                }
                else if (parameterType.IsEnum)
                {
                    datapoints.AddRange(System.Enum.GetValues(parameterType));
                }
            }

            return(datapoints);
        }