Esempio n. 1
0
        public static bool TryParse(string value, out HyperLinkValue hyperLink)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            hyperLink = default;

            var temp = value.Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);

            if (temp.Length != 2)
            {
                return(false);
            }

            if (!Enum.TryParse(temp[0], true, out HyperLinkType valueType))
            {
                return(false);
            }

            switch (valueType)
            {
            case HyperLinkType.Page:
            {
                if (!Guid.TryParse(temp[1], out Guid pageId))
                {
                    return(false);
                }
                hyperLink = new HyperLinkValue(pageId);
                break;
            }

            case HyperLinkType.Url:
            {
                if (!Uri.TryCreate(temp[1], UriKind.RelativeOrAbsolute, out Uri uri))
                {
                    return(false);
                }

                hyperLink = new HyperLinkValue(uri);
                break;
            }

            default:
                throw new InvalidOperationException();
            }

            return(true);
        }
Esempio n. 2
0
 public bool Equals(HyperLinkValue other)
 {
     return(ValueType == other.ValueType && string.Compare(Value, other.Value, true) == 0);
 }