Beispiel #1
0
 public override object ConvertFrom(ITypeDescriptorContext context,
                                    CultureInfo culture, object value)
 {
     if (value is string)
     {
         try
         {
             return(BacnetBitString.Parse(value as String));
         }
         catch { return(null); }
     }
     return(base.ConvertFrom(context, culture, value));
 }
Beispiel #2
0
        public static BacnetValue DeserializeValue(string value, BacnetApplicationTags type)
        {
            switch (type)
            {
            case BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL:
                if (value == "")
                {
                    return(new BacnetValue(type, null));    // Modif FC
                }
                else
                {
                    return(new BacnetValue(value));
                }

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_BOOLEAN:
                return(new BacnetValue(type, bool.Parse(value)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT:
                return(new BacnetValue(type, uint.Parse(value)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_SIGNED_INT:
                return(new BacnetValue(type, int.Parse(value)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL:
                return(new BacnetValue(type, float.Parse(value, System.Globalization.CultureInfo.InvariantCulture)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_DOUBLE:
                return(new BacnetValue(type, double.Parse(value, System.Globalization.CultureInfo.InvariantCulture)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_OCTET_STRING:
                try
                {
                    return(new BacnetValue(type, Convert.FromBase64String(value)));
                }
                catch
                {
                    return(new BacnetValue(type, value));
                }

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_CONTEXT_SPECIFIC_DECODED:
                try
                {
                    return(new BacnetValue(type, Convert.FromBase64String(value)));
                }
                catch
                {
                    return(new BacnetValue(type, value));
                }

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_CHARACTER_STRING:
                return(new BacnetValue(type, value));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_BIT_STRING:
                return(new BacnetValue(type, BacnetBitString.Parse(value)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED:
                return(new BacnetValue(type, uint.Parse(value)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_DATE:
                return(new BacnetValue(type, DateTime.Parse(value)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_TIME:
                return(new BacnetValue(type, DateTime.Parse(value)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_OBJECT_ID:
                return(new BacnetValue(type, BacnetObjectId.Parse(value)));

            case BacnetApplicationTags.BACNET_APPLICATION_TAG_READ_ACCESS_SPECIFICATION:
                return(new BacnetValue(type, BacnetReadAccessSpecification.Parse(value)));

            default:
                return(new BacnetValue(type, null));
            }
        }