Skip to content

Commit

Permalink
README update + version bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwaliszko committed Apr 24, 2016
1 parent 81c5f24 commit 8ab2a37
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 8 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) <sup>(re server-side)</sup>
- [What if there is no built-in function I need?](#what-if-there-is-no-built-in-function-i-need) <sup>(re client and server-side)</sup>
- [Can I have custom utility-like functions outside of my models?](#can-I-have-custom-utility-like-functions-outside-of-my-models) <sup>(re server-side)</sup>
- [How to cope with values of custom types?](#how-to-cope-with-values-of-custom-types) <sup>(re client-side)</sup>
- [How to cope with dates given in non-standard formats?](#how-to-cope-with-dates-given-in-non-standard-formats) <sup>(re client-side)</sup>
- [What if `ea` variable is already used by another library?](#what-if-ea-variable-is-already-used-by-another-library) <sup>(re client-side)</sup>
Expand Down Expand Up @@ -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.

#####<a id="can-I-have-custom-utility-like-functions-outside-of-my-models">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<int[], int>("ArrayLength", array => array.Length);
```
* define new provider:

```
public class CustomFunctionsProvider : IFunctionsProvider
{
public IDictionary<string, IList<LambdaExpression>> GetFunctions()
{
return new Dictionary<string, IList<LambdaExpression>>
{
{"ArrayLength", new LambdaExpression[] {(Expression<Func<int[], int>>) (array => array.Length)}}
};
}
}

protected void Application_Start()
{
Toolchain.Instance.Recharge(new CustomFunctionsProvider());
```

#####<a id="how-to-cope-with-values-of-custom-types">How to cope with values of custom types?</a>

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:
Expand Down
Binary file modified doc/api/api.chm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
17 changes: 16 additions & 1 deletion src/ExpressiveAnnotations.MvcWebSample/Misc/CustomToolchain.cs
Original file line number Diff line number Diff line change
@@ -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<string, IList<LambdaExpression>> GetFunctions()
// {
// return new Dictionary<string, IList<LambdaExpression>>
// {
// {"ArrayLength", new LambdaExpression[] {(Expression<Func<int[], int>>) (array => array.Length)}},
// {"ArrayContains", new LambdaExpression[] {(Expression<Func<int?, int[], bool>>) ((value, array) => value != null && array.Contains((int)value))}}
// };
// }
//}

public static class CustomToolchain
{
public static void Register()
Expand Down
5 changes: 4 additions & 1 deletion src/ExpressiveAnnotations/FunctionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public void Recharge(IFunctionsProvider provider)
}

/// <summary>
/// Gets registered functions.
/// Gets functions for the <see cref="ExpressiveAnnotations.Analysis.Parser" />.
/// </summary>
/// <returns>
/// Registered functions.
/// </returns>
public IDictionary<string, IList<LambdaExpression>> GetFunctions()
{
return Functions.ToDictionary(x => x.Key, x => x.Value);
Expand Down
5 changes: 4 additions & 1 deletion src/ExpressiveAnnotations/IFunctionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ namespace ExpressiveAnnotations
public interface IFunctionsProvider
{
/// <summary>
/// Gets registered functions.
/// Gets functions for the <see cref="ExpressiveAnnotations.Analysis.Parser" />.
/// </summary>
/// <returns>
/// Registered functions.
/// </returns>
IDictionary<string, IList<LambdaExpression>> GetFunctions();
}
}
4 changes: 2 additions & 2 deletions src/ExpressiveAnnotations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
5 changes: 4 additions & 1 deletion src/ExpressiveAnnotations/Toolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ public void AddFunction<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult>(strin
}

/// <summary>
/// Gets registered functions.
/// Gets functions for the <see cref="ExpressiveAnnotations.Analysis.Parser" />.
/// </summary>
/// <returns>
/// Registered functions.
/// </returns>
public IDictionary<string, IList<LambdaExpression>> GetFunctions()
{
return FuncManager.GetFunctions();
Expand Down

0 comments on commit 8ab2a37

Please sign in to comment.