public virtual Decimal GetDecimalVector(String propertyName) { if (DecimalsDict.ContainsKey(propertyName)) { return((Decimal)DecimalsDict[propertyName].GetValue(this, null)); } return(default(Decimal)); }
/// <summary> /// Initializes this instance, registers all Integers and Doubles /// </summary> protected void Init() { var t = GetType(); if (MetricsExtensions.CachedMetricsDefinitions.ContainsKey(t.FullName)) { MetricsExtensions.CachedMetricsDefinitions[t.FullName].SetTo(this); return; } PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.Public); props = props.ToList().OrderBy(x => x.Name).ToArray(); foreach (var p in props) { if (p.hasAttribute(imbAttributeName.measure_excludeFromMetrics)) { IgnoreComputations.Add(p); IgnoreComputationsDict.Add(p.Name, p); continue; } if (p.GetIndexParameters().Length == 0) { if (p.PropertyType == typeof(Int32)) { Integers.Add(p); IntegersDict.Add(p.Name, p); } else if (p.PropertyType == typeof(Double)) { Doubles.Add(p); DoublesDict.Add(p.Name, p); } else if (p.PropertyType == typeof(Decimal)) { Decimals.Add(p); DecimalsDict.Add(p.Name, p); } } } MetricsExtensions.StoreMetricsDefinition(this); }
/* * public DataTable SetDataTable(String name, DataTable table = null) * { * if (table == null) table = new DataTable(name); * * foreach (PropertyInfo db in Doubles) * { * if (!table.Columns.Contains(db.Name)) * { * var dc = table.Columns.Add(db.Name); * dc.SetFormat("F5"); * } * } * * foreach (PropertyInfo db in Integers) * { * if (!table.Columns.Contains(db.Name)) * { * var dc = table.Columns.Add(db.Name); * } * } * * return table; * } * /* * /// <summary> * /// Sets the data row. * /// </summary> * /// <param name="dr">The dr.</param> * /// <param name="table">The table.</param> * /// <param name="addRowBeforeEnd">if set to <c>true</c> [add row before end].</param> * /// <returns></returns> * public DataRow SetDataRow(DataRow dr, DataTable table, Boolean addRowBeforeEnd = true) * { * if (dr == null) dr = table.NewRow(); // new DataTable(name); * * foreach (PropertyInfo db in Doubles) * { * if (table.Columns.Contains(db.Name)) * { * dr[db.Name] = db.GetValue(this, null); * } * } * * foreach (PropertyInfo db in Integers) * { * if (table.Columns.Contains(db.Name)) * { * dr[db.Name] = db.GetValue(this, null); * } * } * if (addRowBeforeEnd) * { * table.Rows.Add(dr); * } * * return dr; * }*/ /// <summary> /// Gets value of specified property or 0 if no property found under that name /// </summary> /// <param name="propertyName">Name of the property.</param> /// <returns></returns> public virtual Double GetVector(String propertyName) { if (DoublesDict.ContainsKey(propertyName)) { return((Double)DoublesDict[propertyName].GetValue(this, null)); } else if (IntegersDict.ContainsKey(propertyName)) { return(Convert.ToDouble(IntegersDict[propertyName].GetValue(this, null))); } else if (DecimalsDict.ContainsKey(propertyName)) { return(Convert.ToDouble(DecimalsDict[propertyName].GetValue(this, null))); } else if (IgnoreComputationsDict.ContainsKey(propertyName)) { return(Convert.ToDouble(IgnoreComputationsDict[propertyName])); } return(0); }