コード例 #1
0
        // --------------------------------------------------------------------------------------------
        /// <summary>
        /// Converts the string representation of a hierarchy ID to HierarchyID equivalent. A return
        /// value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="value">A string containing a hierarchy ID to convert.</param>
        /// <param name="id">
        /// When this method returns, contains the hierarchy ID value equivalent to the id contained
        /// in *value*, if the conversion succeeded, or Nil if the conversion failed.</param>
        /// <returns>
        /// true if *value* was converted successfully; otherwise, false.
        /// </returns>
        // --------------------------------------------------------------------------------------------
        public static bool TryParse(string value, out HierarchyId id)
        {
            if (String.Compare("root", value, true) == 0)
            {
                id = Root;
                return(true);
            }
            if (String.Compare("nil", value, true) == 0)
            {
                id = Nil;
                return(true);
            }
            if (String.Compare("selection", value, true) == 0)
            {
                id = Selection;
                return(true);
            }
            int intId;

            if (Int32.TryParse(value, out intId))
            {
                id = new HierarchyId(intId);
                return(true);
            }
            uint uintId;

            if (UInt32.TryParse(value, out uintId))
            {
                id = new HierarchyId(uintId);
                return(true);
            }
            id = Nil;
            return(false);
        }
コード例 #2
0
        // --------------------------------------------------------------------------------------------
        /// <summary>
        /// Converts the specified value object to a <see cref="T:System.String"/> object.
        /// </summary>
        /// <param name="context">
        /// An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context.
        /// </param>
        /// <param name="culture">
        /// The <see cref="T:System.Globalization.CultureInfo"/> to use.
        /// </param>
        /// <param name="value">The <see cref="T:System.Object"/> to convert.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> that represents the converted value.
        /// </returns>
        /// <exception cref="T:System.NotSupportedException">
        /// The conversion could not be performed.
        /// </exception>
        // --------------------------------------------------------------------------------------------
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is int)
            {
                return(new HierarchyId((int)value));
            }
            if (value is uint)
            {
                return(new HierarchyId((uint)value));
            }
            var strValue = value as string;

            if (strValue != null)
            {
                return(HierarchyId.Parse(strValue));
            }
            return(base.ConvertFrom(context, culture, value));
        }
コード例 #3
0
ファイル: HierarchyId.cs プロジェクト: sunpander/VSDT
 // --------------------------------------------------------------------------------------------
 /// <summary>
 /// Converts the string representation of a hierarchy ID to HierarchyID equivalent. A return 
 /// value indicates whether the conversion succeeded.
 /// </summary>
 /// <param name="value">A string containing a hierarchy ID to convert.</param>
 /// <param name="id">
 /// When this method returns, contains the hierarchy ID value equivalent to the id contained 
 /// in *value*, if the conversion succeeded, or Nil if the conversion failed.</param>
 /// <returns>
 /// true if *value* was converted successfully; otherwise, false. 
 /// </returns>
 // --------------------------------------------------------------------------------------------
 public static bool TryParse(string value, out HierarchyId id)
 {
     if (String.Compare("root", value, true) == 0)
       {
     id = Root;
     return true;
       }
       if (String.Compare("nil", value, true) == 0)
       {
     id = Nil;
     return true;
       }
       if (String.Compare("selection", value, true) == 0)
       {
     id = Selection;
     return true;
       }
       int intId;
       if (Int32.TryParse(value, out intId))
       {
     id = new HierarchyId(intId);
     return true;
       }
       uint uintId;
       if (UInt32.TryParse(value, out uintId))
       {
     id = new HierarchyId(uintId);
     return true;
       }
       id = Nil;
       return false;
 }