Fauna v10 .NET/C# Driver 1.0.1
 
Loading...
Searching...
No Matches
MappingInfo.cs
Go to the documentation of this file.
1using System.Collections.Immutable;
2using System.Reflection;
5
6namespace Fauna.Mapping;
7
11public sealed class MappingInfo
12{
16 public Type Type { get; }
20 public IReadOnlyList<FieldInfo> Fields { get; }
24 public IReadOnlyDictionary<string, FieldInfo> FieldsByName { get; }
25
26 internal bool ShouldEscapeObject { get; }
27 internal ISerializer ClassSerializer { get; }
28 internal Module? Collection { get; }
29
30 internal MappingInfo(MappingContext ctx, Type ty, string? colName = null)
31 {
32 ctx.Add(ty, this);
33 Type = ty;
34 Collection = colName != null ? new Module(colName) : null;
35
36 var fields = new List<FieldInfo>();
37 var byName = new Dictionary<string, FieldInfo>();
38
39 foreach (var prop in ty.GetProperties())
40 {
41 if (prop.GetCustomAttribute<IgnoreAttribute>() != null) continue;
42
43 var attr = prop.GetCustomAttribute<BaseFieldAttribute>() ?? new FieldAttribute();
44 var info = new FieldInfo(ctx, attr, prop);
45
46 if (byName.ContainsKey(info.Name))
47 throw new ArgumentException($"Duplicate field name {info.Name} in {ty}");
48
49 fields.Add(info);
50 byName[info.Name] = info;
51 }
52
53 ShouldEscapeObject = Serializer.Tags.Overlaps(byName.Values.Select(i => i.Name));
54 Fields = fields.ToImmutableList();
55 FieldsByName = byName.ToImmutableDictionary();
56
57 var serType = typeof(ClassSerializer<>).MakeGenericType(new[] { ty });
58 ClassSerializer = (ISerializer)Activator.CreateInstance(serType, this)!;
59 }
60}
System.ArgumentException ArgumentException
Fauna.Types.Module Module
Definition MappingInfo.cs:4
A class that encapsulates the class mapping, serialization, and deserialization of a Fauna object,...
Type Type
The associated type.
IReadOnlyList< FieldInfo > Fields
A read-only list of FieldInfo representing the object.
IReadOnlyDictionary< string, FieldInfo > FieldsByName
A read-only dictionary of FieldInfo representing the object.
Represents a module, a singleton object grouping related functionalities. Modules are serialized as @...
Definition Module.cs:8
A generic interface that defines serialize and deserialize behavior for a specific type,...