示例#1
0
        /** Convert
         */
        public static JsonItem Convert(System.Object a_from_object, System.Type a_from_type, ConvertToJsonItemOption a_from_option, ObjectToJsonItem_WorkPool a_workpool, int a_nest)
        {
            try{
                //IDictionary
                {
                    System.Collections.IDictionary t_from_dictionary = a_from_object as System.Collections.IDictionary;
                    if (t_from_dictionary != null)
                    {
                        System.Type t_list_key_type = Fee.ReflectionTool.Utility.GetDictionaryKeyType(a_from_type);
                        if (t_list_key_type == typeof(string))
                        {
                            //Generic.Dictionary<string.>
                            //Generic.SortedDictionary<string,>
                            //Generic.SortedList<string,>

                            JsonItem t_to_jsonitem = new JsonItem(new Value_AssociativeArray());

                            //値型。
                            System.Type t_list_value_type = Fee.ReflectionTool.Utility.GetListValueType(a_from_object.GetType());

                            if (t_list_value_type == typeof(System.Object))
                            {
                                //ワークに追加。
                                foreach (System.Collections.DictionaryEntry t_from_pair in t_from_dictionary)
                                {
                                    string t_from_listitem_key_string = (string)t_from_pair.Key;
                                    if (t_from_listitem_key_string != null)
                                    {
                                        System.Object t_from_listitem_object = t_from_pair.Value;
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_to_jsonitem, t_from_listitem_key_string, t_from_listitem_object, t_from_listitem_object.GetType(), a_from_option, a_nest + 1);
                                    }
                                    else
                                    {
                                        //NULL処理。
                                        //keyがnullの場合は追加しない。
                                    }
                                }
                            }
                            else
                            {
                                //ワークに追加。
                                foreach (System.Collections.DictionaryEntry t_from_pair in t_from_dictionary)
                                {
                                    string t_from_listitem_key_string = (string)t_from_pair.Key;
                                    if (t_from_listitem_key_string != null)
                                    {
                                        System.Object t_from_listitem_object = t_from_pair.Value;
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_to_jsonitem, t_from_listitem_key_string, t_from_listitem_object, t_list_value_type, a_from_option, a_nest + 1);
                                    }
                                    else
                                    {
                                        //NULL処理。
                                        //keyがnullの場合は追加しない。
                                    }
                                }
                            }

                            //成功。
                            return(t_to_jsonitem);
                        }
                        else
                        {
                            //Generic.Dictionary<key != string.>

                            JsonItem t_to_jsonitem = new JsonItem(new Value_IndexArray());

                            //サイズがわかるので要素確保。
                            t_to_jsonitem.ReSize(t_from_dictionary.Count);

                            int t_index = 0;

                            //値型。
                            System.Type t_list_value_type = Fee.ReflectionTool.Utility.GetListValueType(a_from_type);

                            if (t_list_value_type == typeof(System.Object))
                            {
                                if (t_list_key_type == typeof(System.Object))
                                {
                                    //ワークに追加。
                                    foreach (System.Collections.DictionaryEntry t_from_listitem in t_from_dictionary)
                                    {
                                        JsonItem t_keyvalue_jsonitem = new JsonItem(new Value_AssociativeArray());
                                        t_to_jsonitem.SetItem(t_index, t_keyvalue_jsonitem, false);
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "KEY", t_from_listitem.Key, t_from_listitem.Key.GetType(), a_from_option, a_nest + 1);
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "VALUE", t_from_listitem.Value, t_from_listitem.Value.GetType(), a_from_option, a_nest + 1);
                                        t_index++;
                                    }
                                }
                                else
                                {
                                    //ワークに追加。
                                    foreach (System.Collections.DictionaryEntry t_from_listitem in t_from_dictionary)
                                    {
                                        JsonItem t_keyvalue_jsonitem = new JsonItem(new Value_AssociativeArray());
                                        t_to_jsonitem.SetItem(t_index, t_keyvalue_jsonitem, false);
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "KEY", t_from_listitem.Key, t_list_key_type, a_from_option, a_nest + 1);
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "VALUE", t_from_listitem.Value, t_from_listitem.Value.GetType(), a_from_option, a_nest + 1);
                                        t_index++;
                                    }
                                }
                            }
                            else
                            {
                                if (t_list_key_type == typeof(System.Object))
                                {
                                    //ワークに追加。
                                    foreach (System.Collections.DictionaryEntry t_from_listitem in t_from_dictionary)
                                    {
                                        JsonItem t_keyvalue_jsonitem = new JsonItem(new Value_AssociativeArray());
                                        t_to_jsonitem.SetItem(t_index, t_keyvalue_jsonitem, false);
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "KEY", t_from_listitem.Key, t_from_listitem.Key.GetType(), a_from_option, a_nest + 1);
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "VALUE", t_from_listitem.Value, t_list_value_type, a_from_option, a_nest + 1);
                                        t_index++;
                                    }
                                }
                                else
                                {
                                    //ワークに追加。
                                    foreach (System.Collections.DictionaryEntry t_from_listitem in t_from_dictionary)
                                    {
                                        JsonItem t_keyvalue_jsonitem = new JsonItem(new Value_AssociativeArray());
                                        t_to_jsonitem.SetItem(t_index, t_keyvalue_jsonitem, false);
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "KEY", t_from_listitem.Key, t_list_key_type, a_from_option, a_nest + 1);
                                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddAssociativeArray.Start, t_keyvalue_jsonitem, "VALUE", t_from_listitem.Value, t_list_value_type, a_from_option, a_nest + 1);
                                        t_index++;
                                    }
                                }
                            }

                            //成功。
                            return(t_to_jsonitem);
                        }
                    }
                }

                //ICollection
                {
                    System.Collections.ICollection t_from_collection = a_from_object as System.Collections.ICollection;
                    if (t_from_collection != null)
                    {
                        //Generic.List
                        //Generic.Stack
                        //Generic.LinkedList
                        //Generic.Queue
                        //Generic.SortedSet

                        JsonItem t_to_jsonitem = new JsonItem(new Value_IndexArray());

                        //サイズがわかるので要素確保。
                        t_to_jsonitem.ReSize(t_from_collection.Count);

                        int t_index = 0;

                        //値型。
                        System.Type t_list_value_type = Fee.ReflectionTool.Utility.GetListValueType(a_from_type);

                        if (t_list_value_type == typeof(System.Object))
                        {
                            //Collections.ArrayList

                            //ワークに追加。
                            foreach (System.Object t_from_listitem in t_from_collection)
                            {
                                a_workpool.Add(ObjectToJsonItem_WorkPool.ModeSetIndexArray.Start, t_to_jsonitem, t_index, t_from_listitem, t_from_listitem.GetType(), a_from_option, a_nest + 1);
                                t_index++;
                            }
                        }
                        else
                        {
                            //ワークに追加。
                            foreach (System.Object t_from_listitem in t_from_collection)
                            {
                                a_workpool.Add(ObjectToJsonItem_WorkPool.ModeSetIndexArray.Start, t_to_jsonitem, t_index, t_from_listitem, t_list_value_type, a_from_option, a_nest + 1);
                                t_index++;
                            }
                        }

                        //成功。
                        return(t_to_jsonitem);
                    }
                }

                //IEnumerable
                {
                    System.Collections.IEnumerable t_from_enumerable = a_from_object as System.Collections.IEnumerable;
                    if (t_from_enumerable != null)
                    {
                        //Generic.HashSet

                        JsonItem t_to_jsonitem = new JsonItem(new Value_IndexArray());

                        //値型。
                        System.Type t_list_value_type = Fee.ReflectionTool.Utility.GetListValueType(a_from_type);

                        if (t_list_value_type == typeof(System.Object))
                        {
                            //ワークに追加。
                            foreach (System.Object t_from_listitem in t_from_enumerable)
                            {
                                a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddIndexArray.Start, t_to_jsonitem, t_from_listitem, t_from_listitem.GetType(), a_from_option, a_nest + 1);
                            }
                        }
                        else
                        {
                            //ワークに追加。
                            foreach (System.Object t_from_listitem in t_from_enumerable)
                            {
                                a_workpool.Add(ObjectToJsonItem_WorkPool.ModeAddIndexArray.Start, t_to_jsonitem, t_from_listitem, t_list_value_type, a_from_option, a_nest + 1);
                            }
                        }

                        //成功。
                        return(t_to_jsonitem);
                    }
                }

                //class,struct
                {
                    JsonItem t_to_jsonitem = new JsonItem(new Value_AssociativeArray());

                    //メンバーリスト。取得。
                    System.Collections.Generic.List <System.Reflection.FieldInfo> t_fieldinfo_list = new System.Collections.Generic.List <System.Reflection.FieldInfo>();
                    Fee.JsonItem.ConvertTool.GetMemberListAll(a_from_type, t_fieldinfo_list);

                    //ワークに追加。
                    foreach (System.Reflection.FieldInfo t_fieldinfo in t_fieldinfo_list)
                    {
                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeFieldInfo.Start, t_to_jsonitem, t_fieldinfo, a_from_object, a_nest + 1);
                    }

                    //成功。
                    return(t_to_jsonitem);
                }
            }catch (System.Exception t_exception) {
                Tool.DebugReThrow(t_exception);
            }

            //失敗。
            Tool.Assert(false);
            return(null);
        }
示例#2
0
        /** Convert
         */
        public static JsonItem Convert(System.Object a_from_object, System.Type a_from_type, ConvertToJsonItemOption a_from_option, ObjectToJsonItem_WorkPool a_workpool, int a_nest)
        {
            ObjectToJsonItem_WorkPool t_workpool = a_workpool;

            if (t_workpool == null)
            {
                t_workpool = new ObjectToJsonItem_WorkPool();
            }

            JsonItem t_to_jsonitem = null;

            try{
                if (a_from_object != null)
                {
                    switch (a_from_type.FullName)
                    {
                    case "System." + nameof(System.String):
                    {
                        System.String t_value = a_from_object as System.String;

                        if (t_value != null)
                        {
                            t_to_jsonitem = new JsonItem(new Value_StringData(t_value));
                        }
                        else
                        {
                            //NULL処理。
                            t_to_jsonitem = null;
                        }
                    } break;

                    case "System." + nameof(System.Char):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Char>((System.Char)a_from_object));
                    } break;

                    case "System." + nameof(System.SByte):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.SByte>((System.SByte)a_from_object));
                    } break;

                    case "System." + nameof(System.Byte):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Byte>((System.Byte)a_from_object));
                    } break;

                    case "System." + nameof(System.Int16):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Int16>((System.Int16)a_from_object));
                    } break;

                    case "System." + nameof(System.UInt16):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.UInt16>((System.UInt16)a_from_object));
                    } break;

                    case "System." + nameof(System.Int32):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Int32>((System.Int32)a_from_object));
                    } break;

                    case "System." + nameof(System.UInt32):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.UInt32>((System.UInt32)a_from_object));
                    } break;

                    case "System." + nameof(System.Int64):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Int64>((System.Int64)a_from_object));
                    } break;

                    case "System." + nameof(System.UInt64):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.UInt64>((System.UInt64)a_from_object));
                    } break;

                    case "System." + nameof(System.Single):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Single>((System.Single)a_from_object));
                    } break;

                    case "System." + nameof(System.Double):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Double>((System.Double)a_from_object));
                    } break;

                    case "System." + nameof(System.Boolean):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Boolean>((System.Boolean)a_from_object));
                    } break;

                    case "System." + nameof(System.Decimal):
                    {
                        t_to_jsonitem = new JsonItem(new Value_Number <System.Decimal>((System.Decimal)a_from_object));
                    } break;

                    default:
                    {
                        if (a_from_type.IsArray == true)
                        {
                            //[]
                            t_to_jsonitem = ObjectToJsonItem_FromArray.Convert(a_from_object, a_from_type, a_from_option, t_workpool, a_nest);
                        }
                        else if (a_from_type.IsEnum == true)
                        {
                            //Enum
                            t_to_jsonitem = ObjectToJsonItem_FromEnum.Convert(a_from_object, a_from_option);
                        }
                        else
                        {
                            //class struct generic
                            t_to_jsonitem = ObjectToJsonItem_FromClass.Convert(a_from_object, a_from_type, a_from_option, t_workpool, a_nest);
                        }
                    } break;
                    }
                }
                else
                {
                    //NULL処理。
                }
            }catch (System.Exception t_exception) {
                Tool.DebugReThrow(t_exception);
            }

            //再起呼び出し。
            if (a_workpool == null)
            {
                t_workpool.Main();
            }

            return(t_to_jsonitem);
        }
        /** Convert
         */
        public static JsonItem Convert(System.Object a_from_object, System.Type a_from_type, ConvertToJsonItemOption a_from_option, ObjectToJsonItem_WorkPool a_workpool, int a_nest)
        {
            try{
                //[]

                System.Array t_array_raw = (System.Array)a_from_object;

                JsonItem t_to_jsonitem = new JsonItem(new Value_IndexArray());

                //サイズ確保。
                t_to_jsonitem.ReSize(t_array_raw.Length);

                //値型。
                System.Type t_list_value_type = Fee.ReflectionTool.Utility.GetListValueType(a_from_type);

                if (t_list_value_type == typeof(System.Object))
                {
                    for (int ii = 0; ii < t_array_raw.Length; ii++)
                    {
                        //ワークに追加。
                        System.Object t_listitem_object = t_array_raw.GetValue(ii);
                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeSetIndexArray.Start, t_to_jsonitem, ii, t_listitem_object, t_listitem_object.GetType(), a_from_option, a_nest + 1);
                    }
                }
                else
                {
                    for (int ii = 0; ii < t_array_raw.Length; ii++)
                    {
                        //ワークに追加。
                        System.Object t_listitem_object = t_array_raw.GetValue(ii);
                        a_workpool.Add(ObjectToJsonItem_WorkPool.ModeSetIndexArray.Start, t_to_jsonitem, ii, t_listitem_object, t_list_value_type, a_from_option, a_nest + 1);
                    }
                }

                //成功。
                return(t_to_jsonitem);
            }catch (System.Exception t_exception) {
                Tool.DebugReThrow(t_exception);
            }

            //失敗。
            Tool.Assert(false);
            return(null);
        }