public static EventBean[] TypeCast(IList <EventBean> events, EventType targetType, EventAdapterService eventAdapterService) { var convertedArray = new EventBean[events.Count]; var count = 0; foreach (EventBean theEvent in events) { EventBean converted; if (theEvent is DecoratingEventBean) { var wrapper = (DecoratingEventBean)theEvent; if (targetType is MapEventType) { IDictionary <String, Object> props = new Dictionary <String, Object>(); props.PutAll(wrapper.DecoratingProperties); foreach (EventPropertyDescriptor propDesc in wrapper.UnderlyingEvent.EventType.PropertyDescriptors) { props.Put(propDesc.PropertyName, wrapper.UnderlyingEvent.Get(propDesc.PropertyName)); } converted = eventAdapterService.AdapterForTypedMap(props, targetType); } else { converted = eventAdapterService.AdapterForTypedWrapper(wrapper.UnderlyingEvent, wrapper.DecoratingProperties, targetType); } } else if ((theEvent.EventType is MapEventType) && (targetType is MapEventType)) { var mapEvent = (MappedEventBean)theEvent; converted = eventAdapterService.AdapterForTypedMap(mapEvent.Properties, targetType); } else if ((theEvent.EventType is MapEventType) && (targetType is WrapperEventType)) { converted = eventAdapterService.AdapterForTypedWrapper(theEvent, Collections.EmptyDataMap, targetType); } else if ((theEvent.EventType is BeanEventType) && (targetType is BeanEventType)) { converted = eventAdapterService.AdapterForTypedObject(theEvent.Underlying, targetType); } else if (theEvent.EventType is ObjectArrayEventType && targetType is ObjectArrayEventType) { Object[] convertedObjectArray = ObjectArrayEventType.ConvertEvent(theEvent, (ObjectArrayEventType)targetType); converted = eventAdapterService.AdapterForTypedObjectArray(convertedObjectArray, targetType); } else { throw new EPException("Unknown event type " + theEvent.EventType); } convertedArray[count] = converted; count++; } return(convertedArray); }