Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Services / IJSONSerializer.cs
blobfc2e763be8d78ea505da614c7710d3eb5180f333
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Services
17 using System;
18 using System.IO;
20 /// <summary>
21 /// Abstracts the underlying JSON writer
22 /// </summary>
23 public interface IJSONWriter
25 /// <summary>
26 /// Writes the start object.
27 /// </summary>
28 void WriteStartObject();
29 /// <summary>
30 /// Writes the end object.
31 /// </summary>
32 void WriteEndObject();
33 /// <summary>
34 /// Writes the start array.
35 /// </summary>
36 void WriteStartArray();
37 /// <summary>
38 /// Writes the end array.
39 /// </summary>
40 void WriteEndArray();
41 /// <summary>
42 /// Writes the name of the property.
43 /// </summary>
44 /// <param name="name">The name.</param>
45 void WritePropertyName(string name);
46 /// <summary>
47 /// Writes the end.
48 /// </summary>
49 void WriteEnd();
50 /// <summary>
51 /// Writes the null.
52 /// </summary>
53 void WriteNull();
54 /// <summary>
55 /// Writes the undefined.
56 /// </summary>
57 void WriteUndefined();
58 /// <summary>
59 /// Writes the raw.
60 /// </summary>
61 /// <param name="javaScript">The java script.</param>
62 void WriteRaw(string javaScript);
63 /// <summary>
64 /// Writes the value.
65 /// </summary>
66 /// <param name="value">The value.</param>
67 void WriteValue(object value);
68 /// <summary>
69 /// Writes the value.
70 /// </summary>
71 /// <param name="value">The value.</param>
72 void WriteValue(string value);
73 /// <summary>
74 /// Writes the value.
75 /// </summary>
76 /// <param name="value">The value.</param>
77 void WriteValue(int value);
78 /// <summary>
79 /// Writes the value.
80 /// </summary>
81 /// <param name="value">The value.</param>
82 void WriteValue(long value);
83 /// <summary>
84 /// Writes the value.
85 /// </summary>
86 /// <param name="value">The value.</param>
87 void WriteValue(float value);
88 /// <summary>
89 /// Writes the value.
90 /// </summary>
91 /// <param name="value">if set to <c>true</c> [value].</param>
92 void WriteValue(bool value);
93 /// <summary>
94 /// Writes the value.
95 /// </summary>
96 /// <param name="value">The value.</param>
97 void WriteValue(short value);
98 /// <summary>
99 /// Writes the value.
100 /// </summary>
101 /// <param name="value">The value.</param>
102 void WriteValue(decimal value);
104 /// <summary>
105 /// Writes the value.
106 /// </summary>
107 /// <param name="value">The value.</param>
108 void WriteValue(DateTime value);
111 /// <summary>
112 /// Pendent
113 /// </summary>
114 public interface IJSONConverter
116 /// <summary>
117 /// Writes the specified value using the writer.
118 /// </summary>
119 /// <param name="writer">The writer.</param>
120 /// <param name="value">The value.</param>
121 void Write(IJSONWriter writer, object value);
123 /// <summary>
124 /// Determines whether this instance can handle the specified type.
125 /// </summary>
126 /// <param name="type">The type.</param>
127 /// <returns>
128 /// <c>true</c> if this instance can handle the specified type; otherwise, <c>false</c>.
129 /// </returns>
130 bool CanHandle(Type type);
132 #if DOTNET35
133 /// <summary>
134 /// Converts the JSON read by the supplied reader into an instance of the requested type.
135 /// </summary>
136 /// <param name="reader">The reader.</param>
137 /// <param name="objectType">The type.</param>
138 /// <returns></returns>
139 object ReadJson(IJSONReader reader, Type objectType);
140 #endif
143 /// <summary>
144 /// Pendent
145 /// </summary>
146 public interface IJSONSerializer
148 /// <summary>
149 /// Serializes the specified object.
150 /// </summary>
151 /// <param name="target">The object.</param>
152 /// <returns></returns>
153 string Serialize(object target);
155 /// <summary>
156 /// Serializes the specified object.
157 /// </summary>
158 /// <param name="target">The object.</param>
159 /// <param name="converters">The converters.</param>
160 /// <returns></returns>
161 string Serialize(object target, params IJSONConverter[] converters);
163 /// <summary>
164 /// Serializes the specified object.
165 /// </summary>
166 /// <param name="target">The target.</param>
167 /// <param name="writer">The writer.</param>
168 /// <param name="converters">The converters.</param>
169 void Serialize(object target, TextWriter writer, params IJSONConverter[] converters);
171 /// <summary>
172 /// Deserializes the specified object.
173 /// </summary>
174 /// <param name="jsonString">The json representation of an object string.</param>
175 /// <param name="expectedType">The expected type.</param>
176 /// <returns></returns>
177 object Deserialize(string jsonString, Type expectedType);
179 /// <summary>
180 /// Deserializes the specified object.
181 /// </summary>
182 /// <param name="jsonString">The json representation of an object string.</param>
183 /// <returns></returns>
184 T Deserialize<T>(string jsonString);
186 /// <summary>
187 /// Deserializes the specified object.
188 /// </summary>
189 /// <param name="jsonString">The json representation of an object string.</param>
190 /// <returns></returns>
191 T[] DeserializeArray<T>(string jsonString);
194 #if DOTNET35
195 /// <summary>
196 /// Represents a reader that provides fast, non-cached, forward-only access to serialized Json data.
197 /// </summary>
198 public interface IJSONReader
200 /// <summary>
201 /// Gets the quotation mark character used to enclose the value of a string.
202 /// </summary>
203 char QuoteChar { get; }
205 /// <summary>
206 /// Gets the text value of the current Json token.
207 /// </summary>
208 object Value { get; }
210 /// <summary>
211 /// Gets The Common Language Runtime (CLR) type for the current Json token.
212 /// </summary>
213 Type ValueType { get; }
215 /// <summary>
216 /// Pending.
217 /// </summary>
218 int Depth { get; }
220 /// <summary>
221 /// Reads the next Json token from the stream.
222 /// </summary>
223 /// <returns></returns>
224 bool Read();
226 /// <summary>
227 /// Pending.
228 /// </summary>
229 void Skip();
231 /// <summary>
232 /// Changes the <see cref="Newtonsoft.Json.JsonReader.State"/> to Closed.
233 /// </summary>
234 void Close();
236 #endif