public static string ToString(object value, EPropAssoc assoc) { if (value is bool) { bool bvalue = (bool)value; return(bvalue ? "true" : "false"); } Type type = value.GetType(); IList <PropDesc> allFields = EnumProps(type); PropDesc pd = (from PropDesc pdi in allFields where pdi.EnumValue.Equals(value) select pdi).SingleOrDefault(); string result; if (pd == null || !pd.IDs.TryGetValue(assoc, out result)) { if (value is double) { double dbl = (double)value; result = dbl.ToString(CultureInfo.InvariantCulture); } else { result = value.ToString(); } } return(result); }
private CoreGenDescription CreateCoreGenFile(string path, EPropAssoc assoc) { CoreGenDescription cdesc = new CoreGenDescription(path); cdesc.FromProject(this, assoc); return(cdesc); }
public static string ToString(PropertyInfo pi, EPropAssoc assoc) { object[] attrs = pi.GetCustomAttributes(typeof(PropID), true); foreach (PropID propID in attrs) { if (propID.Assoc == assoc) { return(propID.ID); } } throw new InvalidOperationException("No property ID found for given association"); }
public PropertyBag Copy(EPropAssoc assoc) { PropertyBag result = new PropertyBag(); foreach (var pd in PropEnum.EnumProps(typeof(EXilinxProjectProperties))) { EXilinxProjectProperties key = (EXilinxProjectProperties)pd.EnumValue; object value; if (pd.IDs.ContainsKey(assoc) && Properties.TryGetValue(key, out value)) { result.PutProperty(key, value); } } return(result); }
internal static void FromProject(this CoreGenDescription desc, XilinxProject proj, EPropAssoc assoc) { PropertyBag pbag = proj.PBag.Copy(assoc); if (assoc == EPropAssoc.CoreGenProj) { string fname = Path.GetFileNameWithoutExtension(desc.Path); string wdir = "./tmp/" + fname + "/"; pbag.PutProperty(EXilinxProjectProperties.CoreGen_WorkingDirectory, wdir); } IList<PropDesc> allProps = PropEnum.EnumProps(typeof(EXilinxProjectProperties)); foreach (PropDesc pd in allProps) { if (!pd.IDs.ContainsKey(assoc)) continue; object value = pbag.GetProperty((EXilinxProjectProperties)pd.EnumValue); desc.Set(pd.IDs[assoc], PropEnum.ToString(value, assoc), value.GetType()); } }
internal static void FromProject(this CoreGenDescription desc, XilinxProject proj, EPropAssoc assoc) { PropertyBag pbag = proj.PBag.Copy(assoc); if (assoc == EPropAssoc.CoreGenProj) { string fname = Path.GetFileNameWithoutExtension(desc.Path); string wdir = "./tmp/" + fname + "/"; pbag.PutProperty(EXilinxProjectProperties.CoreGen_WorkingDirectory, wdir); } IList <PropDesc> allProps = PropEnum.EnumProps(typeof(EXilinxProjectProperties)); foreach (PropDesc pd in allProps) { if (!pd.IDs.ContainsKey(assoc)) { continue; } object value = pbag.GetProperty((EXilinxProjectProperties)pd.EnumValue); desc.Set(pd.IDs[assoc], PropEnum.ToString(value, assoc), value.GetType()); } }
public PropID(EPropAssoc assoc, string id) { Assoc = assoc; ID = id; }
public PropertyBag Copy(EPropAssoc assoc) { PropertyBag result = new PropertyBag(); foreach (var pd in PropEnum.EnumProps(typeof(EXilinxProjectProperties))) { EXilinxProjectProperties key = (EXilinxProjectProperties)pd.EnumValue; object value; if (pd.IDs.ContainsKey(assoc) && Properties.TryGetValue(key, out value)) result.PutProperty(key, value); } return result; }
public static string ToString(PropertyInfo pi, EPropAssoc assoc) { object[] attrs = pi.GetCustomAttributes(typeof(PropID), true); foreach (PropID propID in attrs) { if (propID.Assoc == assoc) return propID.ID; } throw new InvalidOperationException("No property ID found for given association"); }
public static string ToString(object value, EPropAssoc assoc) { if (value is bool) { bool bvalue = (bool)value; return bvalue ? "true" : "false"; } Type type = value.GetType(); IList<PropDesc> allFields = EnumProps(type); PropDesc pd = (from PropDesc pdi in allFields where pdi.EnumValue.Equals(value) select pdi).SingleOrDefault(); string result; if (pd == null || !pd.IDs.TryGetValue(assoc, out result)) { if (value is double) { double dbl = (double)value; result = dbl.ToString(CultureInfo.InvariantCulture); } else { result = value.ToString(); } } return result; }