コード例 #1
0
        private string SerializeAsString(FilterPropertyType filterPropertyType, object value)
        {
            switch (filterPropertyType)
            {
            case FilterPropertyType.Float:
                return(((float)value).ToString(GraphFileFormat.Ver_0_1.NumberStyles));

            case FilterPropertyType.Integer:
                return(((int)value).ToString(GraphFileFormat.Ver_0_1.NumberStyles));

            case FilterPropertyType.String:
            case FilterPropertyType.Enum:
                return(value.ToString());

            case FilterPropertyType.Point:
                var point = (Point)value;
                var x     = point.X.ToString(GraphFileFormat.Ver_0_1.NumberStyles);
                var y     = point.Y.ToString(GraphFileFormat.Ver_0_1.NumberStyles);
                return(x + "," + y);

            case FilterPropertyType.Size:
                var size   = (Size)value;
                var width  = size.Width.ToString(GraphFileFormat.Ver_0_1.NumberStyles);
                var height = size.Height.ToString(GraphFileFormat.Ver_0_1.NumberStyles);
                return(width + "," + height);

            default:
                throw new ArgumentOutOfRangeException("filterPropertyType");
            }
        }
コード例 #2
0
 protected NumericProperty(string name, FilterPropertyType type, decimal min, decimal max, decimal step, int decimalPlaces = 0)
     : base(name, type)
 {
     Min           = min;
     Max           = max;
     Step          = step;
     DecimalPlaces = decimalPlaces;
 }
コード例 #3
0
 public FilterProperty(string name, string value, FilterPropertyType propertyType, string suffix = null, string filterOn = null)
 {
     Key          = name;
     Value        = value;
     PropertyType = propertyType;
     Suffix       = suffix;
     FilterOn     = filterOn;
 }
コード例 #4
0
        private void BindValue(JValue jValue, FilterPropertyType propertyType, JsonSerializer serializer)
        {
            Type type = propertyType.ToType();

            if (jValue.Value.GetType() != type)
            {
                jValue.Value = serializer.Deserialize(jValue.CreateReader(), type);
            }
        }
コード例 #5
0
 private void BindValueToken(JToken token, FilterPropertyType propertyType, JsonSerializer serializer)
 {
     if (token is JValue)
     {
         BindValue((JValue)token, propertyType, serializer);
     }
     else if (token is JArray)
     {
         BindArray((JArray)token, propertyType, serializer);
     }
 }
コード例 #6
0
        private bool IsSerializableAsString(FilterPropertyType filterPropertyType)
        {
            switch (filterPropertyType)
            {
            case FilterPropertyType.Float:
            case FilterPropertyType.Integer:
            case FilterPropertyType.String:
            case FilterPropertyType.Point:
            case FilterPropertyType.Size:
            case FilterPropertyType.Enum:
                return(true);

            default:
                throw new ArgumentOutOfRangeException("filterPropertyType");
            }
        }
        private Expression <Func <TEntity, bool> > CollectionContainsExpr()
        {
            var genericType = FilterPropertyType.GetGenericArguments().First();
            var methodInfo  = typeof(CollectionExtensions)
                              .GetMethod(nameof(CollectionExtensions.ContainsMethod), BindingFlags.Public | BindingFlags.Static);

            var valueToEquals = Expression.Constant(FilterPropertyValue);

            Type[]     genericArguments  = { genericType };
            MethodInfo genericMethodInfo = methodInfo.MakeGenericMethod(genericArguments);
            Delegate   @delegate         = (Delegate)genericMethodInfo.Invoke(null,
                                                                              new[] { FilterPropertyValue, Delegates.ContainsEqualityComparer });

            var methodCallExpression = Expression.Call(null, @delegate.Method, valueToEquals, PropertyOrField);

            var lambda = methodCallExpression.LambdaExpressionBuilder <TEntity>(Item);

            return(lambda);
        }
コード例 #8
0
        protected override IFilter Create(Type objectType, JObject jObject, JsonSerializer serializer)
        {
            JToken typeToken = jObject[TypeFieldName];
            string type      = typeToken == null ? null : typeToken.Value <string>();

            if (typeToken == null || string.IsNullOrEmpty(type))
            {
                return(new AlwaysTrueFilter());
            }
            if (type == "simple")
            {
                JToken             propertyTypeToken = jObject[PropertyTypeFieldName];
                FilterPropertyType propertyType      = propertyTypeToken == null
                    ? FilterPropertyType.Auto
                    : serializer.Deserialize <FilterPropertyType>(propertyTypeToken.CreateReader());
                JToken valueToken = jObject[ValueFieldName];
                if (valueToken != null)
                {
                    BindValueToken(valueToken, propertyType, serializer);
                }
            }
            return(!_constructors.ContainsKey(type) ? new AlwaysTrueFilter() : _constructors[type]());
        }
コード例 #9
0
        private IEnumerable <XNode> GetFilterPropertyNodes(IFilterProperty filterProperty)
        {
            var filterPropertyNode = new XElement(FileFormat.Node_FilterProperty);

            filterPropertyNode.Add(new XAttribute(FileFormat.Node_FilterProperty_Name, filterProperty.Name));

            object propertyValue = filterProperty.Value;

            if (propertyValue != null)
            {
                FilterPropertyType propertyType = filterProperty.Type;
                if (IsSerializableAsString(propertyType))
                {
                    string valueAsStr = SerializeAsString(propertyType, propertyValue);
                    filterPropertyNode.Add(new XAttribute(FileFormat.Node_FilterProperty_Value, valueAsStr));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            yield return(filterPropertyNode);
        }
コード例 #10
0
ファイル: Property.cs プロジェクト: kholodovitch/opencv-graph
 public Property(string name, FilterPropertyType type)
 {
     _name = name;
     _type = type;
 }
コード例 #11
0
 private void BindArray(JArray token, FilterPropertyType propertyType, JsonSerializer serializer)
 {
     token.Cast <JValue>().ToList().ForEach(x => BindValue(x, propertyType, serializer));
 }
コード例 #12
0
 public FilterAttribute(string name, FilterPropertyType propertyType = FilterPropertyType.String)
 {
     Name         = name;
     PropertyType = propertyType;
 }
コード例 #13
0
ファイル: frmMain.cs プロジェクト: sunpander/VSDT
        private void FillPropertyGrid1(FilterPropertyType filter)
        {
            string[] Languages = new string[] { "English", "Italian", "Spanish", "Dutch" };
            MyOwnClass[] ListValues = new MyOwnClass[] { new MyOwnClass("English", 0), new MyOwnClass("Italian", 1), new MyOwnClass("Spanish", 2), new MyOwnClass("Dutch", 3) };
            int[] Values = new int[] { 1, 2, 3, 4 };
            MyOwnClass oInstance = new MyOwnClass("String value", 0);

            // The variable filter is used in the "Serialization Example"
            // The filter remove from the grid the properties not correctly supported
            // or not supported at all.

            Properties.ShowCustomProperties = true;
            Properties.Item.Clear();

            // Simple properties
            Properties.Item.Add("My Integer", 100, false, "Simple properties", "This is an integer", true);
            Properties.Item.Add("My Double", 10.4, false, "Simple properties", "This is a double", true);
            Properties.Item.Add("My String", "My Value", false, "Simple properties", "This is a string", true);
            if (filter != FilterPropertyType.FilterXmlSerializer)
            {
                Properties.Item.Add("My Font", new Font("Arial", 9), false, "Simple properties", "This is a font class", true);
                Properties.Item.Add("My Color", new Color(), false, "Simple properties", "This is a color class", true);
                Properties.Item.Add("My Point", new Point(10, 10), false, "Simple properties", "This is point class", true);
            }
            Properties.Item.Add("My Date", new DateTime(DateAndTime.Today.Ticks), true, "Simple properties", "This is date class", true);
            Properties.Item.Add("My Enum", MyEnum.FirstEntry, false, "Simple properties", "Work with Enum too!", true);

            // IsPassword attribute
            Properties.Item.Add("My Password", "password", false, ".NET v2.0 only", "This is a masked string." + "\r\n" + "(This feature is available only under .NET v2.0)", true);
            Properties.Item[Properties.Item.Count - 1].IsPassword = true;

            // Filename editor
            Properties.Item.Add("Filename", "", false, "Properties with custom UITypeEditor", "This property is a filename path. It define a custom UITypeConverter that show a OpenFileDialog or a SaveFileDialog when the user press the 3 dots button to edit the value.", true);
            Properties.Item[Properties.Item.Count - 1].UseFileNameEditor = true;
            Properties.Item[Properties.Item.Count - 1].FileNameDialogType = UIFilenameEditor.FileDialogType.LoadFileDialog;
            Properties.Item[Properties.Item.Count - 1].FileNameFilter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

            if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer)
            {
                // Custom Editor
                Properties.Item.Add("My Custom Editor", "", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true);
                Properties.Item[Properties.Item.Count - 1].CustomEditor = new MyEditor();

                // Custom Event Editor
                Properties.Item.Add("My Custom Event", "Click me", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true);
                Properties.Item[Properties.Item.Count - 1].OnClick += this.CustomEventItem_OnClick;

                // Custom TypeConverter
                Properties.Item.Add("Integer", 1, false, "Properties with custom TypeConverter", "This property have a custom type converter that show a custom error message.", true);
                Properties.Item[Properties.Item.Count - 1].CustomTypeConverter = new MyTypeConverter();
            }

            // Custom Choices Type Converter
            if (filter != FilterPropertyType.FilterXmlSerializer)
            {
                Properties.Item.Add("Language", "", false, "Properties with custom TypeConverter", "This property uses a TypeConverter to dropdown a list of values.", true);
                Properties.Item[Properties.Item.Count - 1].Choices = new CustomChoices(Languages, true);

                Properties.Item.Add("Values", 1, false, "Properties with custom TypeConverter", "This property uses a TypeConverter to dropdown a list of values.", true);
                Properties.Item[Properties.Item.Count - 1].Choices = new CustomChoices(Values, false);
            }

            if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer)
            {
                // Expandable Type Converter
                Properties.Item.Add("My object", oInstance, false, "Properties with custom TypeConverter", "This property make a \'MyOwnClass\' instance browsable.", true);
                Properties.Item[Properties.Item.Count - 1].IsBrowsable = true;
                Properties.Item[Properties.Item.Count - 1].BrowsableLabelStyle = BrowsableTypeConverter.LabelStyle.lsEllipsis;
            }

            // Dynamic properties
            if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer)
            {
                object grid = Properties;
                Properties.Item.Add("Autosize properties", ref grid, "AutoSizeProperties", false, "Dynamic Properties", "This is a dynamic bound property. It changes the autosize property of this grid. Try it!", true);
                Properties.Item.Add("Draw flat toolbar", ref grid, "DrawFlatToolbar", false, "Dynamic Properties", "This is a dynamic bound property. It changes the DrawFlatToolbar property of this grid. Try it!", true);

                object form = this;
                Properties.Item.Add("Form opacity", ref form, "Opacity", false, "Dynamic Properties", "This is a dynamic bound property. It changes the Opacity property of this form. Try it!", true);
                Properties.Item[Properties.Item.Count - 1].IsPercentage = true;

                // PropertyGridEx
                Properties.Item.Add("Item", ref grid, "Item", false, "PropertyGridEx", "Represent the PropertyGridEx Item collection.",true);
                Properties.Item[Properties.Item.Count - 1].Parenthesize = true;

                Properties.Item.Add("DocComment", ref grid, "DocComment", false, "PropertyGridEx", "Represent the DocComment usercontrol of the PropertyGrid.", true);
                Properties.Item[Properties.Item.Count - 1].IsBrowsable = true;

                Properties.Item.Add("Image", ref grid, "DocCommentImage", false, "PropertyGridEx", "Represent the DocComment usercontrol of the PropertyGrid.", true);
                Properties.Item[Properties.Item.Count - 1].DefaultValue = null;
                Properties.Item[Properties.Item.Count - 1].DefaultType = typeof(Image);

                Properties.Item.Add("Toolstrip", ref grid, "Toolstrip", false, "PropertyGridEx", "Represent the toolstrip of the PropertyGrid.", true);
                Properties.Item[Properties.Item.Count - 1].IsBrowsable = true;

            }
            if (filter == FilterPropertyType.FilterBinaryFormatter)
            {

                // Databinding works with serialization
                Properties.Item.Add("Array of objects", ListValues[2].Text, false, "Databinding", "This is a UITypeEditor that implement a listbox", true);
                Properties.Item[Properties.Item.Count - 1].ValueMember = "Value";
                Properties.Item[Properties.Item.Count - 1].DisplayMember = "Text";
                Properties.Item[Properties.Item.Count - 1].Datasource = ListValues;
            }

            Properties.Refresh();
        }
コード例 #14
0
ファイル: frmMain.cs プロジェクト: Loong-Lee/VSDT
        private void FillPropertyGrid1(FilterPropertyType filter)
        {
            string[]     Languages  = new string[] { "English", "Italian", "Spanish", "Dutch" };
            MyOwnClass[] ListValues = new MyOwnClass[] { new MyOwnClass("English", 0), new MyOwnClass("Italian", 1), new MyOwnClass("Spanish", 2), new MyOwnClass("Dutch", 3) };
            int[]        Values     = new int[] { 1, 2, 3, 4 };
            MyOwnClass   oInstance  = new MyOwnClass("String value", 0);

            // The variable filter is used in the "Serialization Example"
            // The filter remove from the grid the properties not correctly supported
            // or not supported at all.

            Properties.ShowCustomProperties = true;
            Properties.Item.Clear();

            // Simple properties
            Properties.Item.Add("My Integer", 100, false, "Simple properties", "This is an integer", true);
            Properties.Item.Add("My Double", 10.4, false, "Simple properties", "This is a double", true);
            Properties.Item.Add("My String", "My Value", false, "Simple properties", "This is a string", true);
            if (filter != FilterPropertyType.FilterXmlSerializer)
            {
                Properties.Item.Add("My Font", new Font("Arial", 9), false, "Simple properties", "This is a font class", true);
                Properties.Item.Add("My Color", new Color(), false, "Simple properties", "This is a color class", true);
                Properties.Item.Add("My Point", new Point(10, 10), false, "Simple properties", "This is point class", true);
            }
            Properties.Item.Add("My Date", new DateTime(DateAndTime.Today.Ticks), true, "Simple properties", "This is date class", true);
            Properties.Item.Add("My Enum", MyEnum.FirstEntry, false, "Simple properties", "Work with Enum too!", true);

            // IsPassword attribute
            Properties.Item.Add("My Password", "password", false, ".NET v2.0 only", "This is a masked string." + "\r\n" + "(This feature is available only under .NET v2.0)", true);
            Properties.Item[Properties.Item.Count - 1].IsPassword = true;

            // Filename editor
            Properties.Item.Add("Filename", "", false, "Properties with custom UITypeEditor", "This property is a filename path. It define a custom UITypeConverter that show a OpenFileDialog or a SaveFileDialog when the user press the 3 dots button to edit the value.", true);
            Properties.Item[Properties.Item.Count - 1].UseFileNameEditor  = true;
            Properties.Item[Properties.Item.Count - 1].FileNameDialogType = UIFilenameEditor.FileDialogType.LoadFileDialog;
            Properties.Item[Properties.Item.Count - 1].FileNameFilter     = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

            if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer)
            {
                // Custom Editor
                Properties.Item.Add("My Custom Editor", "", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true);
                Properties.Item[Properties.Item.Count - 1].CustomEditor = new MyEditor();

                // Custom Event Editor
                Properties.Item.Add("My Custom Event", "Click me", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true);
                Properties.Item[Properties.Item.Count - 1].OnClick += this.CustomEventItem_OnClick;

                // Custom TypeConverter
                Properties.Item.Add("Integer", 1, false, "Properties with custom TypeConverter", "This property have a custom type converter that show a custom error message.", true);
                Properties.Item[Properties.Item.Count - 1].CustomTypeConverter = new MyTypeConverter();
            }

            // Custom Choices Type Converter
            if (filter != FilterPropertyType.FilterXmlSerializer)
            {
                Properties.Item.Add("Language", "", false, "Properties with custom TypeConverter", "This property uses a TypeConverter to dropdown a list of values.", true);
                Properties.Item[Properties.Item.Count - 1].Choices = new CustomChoices(Languages, true);

                Properties.Item.Add("Values", 1, false, "Properties with custom TypeConverter", "This property uses a TypeConverter to dropdown a list of values.", true);
                Properties.Item[Properties.Item.Count - 1].Choices = new CustomChoices(Values, false);
            }

            if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer)
            {
                // Expandable Type Converter
                Properties.Item.Add("My object", oInstance, false, "Properties with custom TypeConverter", "This property make a \'MyOwnClass\' instance browsable.", true);
                Properties.Item[Properties.Item.Count - 1].IsBrowsable         = true;
                Properties.Item[Properties.Item.Count - 1].BrowsableLabelStyle = BrowsableTypeConverter.LabelStyle.lsEllipsis;
            }

            // Dynamic properties
            if (filter != FilterPropertyType.FilterBinaryFormatter && filter != FilterPropertyType.FilterXmlSerializer)
            {
                object grid = Properties;
                Properties.Item.Add("Autosize properties", ref grid, "AutoSizeProperties", false, "Dynamic Properties", "This is a dynamic bound property. It changes the autosize property of this grid. Try it!", true);
                Properties.Item.Add("Draw flat toolbar", ref grid, "DrawFlatToolbar", false, "Dynamic Properties", "This is a dynamic bound property. It changes the DrawFlatToolbar property of this grid. Try it!", true);

                object form = this;
                Properties.Item.Add("Form opacity", ref form, "Opacity", false, "Dynamic Properties", "This is a dynamic bound property. It changes the Opacity property of this form. Try it!", true);
                Properties.Item[Properties.Item.Count - 1].IsPercentage = true;

                // PropertyGridEx
                Properties.Item.Add("Item", ref grid, "Item", false, "PropertyGridEx", "Represent the PropertyGridEx Item collection.", true);
                Properties.Item[Properties.Item.Count - 1].Parenthesize = true;

                Properties.Item.Add("DocComment", ref grid, "DocComment", false, "PropertyGridEx", "Represent the DocComment usercontrol of the PropertyGrid.", true);
                Properties.Item[Properties.Item.Count - 1].IsBrowsable = true;

                Properties.Item.Add("Image", ref grid, "DocCommentImage", false, "PropertyGridEx", "Represent the DocComment usercontrol of the PropertyGrid.", true);
                Properties.Item[Properties.Item.Count - 1].DefaultValue = null;
                Properties.Item[Properties.Item.Count - 1].DefaultType  = typeof(Image);

                Properties.Item.Add("Toolstrip", ref grid, "Toolstrip", false, "PropertyGridEx", "Represent the toolstrip of the PropertyGrid.", true);
                Properties.Item[Properties.Item.Count - 1].IsBrowsable = true;
            }
            if (filter == FilterPropertyType.FilterBinaryFormatter)
            {
                // Databinding works with serialization
                Properties.Item.Add("Array of objects", ListValues[2].Text, false, "Databinding", "This is a UITypeEditor that implement a listbox", true);
                Properties.Item[Properties.Item.Count - 1].ValueMember   = "Value";
                Properties.Item[Properties.Item.Count - 1].DisplayMember = "Text";
                Properties.Item[Properties.Item.Count - 1].Datasource    = ListValues;
            }

            Properties.Refresh();
        }
コード例 #15
0
 internal static Type ToType(this FilterPropertyType propertyType)
 {
     return(!TypeMapping.ContainsKey(propertyType)
         ? typeof(object)
         : TypeMapping[propertyType]);
 }
コード例 #16
0
 public EnumProperty(string name, FilterPropertyType type, string[] values)
     : base(name, type)
 {
     Values = values;
 }
コード例 #17
0
 internal PointProperty(string name, FilterPropertyType type)
     : base(name, type)
 {
 }