コード例 #1
0
ファイル: FilterNode.cs プロジェクト: YHZX2013/exchange_diff
 private static void GetNodeFromComparisonFilter(ComparisonFilter comparisonFilter, Hashtable allowedProperties, List <FilterNode> filterNodes, bool isNotFilter)
 {
     if (allowedProperties.ContainsKey(comparisonFilter.Property.Name))
     {
         FilterNode filterNode = new FilterNode();
         filterNode.FilterablePropertyDescription = (FilterablePropertyDescription)allowedProperties[comparisonFilter.Property.Name];
         filterNode.Operator = (PropertyFilterOperator)comparisonFilter.ComparisonOperator;
         if (typeof(Enum).IsAssignableFrom(comparisonFilter.Property.Type))
         {
             filterNode.Value = Enum.Parse(comparisonFilter.Property.Type, comparisonFilter.PropertyValue.ToString(), true);
         }
         else if (typeof(bool).IsAssignableFrom(comparisonFilter.Property.Type))
         {
             filterNode.Value = !isNotFilter;
         }
         else if (comparisonFilter.Property.Type == typeof(MultiValuedProperty <string>))
         {
             filterNode.Value = comparisonFilter.PropertyValue.ToUserFriendText(CultureInfo.CurrentUICulture.TextInfo.ListSeparator, (object input) => false);
         }
         else
         {
             filterNode.Value = MonadFilter.ConvertValueFromString(comparisonFilter.PropertyValue, comparisonFilter.Property.Type);
         }
         filterNodes.Add(filterNode);
         return;
     }
     throw new InvalidOperationException(Strings.UnknownFilterableProperty(comparisonFilter.Property.Name).ToString());
 }
コード例 #2
0
        private static object ConvertValueFromString(object valueToConvert, Type resultType)
        {
            string value = valueToConvert as string;
            bool   flag;

            if (!string.IsNullOrEmpty(value) && resultType.Equals(typeof(bool)) && bool.TryParse(value, out flag))
            {
                return(flag);
            }
            return(MonadFilter.ConvertValueFromString(valueToConvert, resultType));
        }
コード例 #3
0
ファイル: FilterNode.cs プロジェクト: YHZX2013/exchange_diff
        public string Validate()
        {
            if (this.ValueParsingError != null)
            {
                return(string.Format("{0}: '{1}'", this.DisplayName, this.ValueParsingError));
            }
            string text = null;

            if (this.op == PropertyFilterOperator.Equal || this.op == PropertyFilterOperator.NotEqual || this.op == PropertyFilterOperator.GreaterThan || this.op == PropertyFilterOperator.LessThan || this.op == PropertyFilterOperator.LessThanOrEqual || this.op == PropertyFilterOperator.GreaterThanOrEqual)
            {
                Type type = this.Value.GetType();
                if (type != this.PropertyDefinition.Type)
                {
                    try
                    {
                        string valueToConvert;
                        if (this.Value is DateTime)
                        {
                            valueToConvert = ((DateTime)this.Value).ToString("s");
                        }
                        else
                        {
                            valueToConvert = this.Value.ToString();
                        }
                        MonadFilter.ConvertValueFromString(valueToConvert, this.PropertyDefinition.Type);
                    }
                    catch (PSInvalidCastException ex)
                    {
                        Exception ex2 = ex;
                        while (ex2.InnerException != null && !(ex2.InnerException is FormatException))
                        {
                            ex2 = ex2.InnerException;
                        }
                        text = string.Format("{0}: '{1}'", this.DisplayName, (ex2.InnerException != null) ? ex2.InnerException.Message : ex.Message);
                        if (this.PropertyDefinition.Type == typeof(Version))
                        {
                            text = string.Format("{0}. {1}", text, Strings.ValidVersionExample);
                        }
                    }
                }
            }
            return(text);
        }