Beispiel #1
0
        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);
        }
Beispiel #2
0
        public static IList <PropDesc> EnumProps(Type type)
        {
            FieldInfo[]     fields = type.GetFields();
            List <PropDesc> result = new List <PropDesc>();

            foreach (FieldInfo field in fields)
            {
                if (!field.IsStatic)
                {
                    continue;
                }
                object   value        = field.GetValue(null);
                object[] valueTypes   = field.GetCustomAttributes(typeof(PropValueType), false);
                Type     valueType    = null;
                object   defaultValue = null;
                foreach (PropValueType pvt in valueTypes)
                {
                    valueType    = pvt.Type;
                    defaultValue = pvt.DefaultValue;
                }
                PropDesc pd      = new PropDesc(value, valueType, defaultValue);
                object[] propIDs = field.GetCustomAttributes(typeof(PropID), false);
                foreach (PropID pid in propIDs)
                {
                    pd.IDs[pid.Assoc] = pid.ID;
                }
                result.Add(pd);
            }
            return(result);
        }
Beispiel #3
0
        public static PropDesc FindProp(EXilinxProjectProperties prop)
        {
            IList <PropDesc> allProps = PropEnum.EnumProps(typeof(EXilinxProjectProperties));
            PropDesc         pd       = (from PropDesc pdi in allProps
                                         where pdi.EnumValue.Equals(prop)
                                         select pdi).Single();

            return(pd);
        }
Beispiel #4
0
        public object GetProperty(EXilinxProjectProperties prop)
        {
            PropDesc pd = PropEnum.FindProp(prop);
            object   result;

            if (!Properties.TryGetValue(prop, out result))
            {
                result = pd.DefaultValue;
            }
            return(result);
        }
Beispiel #5
0
        public void PutProperty(EXilinxProjectProperties prop, object value)
        {
            if (value == null)
            {
                throw new ArgumentException("Value must be non-null");
            }

            PropDesc pd = PropEnum.FindProp(prop);

            if (!pd.Type.IsInstanceOfType(value))
            {
                throw new ArgumentException("Wrong argument type");
            }

            Properties[prop] = value;
        }
 public static IList<PropDesc> EnumProps(Type type)
 {
     FieldInfo[] fields = type.GetFields();
     List<PropDesc> result = new List<PropDesc>();
     foreach (FieldInfo field in fields)
     {
         if (!field.IsStatic)
             continue;
         object value = field.GetValue(null);
         object[] valueTypes = field.GetCustomAttributes(typeof(PropValueType), false);
         Type valueType = null;
         object defaultValue = null;
         foreach (PropValueType pvt in valueTypes)
         {
             valueType = pvt.Type;
             defaultValue = pvt.DefaultValue;
         }
         PropDesc pd = new PropDesc(value, valueType, defaultValue);
         object[] propIDs = field.GetCustomAttributes(typeof(PropID), false);
         foreach (PropID pid in propIDs)
         {
             pd.IDs[pid.Assoc] = pid.ID;
         }
         result.Add(pd);
     }
     return result;
 }