public void SetValue(string systemvar, params object[] values) { foreach (PropertyInfo p in this.GetType().GetProperties()) { CadSystemVariableAttribute att = p.GetCustomAttribute <CadSystemVariableAttribute>(); if (att == null || att.Name != systemvar) { continue; } object build = null; ConstructorInfo constr = p.PropertyType.GetConstructor(values.Select(o => o.GetType()).ToArray()); if (p.PropertyType.IsEnum) { build = Enum.ToObject(p.PropertyType, values.First()); } else if (constr == null) { build = Convert.ChangeType(values.First(), p.PropertyType); } else { build = Activator.CreateInstance(p.PropertyType, values); } //Set the value if it has any if (build != null) { p.SetValue(this, build); break; } } }
public static Dictionary <string, DxfCode[]> GetHeaderMap() { Dictionary <string, DxfCode[]> map = new Dictionary <string, DxfCode[]>(); foreach (PropertyInfo p in typeof(CadHeader).GetProperties()) { CadSystemVariableAttribute att = p.GetCustomAttribute <CadSystemVariableAttribute>(); if (att == null) { continue; } map.Add(att.Name, att.ValueCodes); } return(map); }
public void SetValue(string systemvar, object value) { foreach (PropertyInfo p in GetType().GetProperties()) { CadSystemVariableAttribute att = p.GetCustomAttribute <CadSystemVariableAttribute>(); if (att == null) { continue; } if ($"${att.Name}" == systemvar) { p.SetValue(this, value); break; } } }
public object GetValue(string systemvar) { object value = null; foreach (PropertyInfo p in this.GetType().GetProperties()) { CadSystemVariableAttribute att = p.GetCustomAttribute <CadSystemVariableAttribute>(); if (att == null) { continue; } if (att.Name == systemvar) { value = p.GetValue(this); break; } } return(value); }