private static SerdeProvision DetermineSerdeFromProviders(
            Type type,
            ICollection <SerdeProvider> serdeProviders,
            SerdeProviderAdditionalInfo additionalInfo)
        {
            if (serdeProviders.IsEmpty())
            {
                return(null);
            }

            SerdeProviderContextClass context = new SerdeProviderContextClass(type, additionalInfo);

            foreach (SerdeProvider provider in serdeProviders)
            {
                try {
                    SerdeProvision serde = provider.ResolveSerdeForClass(context);
                    if (serde != null)
                    {
                        return(serde);
                    }
                }
                catch (DataInputOutputSerdeException) {
                    throw;
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception ex) {
                    throw HandleProviderRuntimeException(provider, type, ex);
                }
            }

            return(null);
        }
        public DataInputOutputSerdeForge SerdeForEventTypeExternalProvider(
            BaseNestableEventType eventType,
            StatementRawInfo raw)
        {
            if (serdeProviders.IsEmpty())
            {
                return(null);
            }

            SerdeProviderEventTypeContext context = new SerdeProviderEventTypeContext(raw, eventType);

            foreach (SerdeProvider provider in serdeProviders)
            {
                try {
                    SerdeProvision serde = provider.ResolveSerdeForEventType(context);
                    if (serde != null)
                    {
                        return(serde.ToForge());
                    }
                }
                catch (DataInputOutputSerdeException) {
                    throw;
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception ex) {
                    throw new DataInputOutputSerdeException(
                              "Unexpected exception invoking serde provider '" +
                              provider.GetType().Name +
                              "' passing for event type '" +
                              eventType.Name +
                              "': " +
                              ex.Message,
                              ex);
                }
            }

            return(null);
        }
        private DataInputOutputSerdeForge SerdeForClass(
            Type type,
            SerdeProviderAdditionalInfo additionalInfo)
        {
            if (IsBasicBuiltin(type))
            {
                DataInputOutputSerde serde = VMBasicBuiltinSerdeFactory.GetSerde(type);
                if (serde == null)
                {
                    throw new DataInputOutputSerdeException("Failed to find built-in serde for class " + type.Name);
                }

                return(new DataInputOutputSerdeForgeSingleton(serde.GetType()));
            }

            if (_allowExtended)
            {
                DataInputOutputSerde serde = VMExtendedBuiltinSerdeFactory.GetSerde(type);
                if (serde != null)
                {
                    return(new DataInputOutputSerdeForgeSingleton(serde.GetType()));
                }
            }

            if (type == typeof(EPLMethodInvocationContext))
            {
                return(new DataInputOutputSerdeForgeSingleton(typeof(DIOSkipSerde)));
            }

            SerdeProvision provision = SerdeCompileTimeResolverUtil.DetermineSerde(
                type,
                serdeProviders,
                allowSerializable,
                allowSerializationFallback,
                additionalInfo);

            return(provision.ToForge());
        }
        // Order of resolution:
        // (1) any serde providers are asked first, first one taking it counts
        // (2) class implements Serializable (when allowed)
        internal static SerdeProvision DetermineSerde(
            Type type,
            ICollection <SerdeProvider> serdeProviders,
            bool allowSerializable,
            bool allowSerializationFallback,
            SerdeProviderAdditionalInfo additionalInfo)
        {
            SerdeProvision serde;

            if (!serdeProviders.IsEmpty())
            {
                serde = DetermineSerdeFromProviders(type, serdeProviders, additionalInfo);
                if (serde != null)
                {
                    return(serde);
                }

                if (type.IsArray)
                {
                    SerdeProvision componentSerde = DetermineSerdeFromProviders(type.GetElementType(), serdeProviders, additionalInfo);
                    if (componentSerde != null)
                    {
                        return(new SerdeProvisionParameterized(
                                   typeof(DIONullableObjectArraySerde),
                                   vars => Constant(type.GetElementType()),
                                   vars => componentSerde.ToForge().Codegen(vars.Method, vars.Scope, vars.OptionalEventTypeResolver)));
                    }
                }
            }

            serde = DetermineSerializable(type, allowSerializable, allowSerializationFallback);
            if (serde != null)
            {
                return(serde);
            }

            throw MakeFailedToFindException(type, allowSerializable, serdeProviders.Count, additionalInfo);
        }