コード例 #1
0
        public static string Serialize(IResultSet resultSet)
        {
            IResultSetElement[]            elements          = resultSet.Elements.ToArray();
            IDictionary <string, object>[] convertedElements = new IDictionary <string, object> [elements.Length];

            for (int i = 0; i < elements.Length; i++)
            {
                IResultSetElement element = elements[i];

                IDictionary <string, object> convertedElement = new Dictionary <string, object>();

                foreach (string field in element.FieldNames)
                {
                    convertedElement.Add(field, element.GetValue(field));
                }

                convertedElements[i] = convertedElement;
            }


            using (TextWriter textWriter = new StringWriter())
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(textWriter, convertedElements);

                return(textWriter.ToString());
            }
        }
コード例 #2
0
        public override bool Equals(object obj)
        {
            IResultSetElement other = obj as IResultSetElement;

            if (other == null)
            {
                return(false);
            }

            if (this.FieldNames.Length != other.FieldNames.Length)
            {
                return(false);
            }

            for (int i = 0; i < this.FieldNames.Length; i++)
            {
                string name  = this.FieldNames[i];
                object value = this.GetValue(name);

                if (!other.HasValue(name))
                {
                    return(false);
                }

                object otherValue = other.GetValue(name);

                if (otherValue == null || value == null)
                {
                    return(otherValue == null && value == null);
                }

                if (!CompareValues(value, otherValue))
                {
                    return(false);
                }
            }

            return(true);
        }