/// <summary>
        /// This will return null if unable to return a PropertyInfo instance for the named property that we can use with a CompilableEnumConversionPropertyGetter
        /// and that is valid according to the specified name matcher
        /// </summary>
        private PropertyInfo getProperty(Type srcType, string name, Type destPropertyType)
        {
            if (srcType == null)
            {
                throw new ArgumentNullException("srcType");
            }
            name = (name ?? "").Trim();
            if (name == "")
            {
                throw new ArgumentException("Null/blank name specified");
            }
            if (destPropertyType == null)
            {
                throw new ArgumentNullException("destPropertyType");
            }

            if (!destPropertyType.IsEnum)
            {
                return(null);
            }

            return(srcType.GetProperties().FirstOrDefault(p =>
                                                          p.GetIndexParameters().Length == 0 &&
                                                          _nameMatcher.IsMatch(name, p.Name) &&
                                                          p.PropertyType.IsEnum
                                                          ));
        }
Esempio n. 2
0
        /// <summary>
        /// This will return null if unable to return an ICompilablePropertyGetter for the named property that will return a value as the requested type
        /// </summary>
        public ICompilablePropertyGetter TryToGet(Type srcType, string propertyName, Type destPropertyType)
        {
            if (srcType == null)
            {
                throw new ArgumentNullException("srcType");
            }
            propertyName = (propertyName ?? "").Trim();
            if (propertyName == "")
            {
                throw new ArgumentException("Null/empty propertyName specified");
            }
            if (destPropertyType == null)
            {
                throw new ArgumentNullException("destPropertyType");
            }

            // Determine whether the destPropertyType implements IEnumerable<> and get the element type if so, if it doesn't match the destination
            // type of the converter then we'll not be able to work with it
            var destPropertyTypeAsEnumerableElement = tryToGetEnumerableElementTypeOf(destPropertyType);

            if (destPropertyTypeAsEnumerableElement != typeof(TPropertyAsRetrievedElement))
            {
                return(null);
            }

            var possibleProperties = srcType.GetProperties().Where(p =>
                                                                   p.GetIndexParameters().Length == 0 &&
                                                                   _nameMatcher.IsMatch(propertyName, p.Name)
                                                                   );

            foreach (var property in possibleProperties)
            {
                // Try to get element type of srcType, if srcType implements IEnumerable<>
                var srcPropertyTypeAsEnumerableElement = tryToGetEnumerableElementTypeOf(property.PropertyType);
                if (srcPropertyTypeAsEnumerableElement == typeof(TPropertyOnSourceElement))
                {
                    return((ICompilablePropertyGetter)Activator.CreateInstance(
                               typeof(EnumerableCompilablePropertyGetter <, , ,>).MakeGenericType(
                                   srcType,
                                   srcPropertyTypeAsEnumerableElement,
                                   destPropertyTypeAsEnumerableElement,
                                   destPropertyType
                                   ),
                               property,
                               _typeConverter,
                               _enumerableSetNullHandling
                               ));
                }
            }
            return(null);
        }
Esempio n. 3
0
            private void VerifyException(Exception ex)
            {
                if (String.IsNullOrEmpty(this.Attribute.MessagePattern))
                {
                    return;
                }

                INameMatcher matcher = NameMatcherFactory.CreateMatcher(
                    this.Attribute.MessageMatchType,
                    this.Attribute.MessagePattern);

                if (!matcher.IsMatch(ex.Message))
                {
                    throw new ExceptionMessageDoesNotMatchException(matcher, ex);
                }
            }
        /// <summary>
        /// This will return null if unable to return an ICompilablePropertyGetter for the named property that will return a value as the requested type
        /// </summary>
        public ICompilablePropertyGetter TryToGet(Type srcType, string propertyName, Type destPropertyType)
        {
            if (srcType == null)
            {
                throw new ArgumentNullException("srcType");
            }
            propertyName = (propertyName ?? "").Trim();
            if (propertyName == "")
            {
                throw new ArgumentException("Null/empty propertyName specified");
            }
            if (destPropertyType == null)
            {
                throw new ArgumentNullException("destPropertyType");
            }

            // If destination type does not match type converter's destination type then can not handle the request; return null
            if (destPropertyType != typeof(TPropertyAsRetrieved))
            {
                return(null);
            }

            // Try to get a property we CAN retrieve and convert as requested..
            var property = srcType.GetProperties().FirstOrDefault(p =>
                                                                  p.GetIndexParameters().Length == 0 &&
                                                                  _nameMatcher.IsMatch(propertyName, p.Name) &&
                                                                  p.PropertyType == typeof(TPropertyOnSource)
                                                                  );

            if (property == null)
            {
                return(null);
            }

            // .. if successful, use to instantiate a CompilableTypeConverterPropertyGetter
            return((ICompilablePropertyGetter)Activator.CreateInstance(
                       typeof(CompilableTypeConverterPropertyGetter <, ,>).MakeGenericType(
                           srcType,
                           property.PropertyType,
                           destPropertyType
                           ),
                       property,
                       _typeConverter
                       ));
        }
 public override void Run(object fixture)
 {
     System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         this.TestCase.Run(fixture);
     }
     finally
     {
         // looking for processes to kill
         INameMatcher matcher = NameMatcherFactory.CreateMatcher(this.Attribute.MatchType, this.Attribute.Name);
         foreach (Process p in Process.GetProcesses())
         {
             if (matcher.IsMatch(p.ProcessName))
             {
                 Console.WriteLine("Killing {0} {1}", p.Id, p.ProcessName);
                 p.Kill();
             }
         }
     }
 }