Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathSample06_CustomAttributes.cs
More file actions
Latest commit
82 lines (70 loc) · 2.93 KB
/
Copy pathSample06_CustomAttributes.cs
File metadata and controls
82 lines (70 loc) · 2.93 KB
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
#region -- License Terms --
//
// MessagePack for CLI
//
// Copyright (C) 2010-2012 FUJIWARA, Yusuke
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion -- License Terms --
usingSystem;
usingSystem.IO;
usingSystem.Runtime.Serialization;
usingMsgPack.Serialization;
namespaceSamples
{
/// <summary>
/// Sample code to describe MessagePackMember usage.
/// </summary>
/// <remarks>You can tweak serialization behavior via custom attributes.</remarks>
publicclassMessagePackMemberSample
{
[MessagePackMember(
0,// Specify 0 based index for serialized array. You should specify this value to ensure interoperability with other platform bindings.
NilImplication=NilImplication.MemberDefault// Specify the behavior when unpacked value is nil -- default is Null for reference types (set null), Prohibit for value types (throw exception).
)]
publiclongFileId{get;set;}
[MessagePackMember(1)]// NilImplication = Null
publicstringName{get;set;}
[MessagePackMember(2)]// NilImplication = Prohibit
[MessagePackEnumMember(SerializationMethod=EnumMemberSerializationMethod.ByUnderlyingValue)]// Specify enum serialization method for this member. This value overrides the setting of the context and the setting of the enum type itself.
publicFileAttributesAttributes{get;set;}
// When there are marked members, non-marked members are excluded from serialization/deserialization candidates.
publicintPropertyWillNotBeSerialized{get;set;}
}
// ... Or you can use DataMemberAttribute for compabitility among other libraries.
publicclassDataContractSample
{
[DataMember(Name="Id",Order=1)]// Order can be used to interop too.
publiclongId{get;set;}
[DataMember(Name="Title",Order=2)]
publicstringTitle{get;set;}
}
// ... You can "opt-out" with MessagePackIgnore
publicclassOptOutSample
{
[MessagePackIgnore]
publicstringShouldNotEmit{get;set;}
publicintShouldEmit{get;set;}
}
}
namespaceSystem.Runtime.Serialization
{
// Tips: You don't have to refer System.Runtime.Serialization assembly. MessagePack for CLI just see Type.FullName.
publicsealedclassDataMemberAttribute:Attribute
{
publicstringName{get;set;}
publicintOrder{get;set;}
}
// This is also about MessagePackIgnoreAttribute, MessagePackMemberAttribute, and MessagePackDeserializationConstructorAttribute.
}