-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathChoiceAttribute.cs
More file actions
51 lines (43 loc) · 1.7 KB
/
Copy pathChoiceAttribute.cs
File metadata and controls
51 lines (43 loc) · 1.7 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
using Generator.Extensions;
using Microsoft.Xrm.Sdk.Metadata;
namespace Generator.DTO.Attributes;
public class ChoiceAttribute : Attribute
{
public IEnumerable<Option> Options { get; }
public string Type { get; }
public int? DefaultValue { get; }
public string? GlobalOptionSetName { get; set; }
public ChoiceAttribute(PicklistAttributeMetadata metadata) : base(metadata)
{
Options = metadata.OptionSet.Options.Select(x => new Option(
x.Label.ToLabelString(),
x.Value,
x.Color,
x.Description.ToLabelString().PrettyDescription()));
Type = "Single";
DefaultValue = metadata.DefaultFormValue;
GlobalOptionSetName = metadata.OptionSet.IsGlobal == true ? metadata.OptionSet.Name : null;
}
public ChoiceAttribute(StateAttributeMetadata metadata) : base(metadata)
{
Options = metadata.OptionSet.Options.Select(x => new Option(
x.Label.ToLabelString(),
x.Value,
x.Color,
x.Description.ToLabelString().PrettyDescription()));
Type = "Single";
DefaultValue = metadata.DefaultFormValue;
GlobalOptionSetName = null; // State attributes are always local
}
public ChoiceAttribute(MultiSelectPicklistAttributeMetadata metadata) : base(metadata)
{
Options = metadata.OptionSet.Options.Select(x => new Option(
x.Label.ToLabelString(),
x.Value,
x.Color,
x.Description.ToLabelString().PrettyDescription()));
Type = "Multi";
DefaultValue = metadata.DefaultFormValue;
GlobalOptionSetName = metadata.OptionSet.IsGlobal == true ? metadata.OptionSet.Name : null;
}
}