Esempio n. 1
0
        public override EventPropertyGetter GetGetter(BeanEventType eventType, EventAdapterService eventAdapterService)
        {
            InternalEventPropDescriptor propertyDesc = eventType.GetMappedProperty(PropertyNameAtomic);

            if (propertyDesc != null)
            {
                var method    = propertyDesc.ReadMethod;
                var fastClass = eventType.FastClass;
                if (fastClass != null)
                {
                    var fastMethod = fastClass.GetMethod(method);
                    return(new KeyedFastPropertyGetter(fastMethod, _key, eventAdapterService));
                }
                else
                {
                    return(new KeyedMethodPropertyGetter(method, _key, eventAdapterService));
                }
            }

            // Try the array as a simple property
            propertyDesc = eventType.GetSimpleProperty(PropertyNameAtomic);
            if (propertyDesc == null)
            {
                return(null);
            }

            var returnType = propertyDesc.ReturnType;

            // Unlike Java, CLR based maps are strongly typed ... the mechanics
            // for identifying and extracting the map contents are also different.
            if (!returnType.IsGenericStringDictionary())
            {
                return(null);
            }

            if (propertyDesc.ReadMethod != null)
            {
                var fastClass = eventType.FastClass;
                var method    = propertyDesc.ReadMethod;
                if (fastClass != null)
                {
                    var fastMethod = fastClass.GetMethod(method);
                    return(new KeyedMapFastPropertyGetter(method, fastMethod, _key, eventAdapterService));
                }
                else
                {
                    return(new KeyedMapMethodPropertyGetter(method, _key, eventAdapterService));
                }
            }
            else
            {
                var field = propertyDesc.AccessorField;
                return(new KeyedMapFieldPropertyGetter(field, _key, eventAdapterService));
            }
        }
Esempio n. 2
0
        public override GenericPropertyDesc GetPropertyTypeGeneric(BeanEventType eventType,
                                                                   EventAdapterService eventAdapterService)
        {
            InternalEventPropDescriptor descriptor = eventType.GetIndexedProperty(PropertyNameAtomic);

            if (descriptor != null)
            {
                return(new GenericPropertyDesc(descriptor.ReturnType));
            }

            // Check if this is an method returning array which is a type of simple property
            descriptor = eventType.GetSimpleProperty(PropertyNameAtomic);
            if (descriptor == null)
            {
                return(null);
            }

            Type returnType = descriptor.ReturnType;

            if (returnType.IsArray)
            {
                return(new GenericPropertyDesc(returnType.GetElementType()));
            }
            else if (returnType.IsImplementsInterface(typeof(IEnumerable)))
            {
                if (descriptor.ReadMethod != null)
                {
                    Type genericType = TypeHelper.GetGenericReturnType(descriptor.ReadMethod, false);
                    return(new GenericPropertyDesc(genericType));
                }
                else if (descriptor.AccessorField != null)
                {
                    Type genericType = TypeHelper.GetGenericFieldType(descriptor.AccessorField, false);
                    return(new GenericPropertyDesc(genericType));
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Esempio n. 3
0
        public override EventPropertyGetter GetGetter(BeanEventType eventType, EventAdapterService eventAdapterService)
        {
            FastClass fastClass = eventType.FastClass;
            InternalEventPropDescriptor propertyDesc = eventType.GetIndexedProperty(PropertyNameAtomic);

            if (propertyDesc != null)
            {
                if (fastClass != null)
                {
                    MethodInfo method     = propertyDesc.ReadMethod;
                    FastMethod fastMethod = fastClass.GetMethod(method);
                    return(new KeyedFastPropertyGetter(fastMethod, _index, eventAdapterService));
                }
                else
                {
                    return(new KeyedMethodPropertyGetter(propertyDesc.ReadMethod, _index, eventAdapterService));
                }
            }

            // Try the array as a simple property
            propertyDesc = eventType.GetSimpleProperty(PropertyNameAtomic);
            if (propertyDesc == null)
            {
                return(null);
            }

            Type returnType = propertyDesc.ReturnType;

            if (returnType.IsArray)
            {
                if (propertyDesc.ReadMethod != null)
                {
                    MethodInfo method = propertyDesc.ReadMethod;
                    if (fastClass != null)
                    {
                        FastMethod fastMethod = fastClass.GetMethod(method);
                        return(new ArrayFastPropertyGetter(fastMethod, _index, eventAdapterService));
                    }
                    else
                    {
                        return(new ArrayMethodPropertyGetter(method, _index, eventAdapterService));
                    }
                }
                else
                {
                    FieldInfo field = propertyDesc.AccessorField;
                    return(new ArrayFieldPropertyGetter(field, _index, eventAdapterService));
                }
            }
            else if (returnType.IsImplementsInterface(typeof(IList <object>)))
            {
                if (propertyDesc.ReadMethod != null)
                {
                    MethodInfo method = propertyDesc.ReadMethod;
                    if (fastClass != null)
                    {
                        FastMethod fastMethod = fastClass.GetMethod(method);
                        return(new ListFastPropertyGetter(method, fastMethod, _index, eventAdapterService));
                    }
                    else
                    {
                        return(new ListMethodPropertyGetter(method, _index, eventAdapterService));
                    }
                }
                else
                {
                    FieldInfo field = propertyDesc.AccessorField;
                    return(new ListFieldPropertyGetter(field, _index, eventAdapterService));
                }
            }
            else if (returnType.IsImplementsInterface(typeof(IEnumerable)))
            {
                if (propertyDesc.ReadMethod != null)
                {
                    MethodInfo method = propertyDesc.ReadMethod;
                    if (fastClass != null)
                    {
                        FastMethod fastMethod = fastClass.GetMethod(method);
                        return(new EnumerableFastPropertyGetter(method, fastMethod, _index, eventAdapterService));
                    }
                    else
                    {
                        return(new EnumerableMethodPropertyGetter(method, _index, eventAdapterService));
                    }
                }
                else
                {
                    FieldInfo field = propertyDesc.AccessorField;
                    return(new EnumerableFieldPropertyGetter(field, _index, eventAdapterService));
                }
            }

            return(null);
        }