Drucken

Logo Bodoconsult EDV-Dienstleistungen GmbH

Bodoconsult.Core.ExpressionBuilder

Autor: Bodoconsult EDV-Dienstleistungen GmbH, Robert Leisner

Nuget package

https://www.nuget.org/packages/Bodoconsult.Core.ExpressionBuilder/

Github repository

https://github.com/RobertLeisner/Bodoconsult.Core.ExpressionBuilder

About the library Bodoconsult.Core.ExpressionBuilder

What does the library

Bodoconsult.Core.ExpressionBuilder is intended to provide enhanced search features on entitiy classes for user interfaces like WinForms, WPF or Xamarin Forms.

Bodoconsult.Core.ExpressionBuilder is based on the work of David Belmont. See licence file and https://github.com/dbelmont/ExpressionBuilder/tree/master/ExpressionBuilder. We did some changes for better fit to our projects.

How to use the library

The source code contains a NUnit test class, the following source code is extracted from. It sample shows the most helpful use cases for the library.

Getting object properties fur building expressions in UI

Not localized properties

This example shows how to get the queryable properties of a class Person. It provides the properties in a non-localized fashion, means the original property names are used.


            var result = ExpressionPropertiesHelper.LoadPropertyCollection<Person>();
            result.LoadProperties(null);

            var properties = result.ToList();
			
Localized properties

The next example shows to to use localized properties. Bodoconsult.Core.ExpressionBuilder uses C### builtin localization features based on ResourceManager.

Create a resx file for the class like with normal builtin C### localization. Here the folder structure for a class Person:

	Resources
		Person.resx
		Person.pt.resx
		Person.de.resx

Then call LoadProperties with adequate ResourceManager:


            var result = ExpressionPropertiesHelper.LoadPropertyCollection<Person>();
            result.LoadProperties(Resources.Person.ResourceManager);

            var properties = result.ToList();

Building and using an expression

The following example shows how to use


        [TestCase(TestName="Build expression from a filter with property chain filter statements")]
        public void BuilderWithPropertyChainFilterStatements()
        {
            var filter = new Filter<Person>();
            filter.By("Birth.Country", Operation.EqualTo, "usa", value2: default, FilterStatementConnector.Or);
            filter.By("Birth.Date", Operation.LessThanOrEqualTo, new DateTime(1980, 1, 1), connector: FilterStatementConnector.Or);
            filter.By("Name", Operation.Contains, "Doe");
            
            var people = People.Where(filter);
            
            var solution = People.Where(p => (p.Birth != null && p.Birth.Country != null && p.Birth.Country.Trim().ToLower().Equals("usa")) ||
                                             (p.Birth != null && p.Birth.Date <= new DateTime(1980, 1, 1)) ||
                                             p.Name.Trim().ToLower().Contains("doe"));
            
            Assert.That(people, Is.EquivalentTo(solution));
        }

User interface integration

The example before shows how to build expressions and use it generally. In practise the expression should be built up from user input from user interface.

For an example please see the included project Bodoconsult.Core.ExpressionBuilder.WinForms for fully fucntional example how to use Bodoconsult.Core.ExpressionBuilder.

About us

Bodoconsult (http://www.bodoconsult.de) is a Munich based software development company.

Robert Leisner is senior software developer at Bodoconsult. See his profile on http://www.bodoconsult.de/Curriculum_vitae_Robert_Leisner.pdf.

Licence for the library Bodoconsult.Core.ExpressionBuilder

The MIT License (MIT)

Copyright (c) Bodoconsult EDV-Dienstleistungen GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Licences for libraries used by Bodoconsult.Core.ExpressionBuilder

ExpressionBuilder by David Belmont

See: (https://github.com/dbelmont/ExpressionBuilder/tree/master/ExpressionBuilder)

Copyright 2017 David Belmont

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at (http://www.apache.org/licenses/LICENSE-2.0) Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

System.ComponentModel.Annotations by Microsoft

Url: (https://www.nuget.org/packages/System.ComponentModel.Annotations)

Licence: (https://licenses.nuget.org/MIT)

MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 

Drucken