Пример #1
0
 protected void WriteNamedList(JsonWriter writer, INamedList list)
 {
     writer.WriteStartObject();
     if (list.IsNullOrEmpty())
     {
         writer.WriteEndObject();
         return;
     }
     for (int i = 0; i < list.Count; i++)
     {
         var key = list.GetKey(i);
         writer.WritePropertyName(key);
         var value = list.Get(i);
         if (value is INamedList)
         {
             WriteNamedList(writer, value as INamedList);
         }
         else if (value is IList)
         {
             WriteArray(writer, value as IList);
         }
         else
         {
             writer.WriteValue(value);
         }
     }
     writer.WriteEndObject();
 }
Пример #2
0
        protected static void PrintNamedList(INamedList list, int level = 0)
        {
            var prefix = Tabs(level);

            if (level > 10)
            {
                Console.WriteLine(prefix + "too much recursion");
                return;
            }

            if (list.IsNullOrEmpty())
            {
                Console.WriteLine(prefix + "List is empty.");
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine(prefix + list.GetKey(i));
                var item = list.Get(i);
                if (item is INamedList)
                {
                    PrintNamedList(item as INamedList, level + 1);
                }
            }
        }
Пример #3
0
 private void WriteNamedList(INamedList value, SolrBinaryStream stream)
 {
     //TODO: handle orderedMap? value is SimpleOrderedMap ? ORDERED_MAP : NAMED_LST
     WriteTag(NAMED_LST, stream, value.Count);
     for (int i = 0; i < value.Count; i++)
     {
         String name = value.GetKey(i);
         WriteExternString(name, stream);
         Object val = value.Get(i);
         WriteVal(val, stream);
     }
 }
Пример #4
0
 public SolrDocument(INamedList namedList)
 {
     Fields = new Dictionary<string, SolrInputField>();
     if (namedList == null)
         return;
     for (int i = 0; i < namedList.Count; i++)
     {
         var key = namedList.GetKey(i);
         var val = namedList.Get(i);
         Fields.Add(key, new SolrInputField(key) { Value = val });
     }
 }
Пример #5
0
        public static T GetOrDefault <T>(this INamedList namedList, int index) where T : class
        {
            if (namedList.IsNullOrEmpty())
            {
                return(null);
            }
            var item = namedList.Get(index);

            if (item == null)
            {
                return(null);
            }
            return(item as T);
        }
Пример #6
0
        public static T GetOrDefault <T>(this INamedList namedList, string key) where T : class
        {
            if (namedList.IsNullOrEmpty() || string.IsNullOrWhiteSpace(key))
            {
                return(null);
            }
            var item = namedList.Get(key);

            if (item == null)
            {
                return(null);
            }
            return(item as T);
        }
Пример #7
0
 public SolrDocument(INamedList namedList)
 {
     Fields = new Dictionary <string, SolrInputField>();
     if (namedList == null)
     {
         return;
     }
     for (int i = 0; i < namedList.Count; i++)
     {
         var key = namedList.GetKey(i);
         var val = namedList.Get(i);
         Fields.Add(key, new SolrInputField(key)
         {
             Value = val
         });
     }
 }
Пример #8
0
        public static T GetOrDefaultStruct <T>(this INamedList namedList, int index) where T : struct
        {
            if (namedList.IsNullOrEmpty())
            {
                return(default(T));
            }
            var item = namedList.Get(index);

            if (item == null)
            {
                return(default(T));
            }
            try
            {
                return((T)item);
            }
            catch
            {
                return(default(T));
            }
        }
Пример #9
0
        public static T GetOrDefaultStruct <T>(this INamedList namedList, string key) where T : struct
        {
            if (namedList.IsNullOrEmpty() || string.IsNullOrWhiteSpace(key))
            {
                return(default(T));
            }
            var item = namedList.Get(key);

            if (item == null)
            {
                return(default(T));
            }
            try
            {
                return((T)Convert.ChangeType(item, typeof(T)));
                //return (T) item;
            }
            catch
            {
                return(default(T));
            }
        }
Пример #10
0
        protected static void PrintNamedList(INamedList list, int level = 0)
        {
            var prefix = Tabs(level);
            if (level > 10)
            {
                Console.WriteLine(prefix + "too much recursion");
                return;
            }

            if (list.IsNullOrEmpty())
            {
                Console.WriteLine(prefix + "List is empty.");
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine(prefix + list.GetKey(i));
                var item = list.Get(i);
                if (item is INamedList)
                {
                    PrintNamedList(item as INamedList, level + 1);
                }
            }
        }
Пример #11
0
 protected void WriteNamedList(JsonWriter writer, INamedList list)
 {
     writer.WriteStartObject();
     if (list.IsNullOrEmpty())
     {
         writer.WriteEndObject();
         return;
     }
     for (int i = 0; i < list.Count; i++)
     {
         var key = list.GetKey(i);
         writer.WritePropertyName(key);
         var value = list.Get(i);
         if (value is INamedList)
             WriteNamedList(writer, value as INamedList);
         else if (value is IList)
             WriteArray(writer, value as IList);
         else
             writer.WriteValue(value);
     }
     writer.WriteEndObject();
 }
Пример #12
0
 private void WriteNamedList(INamedList value, SolrBinaryStream stream)
 {
     //TODO: handle orderedMap? value is SimpleOrderedMap ? ORDERED_MAP : NAMED_LST
     WriteTag(NAMED_LST, stream, value.Count);
     for (int i = 0; i < value.Count; i++)
     {
         String name = value.GetKey(i);
         WriteExternString(name, stream);
         Object val = value.Get(i);
         WriteVal(val, stream);
     }
 }