private static object CloneValue(object src, Type type)
 {
     if (src != null && type != typeof(string) && type.get_IsClass())
     {
         if (!type.get_IsGenericType())
         {
             return(GeneralUtils.CloneClass(src, type));
         }
         if (src is IDictionary)
         {
             IDictionary           dictionary  = src as IDictionary;
             IDictionary           dictionary2 = GeneralUtils.CreateNewType(type) as IDictionary;
             Type                  type2       = type.GetGenericArguments()[0];
             Type                  type3       = type.GetGenericArguments()[1];
             IDictionaryEnumerator enumerator  = dictionary.GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator.get_Current();
                     dictionary2.Add(GeneralUtils.CloneValue(dictionaryEntry.get_Key(), type2), GeneralUtils.CloneValue(dictionaryEntry.get_Value(), type3));
                 }
             }
             finally
             {
                 IDisposable disposable = enumerator as IDisposable;
                 if (disposable != null)
                 {
                     disposable.Dispose();
                 }
             }
             return(dictionary2);
         }
         if (src is IList)
         {
             IList       list        = src as IList;
             IList       list2       = GeneralUtils.CreateNewType(type) as IList;
             Type        type4       = type.GetGenericArguments()[0];
             IEnumerator enumerator2 = list.GetEnumerator();
             try
             {
                 while (enumerator2.MoveNext())
                 {
                     object current = enumerator2.get_Current();
                     list2.Add(GeneralUtils.CloneValue(current, type4));
                 }
             }
             finally
             {
                 IDisposable disposable2 = enumerator2 as IDisposable;
                 if (disposable2 != null)
                 {
                     disposable2.Dispose();
                 }
             }
             return(list2);
         }
     }
     return(src);
 }
Пример #2
0
    private static object CloneClass(object obj, Type objType)
    {
        object obj2 = GeneralUtils.CreateNewType(objType);

        FieldInfo[] fields = objType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
        foreach (FieldInfo fieldInfo in fields)
        {
            fieldInfo.SetValue(obj2, GeneralUtils.CloneValue(fieldInfo.GetValue(obj), fieldInfo.FieldType));
        }
        return(obj2);
    }
    private static object CloneClass(object obj, Type objType)
    {
        object obj1 = GeneralUtils.CreateNewType(objType);

        FieldInfo[] fields = objType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
        for (int i = 0; i < (int)fields.Length; i++)
        {
            FieldInfo fieldInfo = fields[i];
            fieldInfo.SetValue(obj1, GeneralUtils.CloneValue(fieldInfo.GetValue(obj), fieldInfo.FieldType));
        }
        return(obj1);
    }
    private static object CloneClass(object obj, Type objType)
    {
        object obj2 = GeneralUtils.CreateNewType(objType);

        FieldInfo[] fields = objType.GetFields(52);
        FieldInfo[] array  = fields;
        for (int i = 0; i < array.Length; i++)
        {
            FieldInfo fieldInfo = array[i];
            fieldInfo.SetValue(obj2, GeneralUtils.CloneValue(fieldInfo.GetValue(obj), fieldInfo.get_FieldType()));
        }
        return(obj2);
    }
 private static object CloneValue(object src, Type type)
 {
     if (src != null && type != typeof(string) && type.IsClass)
     {
         if (!type.IsGenericType)
         {
             return(GeneralUtils.CloneClass(src, type));
         }
         if (src is IDictionary)
         {
             IDictionary           dictionaries      = src as IDictionary;
             IDictionary           dictionaries1     = GeneralUtils.CreateNewType(type) as IDictionary;
             Type                  genericArguments  = type.GetGenericArguments()[0];
             Type                  genericArguments1 = type.GetGenericArguments()[1];
             IDictionaryEnumerator enumerator        = dictionaries.GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     DictionaryEntry current = (DictionaryEntry)enumerator.Current;
                     dictionaries1.Add(GeneralUtils.CloneValue(current.Key, genericArguments), GeneralUtils.CloneValue(current.Value, genericArguments1));
                 }
             }
             finally
             {
                 IDisposable disposable  = enumerator as IDisposable;
                 IDisposable disposable1 = disposable;
                 if (disposable != null)
                 {
                     disposable1.Dispose();
                 }
             }
             return(dictionaries1);
         }
         if (src is IList)
         {
             IList       lists       = src as IList;
             IList       lists1      = GeneralUtils.CreateNewType(type) as IList;
             Type        type1       = type.GetGenericArguments()[0];
             IEnumerator enumerator1 = lists.GetEnumerator();
             try
             {
                 while (enumerator1.MoveNext())
                 {
                     object obj = enumerator1.Current;
                     lists1.Add(GeneralUtils.CloneValue(obj, type1));
                 }
             }
             finally
             {
                 IDisposable disposable2 = enumerator1 as IDisposable;
                 IDisposable disposable3 = disposable2;
                 if (disposable2 != null)
                 {
                     disposable3.Dispose();
                 }
             }
             return(lists1);
         }
     }
     return(src);
 }