Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
Add feature of generate array from IEnumerable<> to Client.AngularJS.T4
Browse files Browse the repository at this point in the history
  • Loading branch information
KatsuYuzu committed Feb 18, 2016
1 parent 09d7d84 commit cc380cf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Source/LightNode.Client.AngularJS.T4/light-node-client.tt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
: "any";
};

Func<Type, bool> IsEnumerableType = (Type t) =>
{
return t != typeof(string)
&& ((t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>))
|| t.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable<>)));
};

Func<Type, string> BeautifyType = null;
BeautifyType = (Type t) =>
{
Expand All @@ -72,7 +79,7 @@

if (t.GetGenericTypeDefinition() == typeof(Nullable<>)) return BeautifyType(t.GetGenericArguments()[0]);

if (t.GetGenericTypeDefinition() == typeof(IEnumerable<>)) return BeautifyType(t.GetGenericArguments()[0]) + "[]";
if (IsEnumerableType(t)) return BeautifyType(t.GetGenericArguments()[0]) + "[]";

var innerFormat = string.Join(", ", t.GetGenericArguments().Select(x => BeautifyType(x)));
return Regex.Replace(t.GetGenericTypeDefinition().Name, @"`.+$", "") + "<" + innerFormat + ">";
Expand All @@ -86,12 +93,7 @@
Func<Type, Type> UnWrapEnumerableOrSelf = (Type t) =>
{
return t.IsArray ? t.GetElementType()
: t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>) ? t.GetGenericArguments()[0] : t;
};

Func<Type, bool> IsEnumerableType = (Type t) =>
{
return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>);
: t.IsGenericType && IsEnumerableType(t) ? t.GetGenericArguments()[0] : t;
};

Func<Type, bool> IsComplexType = (Type t) =>
Expand Down

0 comments on commit cc380cf

Please sign in to comment.