public static PropertyInitializationResult Initialize(
            Type testClassType,
            MethodInfo testMethodInfo,
            object[] constructorArguments,
            IPropertyFactory propertyFactory)
        {
            var testClassInstance = Activator.CreateInstance(testClassType, constructorArguments);
            var propertyAttribute = testMethodInfo.GetCustomAttributes <PropertyAttribute>(inherit: true).Single();

            var genFactory = TryResolveGenFactory(testClassType, testMethodInfo);
            var customGens = ResolveCustomGens(testClassInstance, testMethodInfo);
            var property   = propertyFactory.CreateProperty(testMethodInfo, testClassInstance, genFactory, customGens);
            var replay     = testMethodInfo.GetCustomAttributes <ReplayAttribute>().SingleOrDefault()?.Replay;

            var propertyRunParameters = new PropertyRunParameters(
                Property: property,
                Iterations: propertyAttribute.Iterations,
                ShrinkLimit: propertyAttribute.ShrinkLimit,
                Replay: replay,
                Seed: replay == null ? propertyAttribute.NullableSeed : null,
                Size: replay == null ? propertyAttribute.NullableSize : null);

            return(new PropertyInitializationResult(
                       propertyAttribute.Runner,
                       propertyRunParameters,
                       propertyAttribute.Skip?.Length > 0 ? propertyAttribute.Skip : null));
        }
Esempio n. 2
0
        public Properties(
            TType declaringType,
            IPropertyFactory <TProperty, TIndexer, TType> propertyFactory,
            IDictionary <MethodInfo, Type> interfaceMethods)
        {
            List <TIndexer>  indexers   = new List <TIndexer>();
            List <TProperty> properties = new List <TProperty>();
            List <AbstractIndexerWithReflection>           abstractIndexers            = new List <AbstractIndexerWithReflection>();
            List <AbstractPropertyWithReflection>          abstractProperties          = new List <AbstractPropertyWithReflection>();
            List <ExplicitInterfaceIndexerWithReflection>  explicitInterfaceIndexers   = new List <ExplicitInterfaceIndexerWithReflection>();
            List <ExplicitInterfacePropertyWithReflection> explicitInterfaceProperties = new List <ExplicitInterfacePropertyWithReflection>();

            foreach (PropertyInfo property in declaringType.Type.GetAllProperties())
            {
                MethodInfo method = property.Method();
                Type       interfaceType;
                if (property.GetIndexParameters().Any())
                {
                    if (interfaceMethods.TryGetValue(method, out interfaceType))
                    {
                        explicitInterfaceIndexers.Add(new ExplicitInterfaceIndexerWithReflection(declaringType, interfaceType, property));
                    }
                    else if (method.IsAbstract)
                    {
                        abstractIndexers.Add(new AbstractIndexerWithReflection(declaringType, property));
                    }
                    else
                    {
                        indexers.Add(propertyFactory.CreateIndexer(declaringType, property));
                    }
                }
                else if (interfaceMethods.TryGetValue(method, out interfaceType))
                {
                    explicitInterfaceProperties.Add(new ExplicitInterfacePropertyWithReflection(declaringType, interfaceType, property));
                }
                else if (method.IsAbstract)
                {
                    abstractProperties.Add(new AbstractPropertyWithReflection(declaringType, property));
                }
                else
                {
                    properties.Add(propertyFactory.CreateProperty(declaringType, property));
                }
            }

            ExplicitInterfaceIndexersWithReflection   = explicitInterfaceIndexers;
            ExplicitInterfacePropertiesWithReflection = explicitInterfaceProperties;
            AbstractIndexersWithReflection            = abstractIndexers;
            AbstractPropertiesWithReflection          = abstractProperties;
            IndexersWithReflection   = indexers;
            PropertiesWithReflection = properties;
        }
Esempio n. 3
0
        public Properties(
            TType declaringType,
            IPropertyFactory <TProperty, TIndexer, TType> propertyFactory)
        {
            List <TIndexer>  indexers   = new List <TIndexer>();
            List <TProperty> properties = new List <TProperty>();
            List <AbstractIndexerWithMonoCecil>           abstractIndexers            = new List <AbstractIndexerWithMonoCecil>();
            List <AbstractPropertyWithMonoCecil>          abstractProperties          = new List <AbstractPropertyWithMonoCecil>();
            List <ExplicitInterfaceIndexerWithMonoCecil>  explicitInterfaceIndexers   = new List <ExplicitInterfaceIndexerWithMonoCecil>();
            List <ExplicitInterfacePropertyWithMonoCecil> explicitInterfaceProperties = new List <ExplicitInterfacePropertyWithMonoCecil>();

            foreach (PropertyDefinition property in declaringType.TypeDefinition.Properties)
            {
                MethodDefinition method = property.Method();
                if (property.Parameters.Any())
                {
                    if (property.Name.Contains("."))
                    {
                        explicitInterfaceIndexers.Add(new ExplicitInterfaceIndexerWithMonoCecil(declaringType, property));
                    }
                    else if (method.IsAbstract)
                    {
                        abstractIndexers.Add(new AbstractIndexerWithMonoCecil(declaringType, property));
                    }
                    else
                    {
                        indexers.Add(propertyFactory.CreateIndexer(declaringType, property));
                    }
                }
                else if (property.Name.Contains("."))
                {
                    explicitInterfaceProperties.Add(new ExplicitInterfacePropertyWithMonoCecil(declaringType, property));
                }
                else if (method.IsAbstract)
                {
                    abstractProperties.Add(new AbstractPropertyWithMonoCecil(declaringType, property));
                }
                else
                {
                    properties.Add(propertyFactory.CreateProperty(declaringType, property));
                }
            }

            ExplicitInterfaceIndexersWithMonoCecil   = explicitInterfaceIndexers;
            ExplicitInterfacePropertiesWithMonoCecil = explicitInterfaceProperties;
            AbstractIndexersWithMonoCecil            = abstractIndexers;
            AbstractPropertiesWithMonoCecil          = abstractProperties;
            IndexersWithMonoCecil   = indexers;
            PropertiesWithMonoCecil = properties;
        }
Esempio n. 4
0
 public virtual global::EnvDTE.Property Item(string propertyName)
 {
     return(propertyFactory.CreateProperty(propertyName));
 }
Esempio n. 5
0
 public Property Item(string propertyName)
 {
     return(propertyFactory.CreateProperty(propertyName));
 }