/// <summary> /// Propertisi olan nesnelerin propertisini default değerler verir. /// </summary> /// <param name="Istisnalar">Default değeri set edilmeyecek propertyleri belirtmek gerekiyor.</param> public static void DefaultValueSet(this object Deger, params string[] Istisnalar) { foreach (var pi in Deger.GetType().GetProperties()) { if (Istisnalar.Contains(pi.Name)) { continue; } if (pi.PropertyType == typeof(string)) { pi.SetValue(Deger, "", null); } else if (pi.PropertyType == typeof(decimal)) { pi.SetValue(Deger, 0.0m, null); } else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(short) || pi.PropertyType == typeof(Single) || pi.PropertyType == typeof(double)) { pi.SetValue(Deger, (short)0, null); } } }
/// <summary> /// Propertisi olan nesnelerin propertisini default değerler verir. /// </summary> /// <param name="Istisnalar">Default değeri set edilmeyecek propertyleri belirtmek gerekiyor.</param> public static void DefaultValueSet(this object Deger, params string[] Istisnalar) { foreach (var pi in Deger.GetType().GetProperties()) { try { if (Istisnalar.Contains(pi.Name)) { continue; } if (!pi.CanWrite) { continue; } if (pi.PropertyType.Namespace == "System.Collections.Generic") { continue; } if (!pi.PropertyType.IsGenericType) { if (pi.PropertyType == typeof(string)) { pi.SetValue(Deger, "", null); } else if (pi.PropertyType == typeof(decimal)) { pi.SetValue(Deger, 0.0m, null); } else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(short) || pi.PropertyType == typeof(Single) || pi.PropertyType == typeof(double) || pi.PropertyType == typeof(byte)) { pi.SetValue(Deger, (short)0, null); } } else { if (pi.PropertyType.GetGenericArguments()[0] == typeof(string)) { pi.SetValue(Deger, "", null); } else if (pi.PropertyType.GetGenericArguments()[0] == typeof(decimal)) { pi.SetValue(Deger, 0.0m, null); } else if (pi.PropertyType.GetGenericArguments()[0] == typeof(int) || pi.PropertyType.GetGenericArguments()[0] == typeof(double)) { pi.SetValue(Deger, 0, null); } else if (pi.PropertyType.GetGenericArguments()[0] == typeof(Single)) { pi.SetValue(Deger, 0.0f, null); } else if (pi.PropertyType.GetGenericArguments()[0] == typeof(short)) { pi.SetValue(Deger, (short)0, null); } else if (pi.PropertyType.GetGenericArguments()[0] == typeof(byte)) { pi.SetValue(Deger, (byte)0, null); } } } catch (Exception) { } } }