/// <summary> /// use for update command/query /// create list of key-value pair like [ propertyname = propertyvalue ,] and so on /// dont consider primary key property in list /// </summary> /// <param name="mytype">type of class [ex person class or student etc]</param> private void SetUpdatePropertise(MyType myType) { try { UpdatePropertiesNamesValuesPair = ""; SetPimaryKeyName(myType); foreach (PropertyInfo property in myType.GetType().GetProperties()) { if (property.Name != PrimaryKeyNameInSourceCode && !AttributeHeler.CheckIgnoreColumn(property)) { TypeCode typeCode = Type.GetTypeCode(property.PropertyType); string Name = AttributeHeler.GetColumnName(property);// property.Name; Object value = property.GetValue(myType, null); if (Name != PrimaryKeyNameInDB) { UpdatePropertiesNamesValuesPair += (Name + "='" + value + "',"); } } } UpdatePropertiesNamesValuesPair = UpdatePropertiesNamesValuesPair.Remove(UpdatePropertiesNamesValuesPair.Length - 1); } catch (Exception ex) { throw ex; } }
/// <summary> /// create comma separated list of property values /// if includeprimary is true then primary key value also consider in list /// else primary key value is remove from list /// </summary> /// <param name="mytype">type of class [ex person class or student etc]</param> /// <param name="includeprimary">weather primary key property should consider in list or not if yes : consider , if false : removed from list</param> private void SetPropertiesValues(MyType myType, bool includePrimary = true) { string CompleteVal = string.Empty; foreach (PropertyInfo property in myType.GetType().GetProperties()) { if (!AttributeHeler.CheckIgnoreColumn(property) && includePrimary == AttributeHeler.IsPrimaryKeyAttribute(property)) { TypeCode typeCode = Type.GetTypeCode(property.PropertyType); string Name = property.Name; Object value = property.GetValue(myType, null); var val = ClassHelper <MyType> .SetValue(Name, value, myType); CompleteVal += (ClassHelper <MyType> .CreateSqlString(val) + ","); } } CompleteVal = CompleteVal.Remove(CompleteVal.Length - 1); PropertiesValues = CompleteVal; }
/// <summary> /// create comma separated propertyname list /// if includeprimary is true then primary key propery also consider in list /// else primary key property is remove from list /// </summary> /// <param name="mytype">type of class [ex person class or student etc]</param> /// <param name="includeprimary">weather primary key property should consider in list or not if yes : consider , if false : removed from list</param> private void SetPropertiesNames(MyType myType, bool includePrimary = true) { foreach (var property in myType.GetType().GetProperties()) { if (!AttributeHeler.CheckIgnoreColumn(property)) { if (includePrimary) { string Name = AttributeHeler.GetColumnName(property); PropertiesNames += (Name + ","); } else if (!AttributeHeler.IsPrimaryKeyAttribute(property)) { string Name = AttributeHeler.GetColumnName(property); PropertiesNames += (Name + ","); } } } PropertiesNames = PropertiesNames.Remove(PropertiesNames.Length - 1); }