Exemplo n.º 1
0
        protected override object ReadValue(Type t, XElement section, DeserializableAttribute attr)
        {
            switch (attr)
            {
            case RfwsDeserializableKeyAttribute keyAttr:
                object value = section.ReadKeyValue(keyAttr.Key);
                if (t == typeof(double))
                {
                    return(RfwsParserUtilities.ParseSiNotationDouble((string)value));
                }
                else
                {
                    return(value);
                }

            case RfwsDeserializableSectionAttribute sectionAttr:
                object returnValue;
                if (t.IsArray || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List <>)))
                {
                    returnValue = section.FindSections(sectionAttr);
                }
                else
                {
                    returnValue = section.FindSections(sectionAttr).FirstOrDefault();
                }

                if (returnValue == null)
                {
                    Log.Warning("Section {SectionName} with minimum version {SectionVersion} was not found in the file; section will be skipped. " +
                                "Save the RFWS file in the latest released version of the RFmx Waveform Creator to ensure all properties are set correctly",
                                sectionAttr.sectionName, sectionAttr.minimumSupportedVersion);
                }

                return(returnValue);

            default: return(null);
            }
        }
 /// <summary>
 /// Allows a child class to implement selection of a valid deserialization attribute in the case where more than one is specified. The default
 /// implementation for this method is to select the first attribute.
 /// </summary>
 /// <param name="attributes">Specifies a collection of deserialization attributes specified by the member.</param>
 /// <param name="dataContainer">Specifies the data container from which data is read.</param>
 /// <param name="validAttr">Returns the attribute that has been selected.</param>
 /// <returns></returns>
 protected virtual bool SelectValidAttribute(IEnumerable <DeserializableAttribute> attributes, TDataContainer dataContainer, out DeserializableAttribute validAttr)
 {
     validAttr = attributes.First();
     return(true);
 }
 /// <summary>
 /// In a child class, reads a value of type <paramref name="t"/> from <paramref name="dataContainer"/> using deserialization information in
 /// <paramref name="attr"/>.
 /// </summary>
 /// <param name="t">Specifies the type of object to be read from <paramref name="dataContainer"/>.</param>
 /// <param name="dataContainer">Specifies the object containing the data.</param>
 /// <param name="attr">Specifies the deserialization atttribute descrbing how data should be read.</param>
 /// <returns></returns>
 protected abstract object ReadValue(Type t, TDataContainer dataContainer, DeserializableAttribute attr);
Exemplo n.º 4
0
 protected override bool SelectValidAttribute(IEnumerable <DeserializableAttribute> attributes, XElement section, out DeserializableAttribute validAttr)
 {
     if (attributes.First() is RfwsDeserializableKeyAttribute)
     {
         float sectionVersion = section.GetSectionVersion();
         validAttr = attributes.Cast <RfwsDeserializableKeyAttribute>().Where(attr => attr.IsSupported(sectionVersion)).FirstOrDefault();
         return(validAttr != null);
     }
     else
     {
         return(base.SelectValidAttribute(attributes, section, out validAttr));
     }
 }