protected ParserVars GetVariables() { var properties = this.GetType().GetProperties(); ParserVars vars = new ParserVars(); foreach (var property in properties) { #region VariableAttribute ar2 = null; var arr2 = property.GetCustomAttributes(typeof(VariableAttribute), false); if (arr2.Count() > 0) { ar2 = arr2[0] as VariableAttribute; object value = property.GetValue(this, null); string typeName = value.GetType().Name; double dd = 0; if (value is bool) { dd = ((bool)value).GetHashCode(); } else if (value is int) { dd = (int)value; } else if (value is double) { dd = (double)value; } vars.AddVariable(new ParserVar(ar2.LocalName, dd, this.Name + "_" + ar2.LocalName)); Debug.WriteLine(property.GetValue(this, null)); Debug.WriteLine(property.Name); } #endregion } return(vars); //имя + локал , value }
public void RefreshVariables() { var properties = this.GetType().GetProperties(); foreach (var property in properties) { #region VariableAttribute ar2 = null; var arr2 = property.GetCustomAttributes(typeof(VariableAttribute), false); if (arr2.Count() > 0) { ar2 = arr2[0] as VariableAttribute; if (ar2.CanAssign) { object value = property.GetValue(this, null); string typeName = value.GetType().Name; double d = Variables.GetVariables().Where(o => o.Name == ar2.LocalName).First().pVar.Value; if (value is bool) { property.SetValue(this, Convert.ToBoolean(d), null); } else if (value is int) { property.SetValue(this, Convert.ToInt32(d), null); } else if (value is double) { property.SetValue(this, (d), null); } Debug.WriteLine(property.GetValue(this, null)); Debug.WriteLine(property.Name); } } #endregion } }