本文整理汇总了C#中Product.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Product.GetType方法的具体用法?C# Product.GetType怎么用?C# Product.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product.GetType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertLineItem
private void InsertLineItem(Product product, string reason, string otherReason, decimal qty, bool isEditable)
{
var existing = LineItems.FirstOrDefault(n => n.ProductId == product.Id && n.Reason == reason && n.OtherReason == otherReason && n.IsEditable == isEditable);
if (existing == null)
{
LineItems.Add(new DispatchProductLineItem
{
SequenceId = LineItems.Count() + 1,
ProductId = product.Id,
ProductDesc = product.Description,
ProductType = product.GetType().ToString().Split('.').Last(),
Reason = reason,
OtherReason = otherReason,
Qty = qty,
IsEditable = isEditable
});
}
else
{
existing.Qty += qty;
}
}
示例2: GetTemplate
static Template GetTemplate(Product product, string templateName)
{
// Check User Orchestra and then check if Template is shared. Change username if using a different user.
return Env.Current.StaticData.GetTemplate("orchestra", product.GetType().Name, templateName) ?? Env.Current.StaticData.GetTemplate(Template.Shared, product.GetType().Name, templateName); ;
}
示例3: SaveSwapTrade
private static Trade SaveSwapTrade(Product product, Market market, String templateName, Dictionary<string, dynamic> importRow )
{
// Mandatory Inputs
string payRec = importRow["Pay Receive"]; // "Receive";
double fixedRate = importRow["Rate"]; //0.0175;
var trade = CreateProductTrade(product, importRow);
// Use template saved inside of Database and make changes to trade here.
var template = GetTemplate(product, templateName);
if (template == null)
{
Logger.Error("Can not find template " + templateName);
throw new Exception("Can not find template " + templateName);
}
template.Apply(trade, SimpleDate.Today, market);
// Trade specifics
if (trade.TradeTime == DateTime.MinValue)
trade.TradeTime = DateTime.Now;
if (importRow.ContainsKey("CCP"))
{
Party partyCcp = Env.Current.StaticData.GetPartyByCode(importRow["CCP"]);
if (partyCcp != null)
trade.CcpId = partyCcp.Id;
}
// Product Specific
if (trade.Product is Swap)
{
Swap swap = trade.Product as Swap;
swap.PayLeg.FixedRate = fixedRate;
swap.StartDate = new SimpleDate(importRow["StartDate"]); //new SimpleDate(DateTime.ParseExact(startDate, "dd-MMM-yy", null, DateTimeStyles.None));
swap.EndDate = new SimpleDate(importRow["EndDate"]); //SimpleDate(DateTime.ParseExact(endDate, "dd-MMM-yy", null, DateTimeStyles.None));
swap.PayLeg.Notional = importRow["Nominal"];
swap.ReceiveLeg.Notional = importRow["Nominal"];
if ((payRec.Equals("Receive") && swap.ReceiveLeg.IsFloating) ||
payRec.Equals("Pay") && swap.PayLeg.IsFloating)
swap.SwitchLegs();
}
else if (trade.Product is Swaption)
{
Swaption swaption = trade.Product as Swaption;
swaption.Swap.StartDate = new SimpleDate(importRow["Swap Start Date"]);
swaption.Swap.EndDate = new SimpleDate(importRow["Swap End Date"]);
swaption.IsBuy = importRow["Buy Sell"] == "Buy";
swaption.FixedRate = fixedRate;
if ((payRec.Equals("Receive") && swaption.Swap.ReceiveLeg.IsFloating) ||
payRec.Equals("Pay") && swaption.Swap.PayLeg.IsFloating)
swaption.Swap.SwitchLegs();
swaption.ExpiryDate = new SimpleDate(importRow["Expiry"]);
swaption.Premium = importRow["Premium"];
OptionExerciseType oet = OptionExerciseType.None;
OptionExerciseType.TryParse(importRow["Option Style"], true, out oet);
swaption.ExerciseType = oet;
swaption.FirstPremium.IsForwardStart = importRow["Is Forward Start"].Equals("Checked") ? true : false;
swaption.InitialPremiumAmount = importRow["Nominal"];
swaption.InitialPremiumCurrency = importRow["Premium Ccy"];
swaption.InitialPremiumDate = new SimpleDate(importRow["Settle Date"]);
swaption.InitialPremiumPayReceive = swaption.IsBuy ? PayReceive.Pay : PayReceive.Receive;
ExerciseSettlement es = ExerciseSettlement.None;
ExerciseSettlement.TryParse(importRow["Settlement Type"], true, out es);
swaption.ExerciseSettlement = es;
}
//Add UpFront Fee
swapUpfrontFee(importRow, trade);
var templateProvider = Template.Find(product.GetType().Name);
if (templateProvider != null) templateProvider.FillTrade(trade, market);
if (finalSaveTrade(trade)) return null;
return trade;
}
示例4: CheckProperties
public bool CheckProperties(Product p)
{
if (p == null) return false;
foreach (var prop in p.GetType().GetProperties())
{
object type = prop.GetValue(p);
decimal parsedPrice;
if (!(type is string) && type != null) continue;
// Make sure the fields are DEFINITELY not null
if (prop.GetValue(p) == null)
prop.SetValue(p, "");
switch (prop.Name)
{
case "EAN":
string rawEan = prop.GetValue(p) as string;
long tempEan;
if (!long.TryParse(rawEan, out tempEan)) return false;
prop.SetValue(p, Regex.IsMatch(tempEan.ToString(), @"^[0-9]{10,13}$") ? tempEan.ToString() : "");
if ((prop.GetValue(p) as string).Contains("00000000000") || (prop.GetValue(p) as string).Contains("999999999999"))
{
if (LogProperties) PropertyStatisticsMapper.Instance.Add(prop.Name, prop.GetValue(p) as string);
return false;
}
break;
case "Price":
if (p.Webshop.Contains("amazon"))
{
string[] parts;
if (p.Webshop.Contains("co.uk")) parts = (prop.GetValue(p) as string).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
else parts = (prop.GetValue(p) as string).Swap(',', '.').Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
prop.SetValue(p, String.Join("", parts));
}
else prop.SetValue(p, (prop.GetValue(p) as string).Replace(',', '.'));
prop.SetValue(p, Regex.IsMatch(prop.GetValue(p) as string, @"^\d+(.\d{1,2})?$") ? prop.GetValue(p) : "");
if ((prop.GetValue(p) as string) == "")
{
if (LogProperties) PropertyStatisticsMapper.Instance.Add(prop.Name, prop.GetValue(p) as string);
return false;
}
if ((parsedPrice = decimal.Parse(prop.GetValue(p) as string, NumberStyles.Any, CultureInfo.InvariantCulture)) == 0)
{
if (LogProperties) PropertyStatisticsMapper.Instance.Add(prop.Name, prop.GetValue(p) as string);
return false;
}
decimal rate = CurrencyRates == null ? 1 : CurrencyRates.ContainsKey(p.Currency.ToUpper()) ? CurrencyRates[p.Currency.ToUpper()] : 1;
prop.SetValue(p, (parsedPrice / rate).ToString().Replace(',', '.'));
break;
case "DeliveryCost":
prop.SetValue(p, (prop.GetValue(p) as string).Replace(',','.'));
prop.SetValue(p, Regex.IsMatch(prop.GetValue(p) as string, @"^\d+(.\d{1,2})?$") ? prop.GetValue(p) : null);
break;
case "Title":
if ((prop.GetValue(p) as string).Length >= Maximums["max_title_size"])
{
if (LogProperties) PropertyStatisticsMapper.Instance.Add(prop.Name, prop.GetValue(p) as string);
return false;
}
else
{
prop.SetValue(p, (prop.GetValue(p) as string).EscapeChars().Trim());
if (prop.GetValue(p) as string == "")
{
if (LogProperties) PropertyStatisticsMapper.Instance.Add(prop.Name, prop.GetValue(p) as string);
return false;
}
}
break;
case "Brand":
if ((prop.GetValue(p) as string).Length >= Maximums["max_brand_size"])
{
if (LogProperties) PropertyStatisticsMapper.Instance.Add(prop.Name, prop.GetValue(p) as string);
return false;
}
else
{
prop.SetValue(p, (prop.GetValue(p) as string).Trim());
}
break;
case "SKU":
if ((prop.GetValue(p) as string).Contains("!"))
{
if (LogProperties) PropertyStatisticsMapper.Instance.Add(prop.Name, prop.GetValue(p) as string);
return false;
}
if ((prop.GetValue(p) as string).Length > Maximums["max_sku_size"])
{
if (LogProperties) PropertyStatisticsMapper.Instance.Add(prop.Name, prop.GetValue(p) as string);
return false;
}
else
{
prop.SetValue(p, (prop.GetValue(p) as string).ToUpper().Trim());
}
break;
//.........这里部分代码省略.........
示例5: GetPropValue
private static object GetPropValue(Product record, string propName)
{
return record.GetType().GetProperty(propName).GetValue(record, null);
}
示例6: UpdateOrAddLineItem
private void UpdateOrAddLineItem(List<ApproveOrderViewModel.ApproveOrderLineItemViewModel> LineItems, Product product, decimal quantity, bool isEditable, Guid parentProductId, bool isEdit)
{
decimal UnitPrice = PriceCalc(product);
decimal UnitVat = 0;// VatCalc(product);
decimal net = UnitPrice * quantity;
//decimal vat = quantity * UnitVat;//cn
decimal VatAmount = quantity * UnitVat;
decimal TotalPrice = net + VatAmount;
ApproveOrderViewModel.ApproveOrderLineItemViewModel li;
if (LineItems.Any(p => p.ProductId == product.Id) && isEdit == false)
{
li = LineItems.First(p => p.ProductId == product.Id);
li.Qty = li.Qty + quantity;
li.VatValue = UnitVat;
li.LineTotal = li.TotalNet + TotalPrice;
}
else if (LineItems.Any(p => p.ProductId == product.Id) && isEdit == true)
{
li = LineItems.First(p => p.ProductId == product.Id);
li.Qty = quantity;
li.LineTotal = TotalPrice;
}
else
{
li = new ApproveOrderViewModel.ApproveOrderLineItemViewModel();
LineItems.Add(li);
li.Qty = quantity;
li.LineTotal = TotalPrice;
li.ProductType = product.GetType().ToString().Split('.').Last();
}
li.ProductId = product.Id;
li.ProductDesc = product.Description;
li.Value = UnitPrice;
li.TotalNet = net;
li.VatValue = UnitVat;
}
示例7: GetProductReturnables
public List<ReturnableProduct> GetProductReturnables(Product product, decimal qty)
{
ReturnableProduct foundReturnable = null;
if (product.GetType() == typeof(SaleProduct))
{
ReturnableProduct returnable = ((SaleProduct)product).ReturnableProduct;
if (returnable != null)
{
foundReturnable = returnable;
}
}
else if (product.GetType() == typeof(ReturnableProduct))
{
ReturnableProduct returnable = ((ReturnableProduct)product).ReturnAbleProduct;
if (returnable != null)
{
foundReturnable = returnable;
}
}
if (foundReturnable != null)
{
if (foundReturnable.Capacity == 1)
{
productReturnables.Add(foundReturnable);
GetProductReturnables(foundReturnable, qty);
}
else if (foundReturnable.Capacity > 1)
{
if (qty / foundReturnable.Capacity > 1)
{
productReturnables.Add(foundReturnable);
GetProductReturnables(foundReturnable, (qty / foundReturnable.Capacity));
}
}
}
return productReturnables;
}