-
Notifications
You must be signed in to change notification settings - Fork 256
/
CosmosLinqSerializer.xml
130 lines (119 loc) · 6.47 KB
/
CosmosLinqSerializer.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<Type Name="CosmosLinqSerializer" FullName="Microsoft.Azure.Cosmos.CosmosLinqSerializer">
<TypeSignature Language="C#" Value="public abstract class CosmosLinqSerializer : Microsoft.Azure.Cosmos.CosmosSerializer" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit CosmosLinqSerializer extends Microsoft.Azure.Cosmos.CosmosSerializer" />
<TypeSignature Language="DocId" Value="T:Microsoft.Azure.Cosmos.CosmosLinqSerializer" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class CosmosLinqSerializer
Inherits CosmosSerializer" />
<TypeSignature Language="F#" Value="type CosmosLinqSerializer = class
 inherit CosmosSerializer" />
<AssemblyInfo>
<AssemblyName>Microsoft.Azure.Cosmos.Client</AssemblyName>
<AssemblyVersion>3.39.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>Microsoft.Azure.Cosmos.CosmosSerializer</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>
This abstract class can be implemented to allow a custom serializer (Non [Json.NET serializer](https://www.newtonsoft.com/json/help/html/Introduction.htm)'s)
to be used by the CosmosClient for LINQ queries.
</summary>
<remarks>To be added.</remarks>
<example>
This example implements the CosmosLinqSerializer contract.
This example custom serializer will honor System.Text.Json attributes.
<code language="c#"><![CDATA[
class SystemTextJsonSerializer : CosmosLinqSerializer
{
private readonly JsonObjectSerializer systemTextJsonSerializer;
public SystemTextJsonSerializer(JsonSerializerOptions jsonSerializerOptions)
{
this.systemTextJsonSerializer = new JsonObjectSerializer(jsonSerializerOptions);
}
public override T FromStream<T>(Stream stream)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
using (stream)
{
if (stream.CanSeek && stream.Length == 0)
{
return default;
}
if (typeof(Stream).IsAssignableFrom(typeof(T)))
{
return (T)(object)stream;
}
return (T)this.systemTextJsonSerializer.Deserialize(stream, typeof(T), default);
}
}
public override Stream ToStream<T>(T input)
{
MemoryStream streamPayload = new MemoryStream();
this.systemTextJsonSerializer.Serialize(streamPayload, input, input.GetType(), default);
streamPayload.Position = 0;
return streamPayload;
}
public override string SerializeMemberName(MemberInfo memberInfo)
{
System.Text.Json.Serialization.JsonExtensionDataAttribute jsonExtensionDataAttribute =
memberInfo.GetCustomAttribute<System.Text.Json.Serialization.JsonExtensionDataAttribute>(true);
if (jsonExtensionDataAttribute != null)
{
return null;
}
JsonPropertyNameAttribute jsonPropertyNameAttribute = memberInfo.GetCustomAttribute<JsonPropertyNameAttribute>(true);
string memberName = !string.IsNullOrEmpty(jsonPropertyNameAttribute?.Name)
? jsonPropertyNameAttribute.Name
: memberInfo.Name;
// Users must add handling for any additional attributes here
return memberName;
}
}
]]></code></example>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected CosmosLinqSerializer ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Azure.Cosmos.CosmosLinqSerializer.#ctor" />
<MemberSignature Language="VB.NET" Value="Protected Sub New ()" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Azure.Cosmos.Client</AssemblyName>
<AssemblyVersion>3.39.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="SerializeMemberName">
<MemberSignature Language="C#" Value="public abstract string SerializeMemberName (System.Reflection.MemberInfo memberInfo);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance string SerializeMemberName(class System.Reflection.MemberInfo memberInfo) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Azure.Cosmos.CosmosLinqSerializer.SerializeMemberName(System.Reflection.MemberInfo)" />
<MemberSignature Language="VB.NET" Value="Public MustOverride Function SerializeMemberName (memberInfo As MemberInfo) As String" />
<MemberSignature Language="F#" Value="abstract member SerializeMemberName : System.Reflection.MemberInfo -> string" Usage="cosmosLinqSerializer.SerializeMemberName memberInfo" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Azure.Cosmos.Client</AssemblyName>
<AssemblyVersion>3.39.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="memberInfo" Type="System.Reflection.MemberInfo" />
</Parameters>
<Docs>
<param name="memberInfo">Any MemberInfo used in the query.</param>
<summary>
Convert a MemberInfo to a string for use in LINQ query translation.
This must be implemented when using a custom serializer for LINQ queries.
</summary>
<returns>A serialized representation of the member.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>