Fauna .NET Driver 0.1.0-beta
 
Loading...
Searching...
No Matches
FieldInfo.cs
Go to the documentation of this file.
3using System.Reflection;
4
5namespace Fauna.Mapping;
6
7public sealed class FieldInfo
8{
9 public string Name { get; }
10 public PropertyInfo Property { get; }
11 public FaunaType? FaunaTypeHint { get; }
12 public Type Type { get; }
13 public bool IsNullable { get; }
14
15 private MappingContext _ctx;
16 private IDeserializer? _deserializer;
17
18 internal FieldInfo(MappingContext ctx, FieldAttribute attr, PropertyInfo prop)
19 {
20 var nullCtx = new NullabilityInfoContext();
21 var nullInfo = nullCtx.Create(prop);
22
23 Name = attr.Name ?? FieldName.Canonical(prop.Name);
24 FaunaTypeHint = attr.Type;
25 Property = prop;
26 Type = prop.PropertyType;
27 IsNullable = nullInfo.WriteState is NullabilityState.Nullable;
28 _ctx = ctx;
29 }
30
31 internal IDeserializer Deserializer
32 {
33 get
34 {
35 lock (_ctx)
36 {
37 if (_deserializer is null)
38 {
39 _deserializer = Fauna.Serialization.Deserializer.Generate(_ctx, Type);
40 if (IsNullable)
41 {
42 var deserType = typeof(NullableDeserializer<>).MakeGenericType(new[] { Type });
43 var deser = Activator.CreateInstance(deserType, new[] { _deserializer });
44 _deserializer = (IDeserializer)deser!;
45 }
46 }
47
48 return _deserializer;
49 }
50 }
51 }
52}
Attribute used to specify properties of a field in a Fauna object.
Definition Attributes.cs:30
FaunaType? FaunaTypeHint
Definition FieldInfo.cs:11
PropertyInfo Property
Definition FieldInfo.cs:10
FaunaType
Enumerates the different types of data that can be stored in Fauna.
Definition Attributes.cs:7
@ FieldName
The token type is a Fauna property name.
Definition Client.cs:9