Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
McpFloatingPointParameterAttribute.cs
1using System;
4using Waher.Script;
5
7{
11 [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue |
12 AttributeTargets.Property | AttributeTargets.Field,
13 Inherited = true, AllowMultiple = false)]
15 {
22 : base(Title, Description)
23 {
24 }
25
34 object? MinValue, object? MaxValue)
36 {
37 if (!IsFloatingPointType(MinValue))
38 throw new ArgumentException("MinValue is not a float-point type.", nameof(MinValue));
39
40 if (!IsFloatingPointType(MaxValue))
41 throw new ArgumentException("MaxValue is not a float-point type.", nameof(MaxValue));
42 }
43
44 private static bool IsFloatingPointType(object? Value)
45 {
46 if (Value is null)
47 return true;
48
49 switch (Type.GetTypeCode(Value.GetType()))
50 {
51 case TypeCode.Single:
52 case TypeCode.Double:
53 case TypeCode.Decimal:
54 return true;
55
56 default:
57 return false;
58 }
59 }
60
65 public override void Annotate(Dictionary<string, object?> Schema)
66 {
67 base.Annotate(Schema);
68
69 Schema["type"] = "number";
70 }
71
76 public override void GetHtmlInputAttributes(Dictionary<string, string> Attributes)
77 {
78 base.GetHtmlInputAttributes(Attributes);
79 Attributes["type"] = "number";
80 Attributes["step"] = "any";
81 }
82
88 public override string GetHtmlAttributeValue(object Value)
89 {
90 return Expression.ToExpressionString(Value);
91 }
92 }
93}
override void Annotate(Dictionary< string, object?> Schema)
Annotates a schema object with information in the attribute.
override string GetHtmlAttributeValue(object Value)
Gets the HTML attribute value for a parameter, if any.
McpFloatingPointParameterAttribute(string? Title, string? Description, object? MinValue, object? MaxValue)
Provides meta-data about a floating-point-valued parameter.
McpFloatingPointParameterAttribute(string? Title, string? Description)
Provides meta-data about a floating-point-valued parameter.
override void GetHtmlInputAttributes(Dictionary< string, string > Attributes)
Gets HTML input attributes for the parameter, if any.
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