Exemple #1
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;
        }
Exemple #2
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;
        }