private ReflectionPropFieldGetter MakeGetter(Type clazz, String fieldName) { FieldInfo field = clazz.GetField(fieldName); ReflectionPropFieldGetter getter = new ReflectionPropFieldGetter(field, SupportEventAdapterService.Service); return(getter); }
private ReflectionPropFieldGetter MakeGetter(Type clazz, String fieldName) { FieldInfo field = clazz.GetField(fieldName); ReflectionPropFieldGetter getter = new ReflectionPropFieldGetter(field, _container.Resolve <EventAdapterService>()); return(getter); }
public void TestGetter() { ReflectionPropFieldGetter getter = MakeGetter(typeof(SupportLegacyBean), "fieldLegacyVal"); Assert.AreEqual("a", getter.Get(unitTestBean)); try { EventBean eventBean = SupportEventBeanFactory.CreateObject(new Object()); getter.Get(eventBean); Assert.IsTrue(false); } catch (PropertyAccessException ex) { // Expected Log.Debug(".testGetter Expected exception, msg=" + ex.Message); } }
private void Initialize(bool isConfigured) { var propertyListBuilder = PropertyListBuilderFactory.CreateBuilder(OptionalLegacyDef); var properties = propertyListBuilder.AssessProperties(UnderlyingType); _propertyDescriptors = new EventPropertyDescriptor[properties.Count]; _propertyDescriptorMap = new Dictionary <String, EventPropertyDescriptor>(); PropertyNames = new String[properties.Count]; _simpleProperties = new Dictionary <String, SimplePropertyInfo>(); _mappedPropertyDescriptors = new Dictionary <String, InternalEventPropDescriptor>(); _indexedPropertyDescriptors = new Dictionary <String, InternalEventPropDescriptor>(); if (UsesSmartResolutionStyle) { _simpleSmartPropertyTable = new Dictionary <String, IList <SimplePropertyInfo> >(); _mappedSmartPropertyTable = new Dictionary <String, IList <SimplePropertyInfo> >(); _indexedSmartPropertyTable = new Dictionary <String, IList <SimplePropertyInfo> >(); } if ((OptionalLegacyDef == null) || (OptionalLegacyDef.CodeGeneration != CodeGenerationEnum.DISABLED)) { // get CGLib fast class FastClass = null; try { FastClass = FastClass.Create(UnderlyingType); } catch (Exception ex) { Log.Warn(".initialize Unable to obtain CGLib fast class and/or method implementation for class " + UnderlyingType.Name + ", error msg is " + ex.Message, ex); FastClass = null; } } int count = 0; foreach (InternalEventPropDescriptor desc in properties) { String propertyName = desc.PropertyName; Type underlyingType; Type componentType; bool isRequiresIndex; bool isRequiresMapkey; bool isIndexed; bool isMapped; bool isFragment; if (desc.PropertyType.GetValueOrDefault() == EventPropertyType.SIMPLE) { EventPropertyGetter getter; Type type; if (desc.ReadMethod != null) { getter = PropertyHelper.GetGetter(desc.PropertyName, desc.ReadMethod, FastClass, _eventAdapterService); type = desc.ReadMethod.ReturnType; } else { if (desc.AccessorField == null) { // Ignore property continue; } getter = new ReflectionPropFieldGetter(desc.AccessorField, _eventAdapterService); type = desc.AccessorField.FieldType; } underlyingType = type; componentType = null; isRequiresIndex = false; isRequiresMapkey = false; isIndexed = false; isMapped = false; if (type.IsGenericDictionary()) { isMapped = true; // We do not yet allow to fragment maps entries. // Class genericType = TypeHelper.GetGenericReturnTypeMap(desc.ReadMethod, desc.AccessorField); isFragment = false; if (desc.ReadMethod != null) { componentType = TypeHelper.GetGenericReturnTypeMap(desc.ReadMethod, false); } else if (desc.AccessorField != null) { componentType = TypeHelper.GetGenericFieldTypeMap(desc.AccessorField, false); } else { componentType = typeof(object); } } else if (type.IsArray) { isIndexed = true; isFragment = type.GetElementType().IsFragmentableType(); componentType = type.GetElementType(); } else if (type.IsImplementsInterface(typeof(IEnumerable))) { isIndexed = true; Type genericType = TypeHelper.GetGenericReturnType(desc.ReadMethod, desc.AccessorField, true); isFragment = genericType.IsFragmentableType(); if (genericType != null) { componentType = genericType; } else { componentType = typeof(Object); } } else { isMapped = false; isFragment = type.IsFragmentableType(); } _simpleProperties.Put(propertyName, new SimplePropertyInfo(type, getter, desc)); // Recognize that there may be properties with overlapping case-insentitive names if (UsesSmartResolutionStyle) { // Find the property in the smart property table var smartPropertyName = propertyName.ToLower(); var propertyInfoList = _simpleSmartPropertyTable.Get(smartPropertyName); if (propertyInfoList == null) { propertyInfoList = new List <SimplePropertyInfo>(); _simpleSmartPropertyTable.Put(smartPropertyName, propertyInfoList); } // Enter the property into the smart property list var propertyInfo = new SimplePropertyInfo(type, getter, desc); propertyInfoList.Add(propertyInfo); } } else if (desc.PropertyType.GetValueOrDefault() == EventPropertyType.MAPPED) { _mappedPropertyDescriptors.Put(propertyName, desc); underlyingType = desc.ReturnType; componentType = typeof(object); isRequiresIndex = false; isRequiresMapkey = desc.ReadMethod.GetParameterTypes().Length > 0; isIndexed = false; isMapped = true; isFragment = false; // Recognize that there may be properties with overlapping case-insentitive names if (UsesSmartResolutionStyle) { // Find the property in the smart property table var smartPropertyName = propertyName.ToLower(); var propertyInfoList = _mappedSmartPropertyTable.Get(smartPropertyName); if (propertyInfoList == null) { propertyInfoList = new List <SimplePropertyInfo>(); _mappedSmartPropertyTable.Put(smartPropertyName, propertyInfoList); } // Enter the property into the smart property list var propertyInfo = new SimplePropertyInfo(desc.ReturnType, null, desc); propertyInfoList.Add(propertyInfo); } } else if (desc.PropertyType.GetValueOrDefault() == EventPropertyType.INDEXED) { _indexedPropertyDescriptors.Put(propertyName, desc); underlyingType = desc.ReturnType; componentType = null; isRequiresIndex = desc.ReadMethod.GetParameterTypes().Length > 0; isRequiresMapkey = false; isIndexed = true; isMapped = false; isFragment = desc.ReturnType.IsFragmentableType(); if (UsesSmartResolutionStyle) { // Find the property in the smart property table String smartPropertyName = propertyName.ToLower(); IList <SimplePropertyInfo> propertyInfoList = _indexedSmartPropertyTable.Get(smartPropertyName); if (propertyInfoList == null) { propertyInfoList = new List <SimplePropertyInfo>(); _indexedSmartPropertyTable.Put(smartPropertyName, propertyInfoList); } // Enter the property into the smart property list var propertyInfo = new SimplePropertyInfo(desc.ReturnType, null, desc); propertyInfoList.Add(propertyInfo); } } else { continue; } PropertyNames[count] = desc.PropertyName; var descriptor = new EventPropertyDescriptor(desc.PropertyName, underlyingType, componentType, isRequiresIndex, isRequiresMapkey, isIndexed, isMapped, isFragment); _propertyDescriptors[count++] = descriptor; _propertyDescriptorMap.Put(descriptor.PropertyName, descriptor); } // Determine event type super types SuperTypes = GetBaseTypes(UnderlyingType, _eventAdapterService.BeanEventTypeFactory); if (SuperTypes != null && SuperTypes.Length == 0) { SuperTypes = null; } if (Metadata != null && Metadata.TypeClass == TypeClass.NAMED_WINDOW) { SuperTypes = null; } // Determine deep supertypes // Get base types (superclasses and interfaces), deep get of all in the tree ICollection <Type> supers = new HashSet <Type>(); GetSuper(UnderlyingType, supers); RemoveLibraryInterfaces(supers); // Remove CLR library base types // Cache the supertypes of this event type for later use _deepSuperTypes = new HashSet <EventType>(); foreach (Type superClass in supers) { EventType superType = _eventAdapterService.BeanEventTypeFactory.CreateBeanType(superClass.FullName, superClass, false, false, isConfigured); _deepSuperTypes.Add(superType); } DeepSuperTypes = _deepSuperTypes.ToArray(); }