void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            Helpers.ThrowIfNull(info, "info");
            bool flag = context.State == StreamingContextStates.CrossAppDomain;

            if (!flag)
            {
                foreach (RecognizedPhrase alternate in Alternates)
                {
                    try
                    {
                        string          smlContent = alternate.SmlContent;
                        RecognizedAudio audio      = Audio;
                        if (alternate.Text == null || alternate.Homophones == null || alternate.Semantics == null || (smlContent == null && smlContent != null) || (audio == null && audio != null))
                        {
                            throw new SerializationException();
                        }
                    }
                    catch (NotSupportedException)
                    {
                    }
                }
            }
            Type type = GetType();

            MemberInfo[] serializableMembers = FormatterServices.GetSerializableMembers(type, context);
            MemberInfo[] array = serializableMembers;
            foreach (MemberInfo memberInfo in array)
            {
                if (!flag || (memberInfo.Name != "_recognizer" && memberInfo.Name != "_grammar" && memberInfo.Name != "_ruleList" && memberInfo.Name != "_audio" && memberInfo.Name != "_audio"))
                {
                    info.AddValue(memberInfo.Name, ((FieldInfo)memberInfo).GetValue(this));
                }
            }
        }
Beispiel #2
0
        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            Helpers.ThrowIfNull(info, nameof(info));

            bool appDomainTransition = context.State == StreamingContextStates.CrossAppDomain;

            if (!appDomainTransition)
            {
                // build all the properties
                foreach (RecognizedPhrase phrase in Alternates)
                {
                    try
                    {
                        // Get the sml Content and toy with this variable to fool the compiler in not doing the calucation at all
                        string          sml   = phrase.SmlContent;
                        RecognizedAudio audio = Audio;
                        if (phrase.Text == null || phrase.Homophones == null || phrase.Semantics == null || (sml == null && sml != null) || (audio == null && audio != null))
                        {
                            throw new SerializationException();
                        }
                    }
#pragma warning disable 56502 // Remove the empty catch statements warnings
                    catch (NotSupportedException)
                    {
                    }
#pragma warning restore 56502
                }
            }

            // Get the set of serializable members for our class and base classes
            Type         thisType = this.GetType();
            MemberInfo[] mis      = FormatterServices.GetSerializableMembers(thisType, context);

            // Serialize the base class's fields to the info object
            foreach (MemberInfo mi in mis)
            {
                if (!appDomainTransition || (mi.Name != "_recognizer" && mi.Name != "_grammar" && mi.Name != "_ruleList" && mi.Name != "_audio" && mi.Name != "_audio"))
                {
                    info.AddValue(mi.Name, ((FieldInfo)mi).GetValue(this));
                }
            }
        }