public static void ModifyCardInList(this List <CardDetails> list, int index, string propName, object newValue) { CardDetails newDetails = new CardDetails(); copyCardDetails(ref newDetails, list[index]); System.Reflection.PropertyInfo propInfo = newDetails.GetType().GetProperty(propName); propInfo.SetValue(newDetails, Convert.ChangeType(newValue, propInfo.PropertyType, null), null); list.RemoveAt(index); list.Insert(index, newDetails); }
public Payment ProcessPayment(Payment entity) { CardDetails cardDetails = entity.GetType().GetProperty("CardDetails").GetValue(entity) as CardDetails; CardType cardType = cardDetails.GetType().GetProperty("CardType").GetValue(cardDetails) as CardType; if (Int64.TryParse(cardDetails.CardNumber, out long num)) { if (CheckCardType(cardType)) { entity.Status = (int)PaymentStatus.Approved; } } else { throw new Exception("Invalid Card Number Format"); } return(entity); }