コード例 #1
0
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (typeof(string) == destinationType)
            {
                return(((MaybeTreeBlobPath)value).ToString());
            }
            else if (typeof(Errorable <MaybeTreeBlobPath>) == destinationType)
            {
                string strValue = value as string;
                if (strValue == null)
                {
                    return((Errorable <MaybeTreeBlobPath>)null);
                }

                try
                {
                    // {TreeID}:{CanonicalBlobPath}
                    CanonicalBlobPath path;
                    Maybe <TreeID>    rootTreeID;

                    int colon = strValue.IndexOf(':');
                    if (colon >= 0)
                    {
                        var eroot = TreeID.TryParse(strValue.Substring(0, colon));
                        if (eroot.HasErrors)
                        {
                            return((Errorable <MaybeTreeBlobPath>)eroot.Errors);
                        }

                        rootTreeID = eroot.Value;
                        // TODO: TryParse on CanonicalBlobPath...
                        path = (CanonicalBlobPath)('/' + strValue.Substring(colon + 1));
                    }
                    else
                    {
                        rootTreeID = Maybe <TreeID> .Nothing;
                        // TODO: TryParse on CanonicalBlobPath...
                        path = (CanonicalBlobPath)('/' + strValue);
                    }

                    return((Errorable <MaybeTreeBlobPath>) new MaybeTreeBlobPath(rootTreeID, path));
                }
                catch (ErrorBase err)
                {
                    return((Errorable <MaybeTreeBlobPath>)err);
                }
                catch (Exception ex)
                {
                    return((Errorable <MaybeTreeBlobPath>) new InputError(ex.Message));
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
コード例 #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            string strValue = value as string;

            if (strValue != null)
            {
                return(TreeID.TryParse(strValue).Value);
            }

            return(base.ConvertFrom(context, culture, value));
        }
コード例 #3
0
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (typeof(string) == destinationType)
            {
                return(((TreeID)value).ToString());
            }
            else if (typeof(Errorable <TreeID>) == destinationType)
            {
                string strValue = value as string;
                if (strValue != null)
                {
                    return(TreeID.TryParse(strValue));
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
コード例 #4
0
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (typeof(string) == destinationType)
            {
                return(((TreeBlobPath)value).ToString());
            }
            else if (typeof(Errorable <TreeBlobPath>) == destinationType)
            {
                string strValue = value as string;
                if (strValue == null)
                {
                    return((Errorable <TreeBlobPath>)null);
                }

                try
                {
                    // {TreeID}:{CanonicalBlobPath}
                    int colon = strValue.IndexOf(':');
                    if (colon < 0)
                    {
                        return((Errorable <TreeBlobPath>) new TreeID.ParseError("Could not find first ':' char of TreeBlobPath"));
                    }

                    var eroot = TreeID.TryParse(strValue.Substring(0, colon));
                    if (eroot.HasErrors)
                    {
                        return((Errorable <TreeBlobPath>)eroot.Errors);
                    }

                    // TODO: TryParse on CanonicalBlobPath...
                    CanonicalBlobPath path = (CanonicalBlobPath)('/' + strValue.Substring(colon + 1));

                    return((Errorable <TreeBlobPath>) new TreeBlobPath(eroot.Value, path));
                }
                catch (ErrorBase err)
                {
                    return((Errorable <TreeBlobPath>)err);
                }
                catch (Exception ex)
                {
                    return((Errorable <TreeBlobPath>) new InputError(ex.Message));
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }