我在 cricles 中四处改变和重新改变,不明白为什么我没有得到我想要的价值观,也许有人可以解释一下。
我有这个对象
var result = new GetRatePlanListResponse
{
RatePlanId = prodRpsResult.Id,
RatePlanName = prodRpsResult.Name,
EffectiveStartDate = prodRpsResult.EffectiveStartDate,
EffectiveEndDate = prodRpsResult.EffectiveEndDate,
BillingPeriod = prodRpsResult.PRDP_BillingFrequency__c.HasValue ? prodRpsResult.PRDP_BillingFrequency__c.Value.ToString() : null,
ShippingSchedule = prodRpsResult.PRDP_DeliveryFrequency__c.HasValue ? prodRpsResult.PRDP_DeliveryFrequency__c.Value.ToString() : null,
UsageLevel = prodRpsResult?.PRDP_UsageLevel__c,
IncludedUnits = prodRpsResult?.PRDP_NumberofPackages__c,
BasePrice = new RatePlanBasePrice
{
Currency = pricing != null ? pricing.Currency : string.Empty,
Price = pricing != null && pricing.Price != null ? pricing.Price.Value : 0
}
};
然后我用那个对象调用这个函数有参数:
public void PriceConverter<T>(ref T obj)
{
Type t = obj.GetType();
foreach (var prop in t.GetProperties())
{
if (Enum.GetNames(typeof(RootPrices)).Any(x => x.ToLower() == prop.Name.ToLower()))
{
prop.SetValue(obj, ((int)(double.Parse((string)prop.GetValue(obj)) * 100)).ToString(), null);
}
}
}
我的问题是由于某种原因我无法访问值货币和价格。我怎样才能做到这一点?
编辑:
好的,谢谢大家提供的信息,我决定改变我的方法,因为如果它们内部有其他对象,我无法更改通用对象属性,因为它们代表不同的引用。尽管我正在更改它,但如果有人知道一种递归或迭代更改引用对象及其引用的所有对象并可以提供解决方案的方法,我将不胜感激具有相似字段的预先存在的代码库的多个对象数据。