Exemplo n.º 1
0
        /// <summary>
        /// If a given object can be encoded.
        /// </summary>
        /// <param name="Object">Object to encode.</param>
        /// <param name="Grade">How well the object can be encoded.</param>
        /// <param name="Encoder">Best encoder for the object.</param>
        /// <returns>If the object can be encoded.</returns>
        public static bool Encodes(object Object, out Grade Grade, out IContentEncoder Encoder)
        {
            Grade   = Grade.NotAtAll;
            Encoder = null;

            foreach (IContentEncoder Encoder2 in Encoders)
            {
                if (Encoder2.Encodes(Object, out Grade Grade2) && Grade2 > Grade)
                {
                    Grade   = Grade2;
                    Encoder = Encoder2;
                }
            }

            return(Encoder != null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// If a given object can be encoded.
        /// </summary>
        /// <param name="Object">Object to encode.</param>
        /// <param name="Grade">How well the object can be encoded.</param>
        /// <param name="Encoder">Best encoder for the object.</param>
        /// <param name="AcceptedContentTypes">Optional array of accepted content types. If array is empty, all content types are accepted.</param>
        /// <returns>If the object can be encoded.</returns>
        public static bool Encodes(object Object, out Grade Grade, out IContentEncoder Encoder, params string[] AcceptedContentTypes)
        {
            Grade   = Grade.NotAtAll;
            Encoder = null;

            foreach (IContentEncoder Encoder2 in Encoders)
            {
                if (Encoder2.Encodes(Object, out Grade Grade2, AcceptedContentTypes) && Grade2 > Grade)
                {
                    Grade   = Grade2;
                    Encoder = Encoder2;
                }
            }

            return(Encoder != null);
        }