source: code/Website/dot-net-library/written-by-xiao-yifang/OpenFlashChart/JSON/JsonSpecifiedPropertyAttribute.cs@ 7849

Last change on this file since 7849 was 7849, checked in by dennisw, 15 years ago
File size: 3.0 KB
Line 
1#region License
2/*---------------------------------------------------------------------------------*\
3
4 Distributed under the terms of an MIT-style license:
5
6 The MIT License
7
8 Copyright (c) 2006-2009 Stephen M. McKamey
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27
28\*---------------------------------------------------------------------------------*/
29#endregion License
30
31using System;
32using System.Reflection;
33
34namespace JsonFx.Json
35{
36 /// <summary>
37 /// Specifies the name of the property which specifies if member should be serialized.
38 /// </summary>
39 [AttributeUsage(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple=false)]
40 public class JsonSpecifiedPropertyAttribute : Attribute
41 {
42 #region Fields
43
44 private string specifiedProperty = null;
45
46 #endregion Fields
47
48 #region Init
49
50 /// <summary>
51 /// Ctor
52 /// </summary>
53 /// <param name="propertyName">the name of the property which controls serialization for this member</param>
54 public JsonSpecifiedPropertyAttribute(string propertyName)
55 {
56 this.specifiedProperty = propertyName;
57 }
58
59 #endregion Init
60
61 #region Properties
62
63 /// <summary>
64 /// Gets and sets the name of the property which
65 /// specifies if member should be serialized
66 /// </summary>
67 public string SpecifiedProperty
68 {
69 get { return this.specifiedProperty; }
70 set { this.specifiedProperty = value; }
71 }
72
73 #endregion Properties
74
75 #region Methods
76
77 /// <summary>
78 /// Gets the name specified for use in Json serialization.
79 /// </summary>
80 /// <param name="value"></param>
81 /// <returns></returns>
82 public static string GetJsonSpecifiedProperty(MemberInfo memberInfo)
83 {
84 if (memberInfo == null ||
85 !Attribute.IsDefined(memberInfo, typeof(JsonSpecifiedPropertyAttribute)))
86 {
87 return null;
88 }
89
90 JsonSpecifiedPropertyAttribute attribute = (JsonSpecifiedPropertyAttribute)Attribute.GetCustomAttribute(memberInfo, typeof(JsonSpecifiedPropertyAttribute));
91 return attribute.SpecifiedProperty;
92 }
93
94 #endregion Methods
95 }
96}
Note: See TracBrowser for help on using the repository browser.