Beispiel #1
0
        public static void AddBooleanAttribute(this XElement element, string attributeName, bool value, BooleanXmlRepresentation representation = BooleanXmlRepresentation.OneZero)
        {
            switch (representation)
            {
            default:
            case BooleanXmlRepresentation.OneZero:
                element.Add(new XAttribute(attributeName, value ? "1" : "0"));
                break;

            case BooleanXmlRepresentation.TrueFalse:
                element.Add(new XAttribute(attributeName, value ? "true" : "false"));
                break;

            case BooleanXmlRepresentation.YesNo:
                element.Add(new XAttribute(attributeName, value ? "yes" : "no"));
                break;
            }
        }
Beispiel #2
0
        public static bool GetBoolAttribute(this XElement element, string attributeName, BooleanXmlRepresentation representation = BooleanXmlRepresentation.OneZero)
        {
            var attr = GetAttribute(element, attributeName);

            if (attr == null)
            {
                return(false);
            }
            switch (representation)
            {
            default:
            case BooleanXmlRepresentation.OneZero:
                return(attr.Value == "1");

            case BooleanXmlRepresentation.TrueFalse:
                return(attr.Value.ToLower() == "true");

            case BooleanXmlRepresentation.YesNo:
                return(attr.Value.ToLower() == "yes");
            }
        }
Beispiel #3
0
        public static void WriteAttribute(this XElement element, string attributeName, bool value, BooleanXmlRepresentation representation)
        {
            string stringValue = string.Empty;

            switch (representation)
            {
            case BooleanXmlRepresentation.OneZero:
                stringValue = value ? "1" : "0"; break;

            case BooleanXmlRepresentation.TrueFalse:
                stringValue = value ? "true" : "false"; break;

            case BooleanXmlRepresentation.YesNo:
                stringValue = value ? "yes" : "no"; break;
            }
            WriteAttribute(element, attributeName, typeof(bool), stringValue);
        }