Repository navigation
Expand file tree
/
Copy pathApiAllowableValuesAttribute.cs
More file actions
69 lines (59 loc) · 1.85 KB
/
Copy pathApiAllowableValuesAttribute.cs
File metadata and controls
69 lines (59 loc) · 1.85 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//Copyright (c) Service Stack LLC. All Rights Reserved.
//License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
using System;
using System.Reflection;
namespace ServiceStack
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class ApiAllowableValuesAttribute : AttributeBase
{
public ApiAllowableValuesAttribute(string name)
{
this.Name = name;
}
public ApiAllowableValuesAttribute(string name, int min, int max) : this(name)
{
Type = "RANGE";
Min = min;
Max = max;
}
public ApiAllowableValuesAttribute(string name, params string[] values)
: this(name)
{
Type = "LIST";
Values = values;
}
public ApiAllowableValuesAttribute(string name, Type enumType)
: this(name)
{
#if NETFX_CORE
if (enumType.GetTypeInfo().IsEnum)
#else
if (enumType.IsEnum)
#endif
{
Type = "LIST";
Values = System.Enum.GetNames(enumType);
}
}
public ApiAllowableValuesAttribute(string name, Func<string[]> listAction)
: this(name)
{
if (listAction != null)
{
Type = "LIST";
Values = listAction();
}
}
/// <summary>
/// Gets or sets parameter name with which allowable values will be associated.
/// </summary>
public string Name { get; set; }
public string Type { get; set; }
public int? Min { get; set; }
public int? Max { get; set; }
public String[] Values { get; set; }
//TODO: should be implemented according to:
//https://github.com/wordnik/swagger-core/wiki/datatypes
}
}