Esempio n. 1
0
        public void TestInstanceIsStringDefined()
        {
            StringEnum stringEnum = new StringEnum(typeof(EnumWithStrings));

            Assert.IsFalse(stringEnum.IsStringDefined("Something that's not there"));
            Assert.IsFalse(stringEnum.IsStringDefined("first value"));
            Assert.IsTrue(stringEnum.IsStringDefined("First Value"));
        }
Esempio n. 2
0
 private void UpdateValue(PropertyDescriptor thisProperty, XPathNavigator current, String value, Object onObject)
 {
     if (!(thisProperty.Converter is ArrayConverter))
     {
         // set value
         if (value.Length > 0)
         {
             if (thisProperty.Converter is EnumConverter) // enums are a special case
             {
                 StringEnum stringEnum = new StringEnum(thisProperty.PropertyType);
                 Boolean pass = stringEnum.IsStringDefined(value);
                 if (!pass) // normal case, no string value
                 {
                     thisProperty.SetValue(onObject,
                         thisProperty.Converter.ConvertFromString(value));
                 }
                 else // string value, reverse to the enum value
                 {
                     thisProperty.SetValue(onObject, thisProperty.Converter.ConvertFromString(stringEnum.GetEnumValue(value))); 
                 }
             }
             else // everyone else
             {
                 thisProperty.SetValue(onObject,
                     thisProperty.Converter.ConvertFromString(value));
             }
         }
         else
         {
             if (thisProperty.PropertyType == typeof(String)) // replace with empty string
             {
                 thisProperty.SetValue(onObject,
                     thisProperty.Converter.ConvertFromString(String.Empty));
             }
         }
     }
     else
     {
         if (thisProperty.Converter is ArrayConverter)
         {
             // select collection children
             XPathNodeIterator collectionChildren = current.Select("Parameter");
             int index = 0;
             Type elementType = thisProperty.PropertyType.GetElementType();
             Array newValue = Array.CreateInstance(elementType, collectionChildren.Count);
             foreach (XPathNavigator collectionChild in collectionChildren)
             {
                 String xmlValue = collectionChild.GetAttribute(ConfigFileConstants.Value, "");
                 Object result = Convert.ChangeType(xmlValue, elementType);
                 newValue.SetValue(result, index);
                 index++;
             }
             thisProperty.SetValue(onObject, newValue);
         }
     }
 }
Esempio n. 3
0
 public void TestStaticIsStringDefined()
 {
     Assert.IsFalse(StringEnum.IsStringDefined(typeof(EnumWithStrings), "My fair Lady"));
     Assert.IsTrue(StringEnum.IsStringDefined(typeof(EnumPartialStrings), "jack BE NIMble", true));
 }
 public static bool ExisteRegimenFiscal(String sRegimenFiscal)
 {
     return(StringEnum.IsStringDefined(typeof(FacturaElectronica.CFDI33.c_RegimenFiscal), sRegimenFiscal));
 }