using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
Stock stock = new Stock();
ActiveStockProperty recordStock;
recordStock = new ActiveStockProperty("retail", "MAIN", "min", 7);
stock.SetLocationValue(recordStock);
recordStock = new ActiveStockProperty("retail", "MAIN", "max", 14);
stock.SetLocationValue(recordStock);
recordStock = new ActiveStockProperty("retail", "BELL", "max", 6);
stock.SetLocationValue(recordStock);
recordStock = new ActiveStockProperty("direct", "vendor_5", "onHand", 100);
stock.SetLocationValue(recordStock);
Console.WriteLine("\nresults:");
Console.WriteLine(stock.Retail["MAIN"].Min + " / " + stock.Retail["MAIN"].Max);
Console.WriteLine(stock.Retail["BELL"].Min + " / " + stock.Retail["MAIN"].Max);
Console.WriteLine(stock.Direct["vendor_5"].OnHand);
public string SomeString { get; set; } = "I am Retail";
public Nullable<int> OnHand { get; set; }
public Nullable<int> OnOrder { get; set; }
public Nullable<int> Min { get; set; }
public Nullable<int> Max { get; set; }
public Dictionary<string, CounterPointStockEntry> Retail { get; set; } = new Dictionary<string, CounterPointStockEntry>();
public Dictionary<string, StockEntry> Direct { get; set; } = new Dictionary<string, StockEntry>();
public void GetActiveProperties()
PropertyInfo[] properties;
Type stockType = this.GetType();
properties = stockType.GetProperties();
foreach(PropertyInfo prop in properties){
var propertyName = prop.Name;
dynamic propertyValue = null;
PropertyInfo property = stockType.GetProperty(propertyName);
if(property is not null){
propertyValue = property.GetValue(this);
Console.WriteLine("property " + propertyName + " " + (propertyValue is null ? "_null" : propertyValue));
public void SetLocationValue(ActiveStockProperty recordStock)
Console.WriteLine("\n>>> " + recordStock.LocationType + " " + recordStock.Location + " : " + recordStock.FieldName + " = " + recordStock.Value);
PropertyInfo[] properties;
Type stockType = this.GetType();
properties = stockType.GetProperties();
foreach(PropertyInfo prop in properties){
string propertyName = prop.Name;
if(propertyName.ToUpper() == recordStock.LocationType.ToUpper()){
Console.WriteLine("It Worked: " + propertyName + " == " + recordStock.LocationType);
PropertyInfo property = stockType.GetProperty(propertyName);
propertyValue = property.GetValue(this);
if(! propertyValue.ContainsKey(recordStock.Location)){
Type[] locationTypeArguments = propertyValue.GetType().GenericTypeArguments;
Type locationValueType = locationTypeArguments[1];
if(locationValueType == typeof(CounterPointStockEntry)){
Console.WriteLine("+ add <" + recordStock.Location + ", CounterPointStockEntry()>");
propertyValue.Add(recordStock.Location, new CounterPointStockEntry());
}else if(locationValueType == typeof(StockEntry)){
Console.WriteLine("+ add <" + recordStock.Location + ", StockEntry()>");
propertyValue.Add(recordStock.Location, new StockEntry());
Console.WriteLine(": has <" + recordStock.Location + ", <T>>");
PropertyInfo[] locationProperties;
Type locationType = propertyValue[recordStock.Location].GetType();
locationProperties = locationType.GetProperties();
foreach(PropertyInfo locationProp in locationProperties){
string locationPropertyName = locationProp.Name;
Console.WriteLine(locationPropertyName);
if(locationPropertyName.ToUpper() == recordStock.FieldName.ToUpper()){
Console.WriteLine("> setting fieldName: " + locationPropertyName + " = " + recordStock.Value);
locationProp.SetValue(propertyValue[recordStock.Location], recordStock.Value);
public int OnHand { get; set; }
public class CounterPointStockEntry
public int OnHand { get; set; }
public int OnOrder { get; set; }
public int Min { get; set; }
public int Max { get; set; }
public class ActiveStockProperty
public string LocationType { get; set; }
public string Location { get; set; }
public string FieldName { get; set; }
public dynamic Value { get; set; }
public ActiveStockProperty(string locationType, string location, string fieldName, dynamic val)
LocationType = locationType;