Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Base64Literal.cs
1using System;
4
6{
11 {
16 : base()
17 {
18 }
19
24 public Base64Literal(byte[] Value)
25 : base(Value, Convert.ToBase64String(Value))
26 {
27 }
28
34 public Base64Literal(byte[] Value, string StringValue)
35 : base(Value, StringValue)
36 {
37 }
38
42 public const string TypeUri = XmlSchema.Namespace + "base64Binary";
43
47 public override string StringType => TypeUri;
48
54 public override Grade Supports(Type ValueType)
55 {
56 return ValueType == typeof(byte[]) ? Grade.Ok : Grade.NotAtAll;
57 }
58
64 public override ISemanticLiteral Encapsulate(object Value)
65 {
66 if (Value is byte[] Typed)
67 return new Base64Literal(Typed);
68 else
69 return new StringLiteral(Value?.ToString() ?? string.Empty);
70 }
71
79 public override ISemanticLiteral Parse(string Value, string DataType, string Language)
80 {
81 try
82 {
83 return new Base64Literal(Convert.FromBase64String(Value), Value);
84 }
85 catch (Exception)
86 {
87 return new CustomLiteral(Value, DataType, Language);
88 }
89 }
90
92 public override bool Equals(object obj)
93 {
94 return obj is Base64Literal Typed &&
95 Typed.StringValue == this.StringValue;
96 }
97
99 public override int GetHashCode()
100 {
101 return this.StringValue.GetHashCode();
102 }
103 }
104}
override ISemanticLiteral Parse(string Value, string DataType, string Language)
Tries to parse a string value of the type supported by the class..
Base64Literal(byte[] Value)
Represents a byte[] literal.
override Grade Supports(Type ValueType)
How well the type supports a given value type.
Base64Literal(byte[] Value, string StringValue)
Represents a byte[] literal.
override ISemanticLiteral Encapsulate(object Value)
Encapsulates an object value as a semantic literal value.
const string TypeUri
http://www.w3.org/2001/XMLSchema#base64Binary
Abstract base class for semantic literal values.
string StringValue
String representation of value.
Interface for semantic literals.
Grade
Grade enumeration
Definition: Grade.cs:7