-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTypeHelper.cs
More file actions
42 lines (36 loc) · 1.65 KB
/
Copy pathTypeHelper.cs
File metadata and controls
42 lines (36 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Episerver.Labs.Cognitive.Attributes;
using EPiServer.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Episerver.Labs.Cognitive
{
public static class TypeHelper
{
public static IEnumerable<PropertyInfo> PropertiesWithVisionAttributes(this Type t)
{
return t.GetProperties().Where(prop =>
Attribute.IsDefined(prop, typeof(SmartThumbnailAttribute), true) ||
Attribute.IsDefined(prop, typeof(VisionAttribute), true));
}
public static IEnumerable<PropertyInfo> GetPropertiesWithAttribute(this IContent c, Type a)
{
return c.GetType().GetProperties().Where(prop => Attribute.IsDefined(prop, a, true));
}
public static IEnumerable<PropertyInfo> GetEmptyPropertiesWithAttribute(this IContent c, Type a)
{
return c.GetType().GetProperties().Where(prop => Attribute.IsDefined(prop, a, true)).Where(prop => prop.GetValue(c)==null);
}
public static IEnumerable<SmartThumbnailAttribute> GetThumbnailAttributes(this IContent c)
{
return c.GetType().PropertiesWithVisionAttributes().SelectMany(pi => pi.GetCustomAttributes(true)).Where(ca => ca is SmartThumbnailAttribute).Cast<SmartThumbnailAttribute>();
}
public static IEnumerable<VisionAttribute> GetVisionAttributes(this IContent c)
{
return c.GetType().PropertiesWithVisionAttributes().SelectMany(pi => pi.GetCustomAttributes(true)).Where(ca => ca is VisionAttribute).Cast<VisionAttribute>();
}
}
}