Beispiel #1
0
        /// <summary>
        /// Construct a property from the specified string input.
        /// </summary>
        /// <param name="input">A string representation of the property as read from a vCard object.</param>
        internal PropertyBase(string input)
        {
            // Make sure input is not empty
            if (string.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentNullException("input");
            }

            // Split out the name/value.
            if (input.NonQuotedIndexOf(Constants.PROP_NAME_VAL_SEPARATOR) < 0)
            {
                throw new ArgumentOutOfRangeException("input", $"No name/value separator [{Constants.PROP_NAME_VAL_SEPARATOR}] is could be found. Improperly formed input.");
            }
            var nameValue = input.NonQuotedSplitOnFirst(Constants.PROP_NAME_VAL_SEPARATOR);

            nameValue.Item1.UnQuote();

            // Separate out the name/parameters
            if (nameValue.Item1.NonQuotedIndexOf(Constants.PROP_PARAMETER_SEPARATOR) > 0)
            {
                var nameParam = nameValue.Item1.NonQuotedSplitOnFirst(Constants.PROP_PARAMETER_SEPARATOR);
                // Parse the name
                ParseNamePart(nameParam.Item1);
                foreach (string s in nameParam.Item2.NonQuotedSplit(Constants.PROP_PARAMETER_SEPARATOR, false))
                {
                    try {
                        AddParameter(s.ParseParam());
                    } catch { }
                }
            }
            else
            {
                // No parameters, just parse the name
                ParseNamePart(nameValue.Item1);
            }

            // Set the RawValue
            RawValue = nameValue.Item2;

            // Process the values
            if (Value is IList)
            {
                if (Value == null)
                {
                    Value = Activator.CreateInstance <T>();
                }
                foreach (string s in nameValue.Item2.NonQuotedSplit(VALUE_SEPARATOR, true))
                {
                    AddValue(IETFValueEncoding.DecodeValue(s));
                }
            }
            else
            {
                SetValue(IETFValueEncoding.DecodeValue(nameValue.Item2));
            }
        }
        public void ToISO8601StringTest()
        {
            Assert.IsTrue(string.IsNullOrEmpty(IETFValueEncoding.ToISO8601String(null)));
            Assert.IsFalse(string.IsNullOrEmpty(IETFValueEncoding.ToISO8601String(DateTime.Now)));

            DateTime dt = new DateTime(2020, 4, 4, 12, 30, 23);
            // This was accurate as of the time and location tested (the date above in the US Eastern Time Zone)
            string exp = "20200404T123023-04:00";

            Assert.AreEqual(exp, IETFValueEncoding.ToISO8601String(dt));
        }
        public void ParseISO8601StringTest()
        {
            Assert.AreEqual(null, IETFValueEncoding.ParseISO8601String("asdfflkjasdf"));
            DateTime now = DateTime.Now;

            foreach (var f in IETFValueEncoding.ISO8601DT_FORMATS)
            {
                string s = now.ToString(f);
                Assert.IsTrue(IETFValueEncoding.ParseISO8601String(s).HasValue);
            }
        }
        internal PropertyParameter(Tuple <string, string> pair)
        {
            if (pair == null)
            {
                throw new ArgumentNullException(nameof(pair));
            }

            Name = pair.Item1;
            if (Value is IList)
            {
                foreach (string s in pair.Item2.NonQuotedSplit(Constants.PARAM_MULTI_VAL_SEPARATOR, true))
                {
                    AddValue(IETFValueEncoding.DecodeParameterValue(s));
                }
            }
            else
            {
                SetValue(IETFValueEncoding.DecodeParameterValue(pair.Item2));
            }
            Parameter = Name.ToKnownParameter();
        }
Beispiel #5
0
        internal PropertyBase(string name, string parameters, string value)
        {
            Name = name;
            if (!string.IsNullOrWhiteSpace(parameters))
            {
                foreach (string s in parameters.NonQuotedSplit(Constants.PROP_PARAMETER_SEPARATOR, false))
                {
                    try {
                        AddParameter(s.ParseParam());
                    } catch { }
                }
            }

            // Set RawValue
            RawValue = value;
            if (!string.IsNullOrWhiteSpace(value))
            {
                // Process the values
                if (Value is IList)
                {
                    if (Value == null)
                    {
                        Value = Activator.CreateInstance <T>();
                    }
                    foreach (string s in value.NonQuotedSplit(VALUE_SEPARATOR, true))
                    {
                        AddValue(IETFValueEncoding.DecodeValue(s));
                    }
                }
                else
                {
                    SetValue(IETFValueEncoding.DecodeValue(value));
                }
            }
            else
            {
                SetValue(default);
Beispiel #6
0
 /// <summary>
 /// Overrides the ToString method
 /// </summary>
 /// <returns>A string value</returns>
 public override string ToString()
 {
     return(Parameter.GetvCardName() + Constants.PARAM_NAME_VAL_SEPARATOR + IETFValueEncoding.EncodeParameterValue(Tag));
 }
 public void DecodeParameterValueTest(string expected, string input) =>
 Assert.AreEqual(expected, IETFValueEncoding.DecodeParameterValue(input));
 public void EncodeValueTest(string input, string expected, bool encloseInQuotes = false) =>
 Assert.AreEqual(expected, IETFValueEncoding.EncodeValue(input, encloseInQuotes));