Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Commit 6c013f5

Browse files
author
Søren Trudsø Mahon
committed
Bind form to a list as a complex property
1 parent 1b32115 commit 6c013f5

File tree

5 files changed

+257
-125
lines changed

5 files changed

+257
-125
lines changed

src/Nancy/Extensions/CollectionExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,20 @@ public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TS
8484
}
8585
}
8686
}
87+
88+
/// <summary>
89+
/// Tries to get value from dictionary
90+
/// </summary>
91+
/// <typeparam name="TKey"></typeparam>
92+
/// <typeparam name="TValue"></typeparam>
93+
/// <param name="source">The <see cref="IDictionary{TKey,TValue}"/> instance to get value from.</param>
94+
/// <param name="key">The key to lookup.</param>
95+
/// <returns></returns>
96+
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key)
97+
{
98+
TValue result;
99+
source.TryGetValue(key, out result);
100+
return result;
101+
}
87102
}
88103
}

src/Nancy/Extensions/TypeExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ public static Assembly GetAssembly(this Type source)
4545
return source.GetTypeInfo().Assembly;
4646
}
4747

48+
/// <summary>
49+
/// Checks if a type is array, collection or enumerable
50+
/// </summary>
51+
/// <param name="source">The type to check.</param>
52+
/// <returns></returns>
53+
public static bool IsCollectionOrArrayOrEnumerable(this Type source)
54+
{
55+
return source.IsArray() || source.IsCollection() || source.IsEnumerable();
56+
}
57+
4858
/// <summary>
4959
/// Checks if a type is an array or not
5060
/// </summary>

0 commit comments

Comments
 (0)