Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
McpIntegerParameterAttribute.cs
1using System;
3using Waher.Script;
4
6{
10 [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue |
11 AttributeTargets.Property | AttributeTargets.Field,
12 Inherited = true, AllowMultiple = false)]
14 {
21 : base(Title, Description)
22 {
23 }
24
33 object? MinValue, object? MaxValue)
35 {
36 if (!IsIntegerType(MinValue))
37 throw new ArgumentException("MinValue is not an integer type.", nameof(MinValue));
38
39 if (!IsIntegerType(MaxValue))
40 throw new ArgumentException("MaxValue is not an integer type.", nameof(MaxValue));
41 }
42
43 private static bool IsIntegerType(object? Value)
44 {
45 if (Value is null)
46 return true;
47
48 switch (Type.GetTypeCode(Value.GetType()))
49 {
50 case TypeCode.SByte:
51 case TypeCode.Byte:
52 case TypeCode.Int16:
53 case TypeCode.UInt16:
54 case TypeCode.Int32:
55 case TypeCode.UInt32:
56 case TypeCode.Int64:
57 case TypeCode.UInt64:
58 return true;
59
60 default:
61 return false;
62 }
63 }
64
69 public override void Annotate(Dictionary<string, object?> Schema)
70 {
71 base.Annotate(Schema);
72
73 Schema["type"] = "integer";
74 }
75
80 public override void GetHtmlInputAttributes(Dictionary<string, string> Attributes)
81 {
82 base.GetHtmlInputAttributes(Attributes);
83
84 if (this.MinValue is null || this.MaxValue is null)
85 Attributes["type"] = "number";
86 else
87 Attributes["type"] = "range";
88
89 Attributes["step"] = "1";
90 }
91
97 public override string GetHtmlAttributeValue(object Value)
98 {
99 return Expression.ToExpressionString(Value);
100 }
101 }
102}
McpIntegerParameterAttribute(string? Title, string? Description)
Provides meta-data about an integer-valued parameter.
override void GetHtmlInputAttributes(Dictionary< string, string > Attributes)
Gets HTML input attributes for the parameter, if any.
override string GetHtmlAttributeValue(object Value)
Gets the HTML attribute value for a parameter, if any.
override void Annotate(Dictionary< string, object?> Schema)
Annotates a schema object with information in the attribute.
McpIntegerParameterAttribute(string? Title, string? Description, object? MinValue, object? MaxValue)
Provides meta-data about a integer-valued parameter.
Abstract base class for MCP-parameters that have a range of valid values.
Class managing a script expression.
Definition: Expression.cs:41
static string ToExpressionString(object Value)
Converts an object to a string, that can be parsed as part of an expression.
Definition: Expression.cs:5052