GuidTryParse() public static method

Converts the string representation of a Guid to its Guid equivalent. A return value indicates whether the operation succeeded.
/// Thrown if is . ///
public static GuidTryParse ( string s, System.Guid &result ) : bool
s string A string containing a Guid to convert.
result System.Guid /// When this method returns, contains the Guid value equivalent to /// the Guid contained in , if the conversion /// succeeded, or if the conversion failed. /// The conversion fails if the parameter is a /// reference ( in /// Visual Basic), or is not of the correct format. ///
return bool
Example #1
0
        /// <summary>
        /// Determines whether the specified object property value is ok.
        /// </summary>
        /// <param name="ObjectPropertyValue">The object property value.</param>
        /// <param name="Operator">The operator.</param>
        /// <param name="UserValue">The user value.</param>
        /// <returns>
        ///     <c>true</c> if the specified object property value is ok; otherwise, <c>false</c>.
        /// </returns>
        private bool IsOk(object ObjectPropertyValue, string Operator, string UserValue)
        {
            bool Rt = false;

            //Type of the property value
            if (ObjectPropertyValue == null)
            {
                return(false);
            }

            Type   TypeOfValue = ObjectPropertyValue.GetType();
            Object FilterValue = CorrectUserValue(UserValue);

            if (Operator.ToUpper().Equals("IN"))
            {
                try
                {
                    string[] fvalue = FilterValue.ToString().Substring(1, FilterValue.ToString().Length - 2).Split(',');
                    object[] values = new object[fvalue.Length];
                    if (TypeOfValue == typeof(int))
                    {
                        for (int i = 0; i < fvalue.Length; i++)
                        {
                            values[i] = int.Parse(fvalue[i]);
                        }
                    }
                    else if (TypeOfValue == typeof(string))
                    {
                        for (int i = 0; i < fvalue.Length; i++)
                        {
                            values[i] = fvalue[i];
                        }
                    }
                    else if (TypeOfValue == typeof(long))
                    {
                        for (int i = 0; i < fvalue.Length; i++)
                        {
                            values[i] = long.Parse(fvalue[i]);
                        }
                    }
                    if (values.Length > 0)
                    {
                        Rt = IsOk(ObjectPropertyValue, Operator, values);
                    }
                    else
                    {
                        throw new NotSupportedException("IN operator Filtering is not possible on the type " + TypeOfValue.ToString() + ". Please use integer or long values.");
                    }
                }
                catch (Exception ex) { throw new InvalidFilterCriteriaException("Invalid IN Filter value", ex); }
            }
            else if (TypeOfValue == typeof(string))
            {
                Rt = IsOk((string)ObjectPropertyValue, Operator, (string)FilterValue);
            }
            else if (TypeOfValue == typeof(int))
            {
                int o;
                if (int.TryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((int)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else if (TypeOfValue == typeof(double))
            {
                double o;
                if (double.TryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((double)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else if (TypeOfValue == typeof(decimal))
            {
                decimal o;
                if (decimal.TryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((decimal)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else if (TypeOfValue == typeof(DateTime))
            {
                DateTime o;
                if (DateTime.TryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((DateTime)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else if (TypeOfValue == typeof(bool))
            {
                bool o;
                if (bool.TryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((bool)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else if (TypeOfValue == typeof(Guid))
            {
                Guid o;
                if (EntityUtil.GuidTryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((Guid)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else if (TypeOfValue == typeof(byte))
            {
                byte o;
                if (byte.TryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((byte)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else if (TypeOfValue == typeof(long))
            {
                long o;
                if (long.TryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((long)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else if (TypeOfValue == typeof(short))
            {
                short o;
                if (short.TryParse(FilterValue.ToString(), out o))
                {
                    Rt = IsOk((short)ObjectPropertyValue, Operator, o);
                }
                else
                {
                    Rt = false;
                }
            }
            else
            {
                throw new Exception("Filtering is not possible on the type " + TypeOfValue.ToString());
            }
            return(Rt);
        }