diff --git a/README.md b/README.md index 9c33401..6508a60 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ A small .NET and JavaScript library which provides annotation-based conditional - [Frequently asked questions](#frequently-asked-questions) - [Is it possible to compile all usages of annotations at once?](#is-it-possible-to-compile-all-usages-of-annotations-at-once) (re server-side) - [What if there is no built-in function I need?](#what-if-there-is-no-built-in-function-i-need) (re client and server-side) + - [Can I have custom utility-like functions outside of my models?](#can-I-have-custom-utility-like-functions-outside-of-my-models) (re server-side) - [How to cope with values of custom types?](#how-to-cope-with-values-of-custom-types) (re client-side) - [How to cope with dates given in non-standard formats?](#how-to-cope-with-dates-given-in-non-standard-formats) (re client-side) - [What if `ea` variable is already used by another library?](#what-if-ea-variable-is-already-used-by-another-library) (re client-side) @@ -540,6 +541,36 @@ class Model ``` Many signatures can be defined for a single function name. Types are not taken under consideration as a differentiating factor though. Methods overloading is based on the number of arguments only. Functions with the same name and exact number of arguments are considered as ambiguous. The next issue important here is the fact that custom methods take precedence over built-in ones. If exact signatures are provided built-in methods are simply overridden by new definitions. +#####Can I have custom utility-like functions outside of my models? + +Sure, provide your own methods provider, or extend existing global one, i.e. + +* extend existing provider: + + ``` + protected void Application_Start() + { + Toolchain.Instance.AddFunction("ArrayLength", array => array.Length); +``` +* define new provider: + + ``` + public class CustomFunctionsProvider : IFunctionsProvider + { + public IDictionary> GetFunctions() + { + return new Dictionary> + { + {"ArrayLength", new LambdaExpression[] {(Expression>) (array => array.Length)}} + }; + } + } + + protected void Application_Start() + { + Toolchain.Instance.Recharge(new CustomFunctionsProvider()); +``` + #####How to cope with values of custom types? If you need to handle value string extracted from DOM field in any non built-in way, you can redefine given type-detection logic. The default mechanism recognizes and handles automatically types identified as: `timespan`, `datetime`, `numeric`, `string`, `bool` and `guid`. If non of them is matched for a particular field, JSON deserialization is invoked. You can provide your own deserializers though. The process is as follows: diff --git a/doc/api/api.chm b/doc/api/api.chm index ce352a3..1886711 100644 Binary files a/doc/api/api.chm and b/doc/api/api.chm differ diff --git a/src/ExpressiveAnnotations.MvcUnobtrusive/Properties/AssemblyInfo.cs b/src/ExpressiveAnnotations.MvcUnobtrusive/Properties/AssemblyInfo.cs index e79ebe9..385add6 100644 --- a/src/ExpressiveAnnotations.MvcUnobtrusive/Properties/AssemblyInfo.cs +++ b/src/ExpressiveAnnotations.MvcUnobtrusive/Properties/AssemblyInfo.cs @@ -37,5 +37,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.4.6.0")] -[assembly: AssemblyFileVersion("2.4.6.0")] +[assembly: AssemblyVersion("2.4.7.0")] +[assembly: AssemblyFileVersion("2.4.7.0")] diff --git a/src/ExpressiveAnnotations.MvcWebSample/Misc/CustomToolchain.cs b/src/ExpressiveAnnotations.MvcWebSample/Misc/CustomToolchain.cs index df3280b..669c14f 100644 --- a/src/ExpressiveAnnotations.MvcWebSample/Misc/CustomToolchain.cs +++ b/src/ExpressiveAnnotations.MvcWebSample/Misc/CustomToolchain.cs @@ -1,7 +1,22 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; namespace ExpressiveAnnotations.MvcWebSample.Misc { + //public class CustomFunctionsProvider : IFunctionsProvider + //{ + // public IDictionary> GetFunctions() + // { + // return new Dictionary> + // { + // {"ArrayLength", new LambdaExpression[] {(Expression>) (array => array.Length)}}, + // {"ArrayContains", new LambdaExpression[] {(Expression>) ((value, array) => value != null && array.Contains((int)value))}} + // }; + // } + //} + public static class CustomToolchain { public static void Register() diff --git a/src/ExpressiveAnnotations/FunctionsManager.cs b/src/ExpressiveAnnotations/FunctionsManager.cs index 53d4ed9..872a2ae 100644 --- a/src/ExpressiveAnnotations/FunctionsManager.cs +++ b/src/ExpressiveAnnotations/FunctionsManager.cs @@ -40,8 +40,11 @@ public void Recharge(IFunctionsProvider provider) } /// - /// Gets registered functions. + /// Gets functions for the . /// + /// + /// Registered functions. + /// public IDictionary> GetFunctions() { return Functions.ToDictionary(x => x.Key, x => x.Value); diff --git a/src/ExpressiveAnnotations/IFunctionsProvider.cs b/src/ExpressiveAnnotations/IFunctionsProvider.cs index 13bd74c..56764e6 100644 --- a/src/ExpressiveAnnotations/IFunctionsProvider.cs +++ b/src/ExpressiveAnnotations/IFunctionsProvider.cs @@ -13,8 +13,11 @@ namespace ExpressiveAnnotations public interface IFunctionsProvider { /// - /// Gets registered functions. + /// Gets functions for the . /// + /// + /// Registered functions. + /// IDictionary> GetFunctions(); } } diff --git a/src/ExpressiveAnnotations/Properties/AssemblyInfo.cs b/src/ExpressiveAnnotations/Properties/AssemblyInfo.cs index 7588c60..c1e641d 100644 --- a/src/ExpressiveAnnotations/Properties/AssemblyInfo.cs +++ b/src/ExpressiveAnnotations/Properties/AssemblyInfo.cs @@ -42,5 +42,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.4.0.0")] -[assembly: AssemblyFileVersion("2.4.0.0")] +[assembly: AssemblyVersion("2.4.1.0")] +[assembly: AssemblyFileVersion("2.4.1.0")] diff --git a/src/ExpressiveAnnotations/Toolchain.cs b/src/ExpressiveAnnotations/Toolchain.cs index 8f3a804..3ce80e0 100644 --- a/src/ExpressiveAnnotations/Toolchain.cs +++ b/src/ExpressiveAnnotations/Toolchain.cs @@ -185,8 +185,11 @@ public void AddFunction(strin } /// - /// Gets registered functions. + /// Gets functions for the . /// + /// + /// Registered functions. + /// public IDictionary> GetFunctions() { return FuncManager.GetFunctions();