CarotDav_decompile/CarotDAV/SettingSupport.cs

81 lines
3.5 KiB
C#

// Decompiled with JetBrains decompiler
// Type: CarotDAV.SettingSupport
// Assembly: CarotDAV, Version=1.13.2.18337, Culture=neutral, PublicKeyToken=null
// MVID: C31F2651-A4A8-4D09-916A-8C6106F5E7C8
// Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\CarotDAV.exe
using System.Collections;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace CarotDAV
{
public class SettingSupport
{
public static bool IsSameType(object object1, object object2)
{
if (object1 == null)
return object2 == null;
if (object2 == null)
return false;
return object1.GetType() == object2.GetType();
}
public static bool IsSameContents(object object1, object object2, bool includenonpublic)
{
if (object.ReferenceEquals(RuntimeHelpers.GetObjectValue(object1), RuntimeHelpers.GetObjectValue(object2)))
return true;
if (!SettingSupport.IsSameType(RuntimeHelpers.GetObjectValue(object1), RuntimeHelpers.GetObjectValue(object2)))
return false;
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public;
if (includenonpublic)
bindingAttr |= BindingFlags.NonPublic;
FieldInfo[] fields = object1.GetType().GetFields(bindingAttr);
FieldInfo[] fieldInfoArray1 = fields;
int index1 = 0;
while (index1 < fieldInfoArray1.Length)
{
FieldInfo fieldInfo = fieldInfoArray1[index1];
object objectValue = RuntimeHelpers.GetObjectValue(fieldInfo.GetValue(RuntimeHelpers.GetObjectValue(object1)));
if (objectValue == null)
{
if (fieldInfo.GetValue(RuntimeHelpers.GetObjectValue(object2)) != null)
return false;
}
else if ((fieldInfo.FieldType.IsPrimitive || fieldInfo.FieldType.IsEnum) && !objectValue.Equals(RuntimeHelpers.GetObjectValue(fieldInfo.GetValue(RuntimeHelpers.GetObjectValue(object2)))))
return false;
checked { ++index1; }
}
FieldInfo[] fieldInfoArray2 = fields;
int index2 = 0;
while (index2 < fieldInfoArray2.Length)
{
FieldInfo fieldInfo = fieldInfoArray2[index2];
object objectValue1 = RuntimeHelpers.GetObjectValue(fieldInfo.GetValue(RuntimeHelpers.GetObjectValue(object1)));
object objectValue2 = RuntimeHelpers.GetObjectValue(fieldInfo.GetValue(RuntimeHelpers.GetObjectValue(object2)));
if (objectValue1 != null && !fieldInfo.FieldType.IsPrimitive && !fieldInfo.FieldType.IsEnum && (fieldInfo.FieldType.IsValueType || !object.ReferenceEquals(RuntimeHelpers.GetObjectValue(objectValue1), RuntimeHelpers.GetObjectValue(objectValue2))))
{
if (objectValue1 is ICollection)
{
ICollection collection1 = (ICollection) objectValue1;
ICollection collection2 = (ICollection) objectValue2;
if (collection1.Count != collection2.Count)
return false;
IEnumerator enumerator1 = collection1.GetEnumerator();
IEnumerator enumerator2 = collection2.GetEnumerator();
while (enumerator1.MoveNext() && enumerator2.MoveNext())
{
if (!SettingSupport.IsSameContents(RuntimeHelpers.GetObjectValue(enumerator1.Current), RuntimeHelpers.GetObjectValue(enumerator2.Current), includenonpublic))
return false;
}
}
else if (!objectValue1.Equals(RuntimeHelpers.GetObjectValue(objectValue2)))
return false;
}
checked { ++index2; }
}
return true;
}
}
}