Esempio n. 1
0
 public CachingClassStrategy(IClassStrategy classStrategy)
 {
     this.classStrategy = classStrategy;
     lock (Cache) {
         Cache.Clear();
     }
 }
 public IList <MethodInfo> FindActions(IList <MethodInfo> candidates, IClassStrategy classStrategy)
 {
     return(candidates.Where(methodInfo => methodInfo.GetCustomAttribute <NakedObjectsIgnoreAttribute>() == null &&
                             !methodInfo.IsStatic &&
                             !methodInfo.IsGenericMethod &&
                             classStrategy.IsTypeToBeIntrospected(methodInfo.ReturnType) &&
                             ParametersAreSupported(methodInfo, classStrategy)).ToList());
 }
        public bool Filters(MethodInfo method, IClassStrategy classStrategy) {
            string typeName = method.DeclaringType == null ? "Unknown" : method.DeclaringType.FullName;

            if (classStrategy.IsSystemClass(method.DeclaringType)) {
                return true;
            }

            return false;
        }
        public bool Filters(PropertyInfo property, IClassStrategy classStrategy) {
            string typeName = property.DeclaringType == null ? "Unknown" : property.DeclaringType.FullName;

            if (classStrategy.IsSystemClass(property.DeclaringType)) {
                return true;
            }

            return false;
        }
        protected virtual IReflector Reflector(Metamodel metamodel, ILoggerFactory lf)
        {
            var config = new ObjectReflectorConfiguration(new[] { typeof(TestPoco), typeof(TestDomainObject), typeof(ArrayList) }, new Type[] { });
            var objectFactFactorySet = new ObjectFacetFactorySet(FacetFactories.OfType <IObjectFacetFactoryProcessor>().ToArray());

            ClassStrategy = new ObjectClassStrategy(config);
            var mockLogger1 = new Mock <ILogger <AbstractParallelReflector> >().Object;

            return(new ObjectReflector(objectFactFactorySet, (ObjectClassStrategy)ClassStrategy, metamodel, config, new IFacetDecorator[] { }, lf, mockLogger1));
        }
        public bool Filters(MethodInfo method, IClassStrategy classStrategy) {
            string typeName = method.DeclaringType == null ? "Unknown" : method.DeclaringType.FullName;

            if (classStrategy.IsSystemClass(method.DeclaringType)) {
                Log.InfoFormat("Skipping actions in {0} (system class according to ClassStrategy)", typeName);
                return true;
            }

            return false;
        }
        public bool Filters(PropertyInfo property, IClassStrategy classStrategy) {
            string typeName = property.DeclaringType == null ? "Unknown" : property.DeclaringType.FullName;

            if (classStrategy.IsSystemClass(property.DeclaringType)) {
                Log.InfoFormat("Skipping field {0} in {1} (system class according to ClassStrategy)", property.Name, typeName);
                return true;
            }

            return false;
        }
        public bool Filters(MethodInfo method, IClassStrategy classStrategy)
        {
            string typeName = method.DeclaringType == null ? "Unknown" : method.DeclaringType.FullName;

            if (classStrategy.IsSystemClass(method.DeclaringType))
            {
                return(true);
            }

            return(false);
        }
        public bool Filters(PropertyInfo property, IClassStrategy classStrategy)
        {
            string typeName = property.DeclaringType == null ? "Unknown" : property.DeclaringType.FullName;

            if (classStrategy.IsSystemClass(property.DeclaringType))
            {
                return(true);
            }

            return(false);
        }
        public bool Filters(MethodInfo method, IClassStrategy classStrategy)
        {
            string typeName = method.DeclaringType == null ? "Unknown" : method.DeclaringType.FullName;

            if (classStrategy.IsSystemClass(method.DeclaringType))
            {
                Log.InfoFormat("Skipping actions in {0} (system class according to ClassStrategy)", typeName);
                return(true);
            }

            return(false);
        }
 private bool ParametersAreSupported(MethodInfo method, IClassStrategy classStrategy)
 {
     foreach (ParameterInfo parameterInfo in method.GetParameters())
     {
         if (!classStrategy.IsTypeToBeIntrospected(parameterInfo.ParameterType))
         {
             Log.InfoFormat("Ignoring method: {0}.{1} because parameter '{2}' is of type {3}", method.DeclaringType, method.Name, parameterInfo.Name, parameterInfo.ParameterType);
             return(false);
         }
     }
     return(true);
 }
Esempio n. 12
0
        public bool Filters(PropertyInfo property, IClassStrategy classStrategy)
        {
            string typeName = property.DeclaringType == null ? "Unknown" : property.DeclaringType.FullName;

            if (classStrategy.IsSystemClass(property.DeclaringType))
            {
                Log.InfoFormat("Skipping field {0} in {1} (system class according to ClassStrategy)", property.Name, typeName);
                return(true);
            }

            return(false);
        }
        public bool Filters(PropertyInfo property, IClassStrategy classStrategy)
        {
            string typeName = property.DeclaringType == null ? "Unknown" : property.DeclaringType.FullName;

            //todo rework this so that factories filter actions appropraitely
            if (classStrategy.IsSystemClass(property.DeclaringType))
            {
                Log.InfoFormat("Skipping fields in {0} (system class according to ClassStrategy)", typeName);
                return(true);
            }

            return(false);
        }
 private bool ParametersAreSupported(MethodInfo method, IClassStrategy classStrategy)
 {
     foreach (ParameterInfo parameterInfo in method.GetParameters())
     {
         if (!classStrategy.IsTypeToBeIntrospected(parameterInfo.ParameterType))
         {
             // log if not a System or NOF type
             if (!TypeUtils.IsSystem(method.DeclaringType) && !TypeUtils.IsNakedObjects(method.DeclaringType))
             {
                 Log.WarnFormat("Ignoring method: {0}.{1} because parameter '{2}' is of type {3}", method.DeclaringType, method.Name, parameterInfo.Name, parameterInfo.ParameterType);
             }
             return(false);
         }
     }
     return(true);
 }
        public bool Filters(MethodInfo method, IClassStrategy classStrategy)
        {
            string typeName = method.DeclaringType == null ? "Unknown" : method.DeclaringType.FullName;

            //todo rework this so that factories filter actions appropraitely
            if (classStrategy.IsSystemClass(method.DeclaringType))
            {
                Log.InfoFormat("Skipping fields in {0} (system class according to ClassStrategy)", typeName);
                return(true);
            }

            if (method.GetCustomAttribute <NakedObjectsIgnoreAttribute>() != null)
            {
                Log.InfoFormat("Ignoring method: {0}.{1} because it is ignored", typeName, method.Name);
                return(true);
            }

            if (method.IsStatic)
            {
                Log.InfoFormat("Ignoring method: {0}.{1} because it is static", typeName, method.Name);
                return(true);
            }

            if (method.IsGenericMethod)
            {
                Log.InfoFormat("Ignoring method: {0}.{1} because it is generic", typeName, method.Name);
                return(true);
            }

            if (!classStrategy.IsTypeToBeIntrospected(method.ReturnType))
            {
                Log.InfoFormat("Ignoring method: {0}.{1} because return type is of type {3}", typeName, method.Name, method.ReturnType);
                return(true);
            }

            foreach (ParameterInfo parameterInfo in method.GetParameters())
            {
                if (!classStrategy.IsTypeToBeIntrospected(parameterInfo.ParameterType))
                {
                    Log.InfoFormat("Ignoring method: {0}.{1} because parameter '{2}' is of type {3}", typeName, method.Name, parameterInfo.Name, parameterInfo.ParameterType);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 16
0
 public Reflector(IClassStrategy classStrategy,
                  IMetamodelBuilder metamodel,
                  IReflectorConfiguration config,
                  IMenuFactory menuFactory,
                  IEnumerable <IFacetDecorator> facetDecorators,
                  IEnumerable <IFacetFactory> facetFactories,
                  ILoggerFactory loggerFactory,
                  ILogger <Reflector> logger)
 {
     ClassStrategy      = classStrategy ?? throw new InitialisationException($"{nameof(classStrategy)} is null");
     this.metamodel     = metamodel ?? throw new InitialisationException($"{nameof(metamodel)} is null");
     this.config        = config ?? throw new InitialisationException($"{nameof(config)} is null");
     this.menuFactory   = menuFactory ?? throw new InitialisationException($"{nameof(menuFactory)} is null");
     this.loggerFactory = loggerFactory ?? throw new InitialisationException($"{nameof(loggerFactory)} is null");
     this.logger        = logger ?? throw new InitialisationException($"{nameof(logger)} is null");
     facetDecoratorSet  = new FacetDecoratorSet(facetDecorators.ToArray());
     FacetFactorySet    = new FacetFactorySet(facetFactories.ToArray());
 }
        public Reflector(IClassStrategy classStrategy,
                         IMetamodelBuilder metamodel,
                         IReflectorConfiguration config,
                         IMenuFactory menuFactory,
                         IFacetDecorator[] facetDecorators,
                         IFacetFactory[] facetFactories)
        {
            Assert.AssertNotNull(classStrategy);
            Assert.AssertNotNull(metamodel);
            Assert.AssertNotNull(config);
            Assert.AssertNotNull(menuFactory);

            this.classStrategy = classStrategy;
            this.metamodel     = metamodel;
            this.config        = config;
            this.menuFactory   = menuFactory;
            facetDecoratorSet  = new FacetDecoratorSet(facetDecorators);
            FacetFactorySet    = new FacetFactorySet(facetFactories);
        }
        private int?GetValueTypeTypicalLength(Type type, IClassStrategy classStrategy)
        {
            var actualType = classStrategy.GetType(type);

            if (actualType != null)
            {
                var fn = actualType.FullName;


                if (actualType.IsArray)
                {
                    var elementType = actualType.GetElementType();

                    if (elementType == typeof(string))
                    {
                        return(null);
                    }

                    // byte[] has special facet factory

                    if (elementType != null && elementType.IsValueType && elementType == typeof(byte))
                    {
                        return(20);
                    }

                    return(null);
                }

                if (actualType.IsEnum)
                {
                    return(11);
                }

                if (TypeMap.ContainsKey(actualType))
                {
                    return(TypeMap[actualType]);
                }
            }

            return(null);
        }
Esempio n. 19
0
        public ParallelReflector(IClassStrategy classStrategy,
                                 IMetamodelBuilder metamodel,
                                 IReflectorConfiguration config,
                                 IFunctionalReflectorConfiguration functionalConfig,
                                 IMenuFactory menuFactory,
                                 IEnumerable <IFacetDecorator> facetDecorators,
                                 IEnumerable <IFacetFactory> facetFactories,
                                 ILoggerFactory loggerFactory,
                                 ILogger <ParallelReflector> logger)
        {
            ClassStrategy         = classStrategy ?? throw new InitialisationException($"{nameof(classStrategy)} is null");
            initialMetamodel      = metamodel ?? throw new InitialisationException($"{nameof(metamodel)} is null");
            this.config           = config ?? throw new InitialisationException($"{nameof(config)} is null");
            this.functionalConfig = functionalConfig;
            this.menuFactory      = menuFactory ?? throw new InitialisationException($"{nameof(menuFactory)} is null");
            this.loggerFactory    = loggerFactory ?? throw new InitialisationException($"{nameof(loggerFactory)} is null");
            this.logger           = logger ?? throw new InitialisationException($"{nameof(logger)} is null");
            facetDecoratorSet     = new FacetDecoratorSet(facetDecorators.ToArray());
            FacetFactorySet       = new FacetFactorySet(facetFactories.Where(f => f.ReflectionTypes.HasFlag(ReflectionType.ObjectOriented)).ToArray());

            FunctionalFacetFactorySet = new FacetFactorySet(facetFactories.Where(f => f.ReflectionTypes.HasFlag(ReflectionType.Functional)).ToArray());
        }
        private static int?GetValueTypeTypicalLength(Type type, IClassStrategy classStrategy)
        {
            var actualType = TypeKeyUtils.FilterNullableAndProxies(type);

            if (actualType is not null)
            {
                if (actualType.IsArray)
                {
                    var elementType = actualType.GetElementType();

                    if (elementType == typeof(string))
                    {
                        return(null);
                    }

                    // byte[] has special facet factory

                    if (elementType is not null && elementType.IsValueType && elementType == typeof(byte))
                    {
                        return(20);
                    }

                    return(null);
                }

                if (actualType.IsEnum)
                {
                    return(11);
                }

                if (TypeMap.ContainsKey(actualType))
                {
                    return(TypeMap[actualType]);
                }
            }

            return(null);
        }
Esempio n. 21
0
 /// <summary>
 ///     Whether this method is recognized (and should be ignored) by
 ///     any of the registered <see cref="IFacetFactory" />
 /// </summary>
 /// <para>
 ///     Checks:
 /// </para>
 /// <list type="bullet">
 ///     <item>
 ///         the method's prefix against the prefixes supplied by any <see cref="IMethodPrefixBasedFacetFactory" />
 ///     </item>
 ///     <item>
 ///         the method against any <see cref="IMethodFilteringFacetFactory" />
 ///     </item>
 /// </list>
 /// <para>
 ///     The design of <see cref="IMethodPrefixBasedFacetFactory" /> (whereby this
 ///     facet factory set does the work) is a slight performance optimization
 ///     for when there are multiple facet factories that search for the
 ///     same prefix.
 /// </para>
 public bool Filters(MethodInfo method, IClassStrategy classStrategy) {
     return methodFilteringFactories.Any(factory => factory.Filters(method, classStrategy));
 }
Esempio n. 22
0
 public virtual IList <PropertyInfo> FindProperties(IList <PropertyInfo> candidates, IClassStrategy classStrategy) => new PropertyInfo[]
 {
 };
 public override IList <PropertyInfo> FindProperties(IList <PropertyInfo> candidates, IClassStrategy classStrategy)
 {
     candidates = candidates.Where(property => !CollectionUtils.IsQueryable(property.PropertyType)).ToList();
     return(PropertiesToBeIntrospected(candidates, classStrategy));
 }
Esempio n. 24
0
        public IList<MethodInfo> FindActions(IList<MethodInfo> candidates, IClassStrategy classStrategy) {
            return actionIdentifyingFactories.SelectMany(fact => fact.FindActions(candidates, classStrategy)).ToList();

        }
 public IList <PropertyInfo> FindProperties(IList <PropertyInfo> candidates, IClassStrategy classStrategy)
 {
     return(propertyOrCollectionIdentifyingFactories.SelectMany(fact => fact.FindProperties(candidates, classStrategy)).ToArray());
 }
 /// <summary>
 ///     Whether this method is recognized (and should be ignored) by
 ///     any of the registered <see cref="IFacetFactory" />
 /// </summary>
 /// <para>
 ///     Checks:
 /// </para>
 /// <list type="bullet">
 ///     <item>
 ///         the method's prefix against the prefixes supplied by any <see cref="IMethodPrefixBasedFacetFactory" />
 ///     </item>
 ///     <item>
 ///         the method against any <see cref="IMethodFilteringFacetFactory" />
 ///     </item>
 /// </list>
 /// <para>
 ///     The design of <see cref="IMethodPrefixBasedFacetFactory" /> (whereby this
 ///     facet factory set does the work) is a slight performance optimization
 ///     for when there are multiple facet factories that search for the
 ///     same prefix.
 /// </para>
 public bool Filters(MethodInfo method, IClassStrategy classStrategy)
 {
     return(methodFilteringFactories.Any(factory => factory.Filters(method, classStrategy)));
 }
Esempio n. 27
0
 public Metamodel(IClassStrategy classStrategy, ISpecificationCache cache, ILogger <Metamodel> logger)
 {
     this.classStrategy = classStrategy;
     this.cache         = cache;
     this.logger        = logger;
 }
Esempio n. 28
0
 protected IList <PropertyInfo> PropertiesToBeIntrospected(IList <PropertyInfo> candidates, IClassStrategy classStrategy)
 {
     return(candidates.Where(property => property.GetGetMethod() != null &&
                             classStrategy.IsTypeToBeIntrospected(property.PropertyType) &&
                             IsPropertyIncluded(property)
                             ).ToList());
 }
Esempio n. 29
0
 public bool Filters(PropertyInfo property, IClassStrategy classStrategy) {
     return propertyFilteringFactories.Any(factory => factory.Filters(property, classStrategy));
 }
Esempio n. 30
0
 public IntrospectionControlParameters(IFacetFactorySet facetFactorySet,
                                       IClassStrategy classStrategy) {
     FacetFactorySet = facetFactorySet;
     ClassStrategy = classStrategy;
 }
Esempio n. 31
0
 public IList<PropertyInfo> FindProperties(IList<PropertyInfo> candidates, IClassStrategy classStrategy) {
     return propertyOrCollectionIdentifyingFactories.SelectMany(fact => fact.FindProperties(candidates, classStrategy)).ToList();
 }
 public override IList<PropertyInfo> FindProperties(IList<PropertyInfo> candidates, IClassStrategy classStrategy) {
     candidates = candidates.Where(property => !CollectionUtils.IsQueryable(property.PropertyType)).ToList();
     return PropertiesToBeIntrospected(candidates, classStrategy);
 }
 public override IList<PropertyInfo> FindCollectionProperties(IList<PropertyInfo> candidates, IClassStrategy classStrategy) {
     IList<Type> collectionTypes = BuildCollectionTypes(candidates);
     candidates = candidates.Where(property => collectionTypes.Contains(property.PropertyType)).ToList();
     return PropertiesToBeIntrospected(candidates, classStrategy);
 }
 public IList<MethodInfo> FindActions(IList<MethodInfo> candidates, IClassStrategy classStrategy) {
     return candidates.Where(methodInfo => methodInfo.GetCustomAttribute<NakedObjectsIgnoreAttribute>() == null &&
                                           !methodInfo.IsStatic &&
                                           !methodInfo.IsGenericMethod &&
                                           classStrategy.IsTypeToBeIntrospected(methodInfo.ReturnType) &&
                                           ParametersAreSupported(methodInfo, classStrategy)).ToList();
 }
 public override IList <PropertyInfo> FindProperties(IList <PropertyInfo> candidates, IClassStrategy classStrategy)
 {
     return(candidates.Where(property => property.GetGetMethod() != null &&
                             property.GetCustomAttribute <NakedObjectsIgnoreAttribute>() == null &&
                             classStrategy.IsTypeToBeIntrospected(property.PropertyType) &&
                             !CollectionUtils.IsQueryable(property.PropertyType)).ToList());
 }
 protected IList<PropertyInfo> PropertiesToBeIntrospected(IList<PropertyInfo> candidates, IClassStrategy classStrategy) {
     return candidates.Where(property => property.GetGetMethod() != null &&
                                         classStrategy.IsTypeToBeIntrospected(property.PropertyType) &&
                                         IsPropertyIncluded(property)
                             ).ToList();
 }
 public bool Filters(MethodInfo method, IClassStrategy classStrategy) {
     return IsComplementaryMethod(method);
 }
Esempio n. 38
0
 public DR(IClassStrategy classStrategy)
 {
     this.classStrategy = classStrategy;
 }
 public bool Filters(PropertyInfo property, IClassStrategy classStrategy)
 {
     return(propertyFilteringFactories.Any(factory => factory.Filters(property, classStrategy)));
 }
Esempio n. 40
0
        public override IList <PropertyInfo> FindCollectionProperties(IList <PropertyInfo> candidates, IClassStrategy classStrategy)
        {
            IList <Type> collectionTypes = BuildCollectionTypes(candidates);

            candidates = candidates.Where(property => collectionTypes.Contains(property.PropertyType)).ToArray();
            return(PropertiesToBeIntrospected(candidates, classStrategy));
        }
 public IList <MethodInfo> FindActions(IList <MethodInfo> candidates, IClassStrategy classStrategy)
 {
     return(actionIdentifyingFactories.SelectMany(fact => fact.FindActions(candidates, classStrategy)).ToArray());
 }
 private bool ParametersAreSupported(MethodInfo method, IClassStrategy classStrategy) {
     foreach (ParameterInfo parameterInfo in method.GetParameters()) {
         if (!classStrategy.IsTypeToBeIntrospected(parameterInfo.ParameterType)) {
             Log.InfoFormat("Ignoring method: {0}.{1} because parameter '{2}' is of type {3}", method.DeclaringType, method.Name, parameterInfo.Name, parameterInfo.ParameterType);
             return false;
         }
     }
     return true;
 }
Esempio n. 43
0
 public TypeKeyComparer(IClassStrategy classStrategy) => this.classStrategy = classStrategy;
 public Metamodel(IClassStrategy classStrategy, ISpecificationCache cache) {
     this.classStrategy = classStrategy;
     this.cache = cache;
 }
 public virtual IList<PropertyInfo> FindProperties(IList<PropertyInfo> candidates, IClassStrategy classStrategy) {
     return new PropertyInfo[] {};
 }
 private static void AddFacetDerivedFromTypeIfPresent(ISpecification holder, Type type, IClassStrategy classStrategy) => FacetUtils.AddFacet(GetTypicalLengthFacet(type, holder, classStrategy));
        private static ITypicalLengthFacet GetTypicalLengthFacet(Type type, ISpecification holder, IClassStrategy classStrategy)
        {
            var attribute = type.GetCustomAttribute <TypicalLengthAttribute>();

            if (attribute is not null)
            {
                return(new TypicalLengthFacetDerivedFromType(attribute.Value, holder));
            }

            var length = GetValueTypeTypicalLength(type, classStrategy);

            return(length is not null ? new TypicalLengthFacetDerivedFromType(length.Value, holder) : null);
        }
 private bool ParametersAreSupported(MethodInfo method, IClassStrategy classStrategy) {
     foreach (ParameterInfo parameterInfo in method.GetParameters()) {
         if (!classStrategy.IsTypeToBeIntrospected(parameterInfo.ParameterType)) {
             // log if not a System or NOF type 
             if (!TypeUtils.IsSystem(method.DeclaringType) && !TypeUtils.IsNakedObjects(method.DeclaringType)) {
                 Log.WarnFormat("Ignoring method: {0}.{1} because parameter '{2}' is of type {3}", method.DeclaringType, method.Name, parameterInfo.Name, parameterInfo.ParameterType);
             }
             return false;
         }
     }
     return true;
 }