private bool CheckStringProp(PropertyInfo Prop) { if (Prop == null || Prop.PropertyType != typeof(string)) { return(false); } RequiredData Data = Attribute.GetCustomAttribute(Prop, typeof(RequiredData)) as RequiredData; if (Prop.GetValue(this) == null || Prop.GetValue(this).ToString() == "") { return(false); } return(true); }
private bool CheckIntProp(PropertyInfo Prop) { if (Prop == null) { return(false); } RequiredData Data = Attribute.GetCustomAttribute(Prop, typeof(RequiredData)) as RequiredData; if ((Prop.GetValue(this) == null || Prop.GetValue(this).ToString() == "")) { return(false); } if (Data.AllowZeros == false) { if ((Convert.ToInt32(Prop.GetValue(this)) == 0)) { return(false); } } return(true); }
public bool Validate() { try { if (ValiationObject != null) { Type ObjectType = ValiationObject.GetType(); PropertyInfo[] Props = ObjectType.GetProperties(); PropertyList.Clear(); foreach (PropertyInfo Prop in Props) { if (Attribute.IsDefined(Prop, typeof(RequiredData))) { RequiredData Data = Attribute.GetCustomAttribute(Prop, typeof(RequiredData)) as RequiredData; switch (Prop.PropertyType.Name) { case "String": if (CheckStringProp(Prop)) { AddToList(Prop.Name, Prop.PropertyType.Name, true, Prop.GetValue(this)); } else { AddToList(Prop.Name, Prop.PropertyType.Name, false, Prop.GetValue(this)); } break; case "Decimal": if (CheckIntProp(Prop)) { AddToList(Prop.Name, Prop.PropertyType.Name, true, Prop.GetValue(this)); } else { AddToList(Prop.Name, Prop.PropertyType.Name, false, Prop.GetValue(this)); } break; case "Int32": if (CheckIntProp(Prop)) { AddToList(Prop.Name, Prop.PropertyType.Name, true, Prop.GetValue(this)); } else { AddToList(Prop.Name, Prop.PropertyType.Name, false, Prop.GetValue(this)); } break; case "skvendors": case "skValueBands": case "skCategory": if (CheckEntityProp(Prop)) { AddToList(Prop.Name, Prop.PropertyType.Name, true, Prop.GetValue(this)); } else { AddToList(Prop.Name, Prop.PropertyType.Name, false, Prop.GetValue(this)); } break; } } } if (PropertyList.Count > 0) { if (PropertyList.Exists(x => x.IsValid == false)) { IsObjectValid = false; } else { IsObjectValid = true; } } else { IsObjectValid = true; } } return(IsObjectValid); } catch (Exception) { throw; } }