public MergeableRow() { Type curType = this.GetType(); AttributeProperties curAttrProps; lock (AttributePropDict) { if (!AttributePropDict.TryGetValue(curType, out curAttrProps)) { curAttrProps = new AttributeProperties(); foreach (PropertyInfo propInfo in curType.GetProperties()) { var idAttr = propInfo.GetCustomAttribute(typeof(IdColumn)) as IdColumn; if (idAttr != null) { curAttrProps.IdAttributeProps.Add(propInfo); } var compAttr = propInfo.GetCustomAttribute(typeof(CompareColumn)) as CompareColumn; if (compAttr != null) { curAttrProps.CompareAttributeProps.Add(propInfo); } var deleteAttr = propInfo.GetCustomAttribute(typeof(DeleteColumn)) as DeleteColumn; if (deleteAttr != null) { curAttrProps.DeleteAttributeProps.Add(Tuple.Create(propInfo, deleteAttr.DeleteOnMatchValue)); } } AttributePropDict.TryAdd(curType, curAttrProps); } } }
public MergeableRow() { Type curType = this.GetType(); AttributeProperties curAttrProps; if (!AttributePropDict.TryGetValue(curType, out curAttrProps)) { lock (this) { curAttrProps = new AttributeProperties(); foreach (PropertyInfo propInfo in curType.GetProperties()) { var idAttr = propInfo.GetCustomAttribute(typeof(IdColumn)) as IdColumn; if (idAttr != null) { curAttrProps.IdAttributeProps.Add(propInfo); } var compAttr = propInfo.GetCustomAttribute(typeof(CompareColumn)) as CompareColumn; if (compAttr != null) { curAttrProps.CompareAttributeProps.Add(propInfo); } } AttributePropDict.TryAdd(curType, curAttrProps); } } }
/// <summary> /// Overriding the Equals implementation. The Equals function is used identify records /// that don't need to be updated. Only properties marked with the CompareColumn attribute /// are considered for the comparison. If the property is of type object, the Equals() method of the object is used. /// </summary> /// <param name="other">Object to compare with. Should be of the same type.</param> /// <returns>True if all properties marked with CompareColumn attribute are equal.</returns> public override bool Equals(object other) { if (other == null) { return(false); } AttributeProperties attrProps = AttributePropDict[this.GetType()]; bool result = true; foreach (var propInfo in attrProps.CompareAttributeProps) { result &= (propInfo?.GetValue(this))?.Equals(propInfo?.GetValue(other)) ?? false; } return(result); }