main
1<?xml version="1.0" encoding="utf-8"?>
2<xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="xsl msxsl"
5>
6 <xsl:import href="common.xslt"/>
7 <xsl:param name="help"/>
8 <xsl:param name="xml"/>
9 <xsl:param name="datacontract"/>
10 <xsl:param name="binary"/>
11 <xsl:param name="protoRpc"/>
12 <xsl:param name="observable"/>
13 <xsl:param name="preObservable"/>
14 <xsl:param name="partialMethods"/>
15 <xsl:param name="detectMissing"/>
16 <xsl:param name="lightFramework"/>
17 <xsl:param name="asynchronous"/>
18 <xsl:param name="clientProxy"/>
19 <xsl:param name="defaultNamespace"/>
20
21
22 <xsl:key name="fieldNames" match="//FieldDescriptorProto" use="name"/>
23
24 <xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
25 <xsl:variable name="types" select="//EnumDescriptorProto | //DescriptorProto"/>
26 <xsl:variable name="optionXml" select="$xml='true'"/>
27 <xsl:variable name="optionDataContract" select="$datacontract='true'"/>
28 <xsl:variable name="optionBinary" select="$binary='true'"/>
29 <xsl:variable name="optionProtoRpc" select="$protoRpc='true'"/>
30 <xsl:variable name="optionObservable" select="$observable='true'"/>
31 <xsl:variable name="optionPreObservable" select="$preObservable='true'"/>
32 <xsl:variable name="optionPartialMethods" select="$partialMethods='true'"/>
33 <xsl:variable name="optionDetectMissing" select="$detectMissing='true'"/>
34 <xsl:variable name="optionFullFramework" select="not($lightFramework='true')"/>
35 <xsl:variable name="optionAsynchronous" select="$asynchronous='true'"/>
36 <xsl:variable name="optionClientProxy" select="$clientProxy='true'"/>
37 <xsl:variable name="optionFixCase" select="$fixCase='true'"/>
38
39 <xsl:template match="FileDescriptorSet">
40 <xsl:if test="$help='true'">
41 <xsl:message terminate="yes">
42 VisualBasic template for protobuf-net.
43 Options:
44 General:
45 "help" - this page
46 Additional serializer support:
47 "xml" - enable explicit xml support (XmlSerializer)
48 "datacontract" - enable data-contract support (DataContractSerializer; requires .NET 3.0)
49 "binary" - enable binary support (BinaryFormatter; not supported on Silverlight)
50 Other:
51 "protoRpc" - enable proto-rpc client
52 "observable" - change notification (observer pattern) support
53 "preObservable" - pre-change notification (observer pattern) support (requires .NET 3.5)
54 "partialMethods" - provide partial methods for changes (requires C# 3.0)
55 "detectMissing" - provide *Specified properties to indicate whether fields are present
56 "lightFramework" - omit additional attributes not included in CF/Silverlight
57 "asynchronous" - emit asynchronous methods for use with WCF
58 "clientProxy" - emit asynchronous client proxy class
59 </xsl:message>
60 </xsl:if>
61
62 <xsl:if test="$optionXml and $optionDataContract">
63 <xsl:message terminate="yes">
64 Invalid options: xml and data-contract serialization are mutually exclusive.
65 </xsl:message>
66 </xsl:if>
67 ' Generated from <xsl:value-of select="name"/>
68 <xsl:if test="$optionXml">
69 ' Option: xml serialization ([XmlType]/[XmlElement]) enabled
70 </xsl:if><xsl:if test="$optionDataContract">
71 ' Option: data-contract serialization ([DataContract]/[DataMember]) enabled
72 </xsl:if><xsl:if test="$optionBinary">
73 ' Option: binary serialization (ISerializable) enabled
74 </xsl:if><xsl:if test="$optionObservable">
75 ' Option: observable (OnPropertyChanged) enabled
76 </xsl:if><xsl:if test="$optionPreObservable">
77 ' Option: pre-observable (OnPropertyChanging) enabled
78 </xsl:if><xsl:if test="$partialMethods">
79 ' Option: partial methods (On*Changing/On*Changed) enabled
80 </xsl:if><xsl:if test="$detectMissing">
81 ' Option: missing-value detection (*Specified/ShouldSerialize*/Reset*) enabled
82 </xsl:if><xsl:if test="not($optionFullFramework)">
83 ' Option: light framework (CF/Silverlight) enabled
84 </xsl:if><xsl:if test="$optionProtoRpc">
85 ' Option: proto-rpc enabled
86 </xsl:if>
87 <xsl:apply-templates select="file/FileDescriptorProto"/>
88 </xsl:template>
89
90 <xsl:template match="FileDescriptorProto">
91' Generated from: <xsl:value-of select="name"/>
92 <xsl:apply-templates select="dependency/string[.!='']"/>
93 <xsl:variable name="namespace"><xsl:call-template name="PickNamespace">
94 <xsl:with-param name="defaultNamespace" select="$defaultNamespace"/>
95 </xsl:call-template>
96 </xsl:variable>
97 <xsl:if test="string($namespace) != ''">
98Namespace <xsl:value-of select="translate($namespace,':-/\','__..')"/>
99</xsl:if>
100 <xsl:apply-templates select="message_type | enum_type | service"/>
101 <xsl:if test="string($namespace) != ''">
102End Namespace</xsl:if></xsl:template>
103
104<xsl:template match="FileDescriptorProto/dependency/string">
105' Note: requires additional types generated from: <xsl:value-of select="."/></xsl:template>
106
107<xsl:template match="DescriptorProto">
108<xsl:choose>
109<xsl:when test="$optionDataContract">
110<Global.System.Serializable, Global.ProtoBuf.ProtoContract(Name:="<xsl:value-of select="name"/>")> _
111<Global.System.Runtime.Serialization.DataContract(Name:="<xsl:value-of select="name"/>")> _
112</xsl:when>
113<xsl:when test="$optionXml">
114<Global.System.Serializable, Global.ProtoBuf.ProtoContract(Name:="<xsl:value-of select="name"/>")> _
115<Global.System.Xml.Serialization.XmlType(TypeName:="<xsl:value-of select="name"/>")> _
116</xsl:when>
117<xsl:otherwise>
118<Global.System.Serializable, Global.ProtoBuf.ProtoContract(Name:="<xsl:value-of select="name"/>")> _
119</xsl:otherwise>
120</xsl:choose><!--
121-->Public Partial Class <xsl:call-template name="pascal"/>
122 implements Global.ProtoBuf.IExtensible<!--
123 --><xsl:if test="$optionBinary">, Global.System.Runtime.Serialization.ISerializable</xsl:if><!--
124 --><xsl:if test="$optionObservable">, Global.System.ComponentModel.INotifyPropertyChanged</xsl:if><!--
125 --><xsl:if test="$optionPreObservable">, Global.System.ComponentModel.INotifyPropertyChanging</xsl:if>
126
127 Public Sub New
128 End Sub
129 <xsl:apply-templates select="*"/><xsl:if test="$optionBinary">
130 Protected Sub New(ByVal info As Global.System.Runtime.Serialization.SerializationInfo, ByVal context As Global.System.Runtime.Serialization.StreamingContext)
131 MyBase.New()
132 Global.ProtoBuf.Serializer.Merge(info, Me)
133 End Sub
134
135 Sub GetObjectData(ByVal info As Global.System.Runtime.Serialization.SerializationInfo, ByVal context As Global.System.Runtime.Serialization.StreamingContext) implements Global.System.Runtime.Serialization.ISerializable.GetObjectData
136 Global.ProtoBuf.Serializer.Serialize(info, Me)
137 End Sub
138
139 </xsl:if><xsl:if test="$optionObservable">
140 Public Event PropertyChanged As Global.System.ComponentModel.PropertyChangedEventHandler Implements Global.System.ComponentModel.INotifyPropertyChanged.PropertyChanged
141 Protected Overridable Sub OnPropertyChanged(ByVal propertyName As String)
142 RaiseEvent PropertyChanged(Me, New Global.System.ComponentModel.PropertyChangedEventArgs(propertyName))
143 End Sub
144 </xsl:if><xsl:if test="$optionPreObservable">
145 Public Event PropertyChanging As Global.System.ComponentModel.PropertyChangingEventHandler Implements Global.System.ComponentModel.INotifyPropertyChanging.PropertyChanging
146 Protected Overridable Sub OnPropertyChanging(ByVal propertyName As String)
147 RaiseEvent PropertyChanging(Me, New Global.System.ComponentModel.PropertyChangingEventArgs(propertyName))
148 End Sub
149 </xsl:if>
150 Private extensionObject As Global.ProtoBuf.IExtension
151 Function GetExtensionObject(createIfMissing As Boolean) As Global.ProtoBuf.IExtension Implements Global.ProtoBuf.IExtensible.GetExtensionObject
152 Return Global.ProtoBuf.Extensible.GetExtensionObject(extensionObject, createIfMissing)
153 End Function
154End Class
155 </xsl:template>
156
157
158
159 <xsl:template match="DescriptorProto/name | DescriptorProto/extension_range | DescriptorProto/extension"/>
160
161 <xsl:template match="
162 FileDescriptorProto/message_type | FileDescriptorProto/enum_type | FileDescriptorProto/service
163 | DescriptorProto/field | DescriptorProto/enum_type | DescriptorProto/message_type
164 | DescriptorProto/nested_type | EnumDescriptorProto/value | ServiceDescriptorProto/method">
165 <xsl:apply-templates select="*"/>
166 </xsl:template>
167
168 <xsl:template match="EnumDescriptorProto">
169 Public Enum <xsl:call-template name="pascal"/>
170 <xsl:apply-templates select="value"/>
171 End Enum
172 </xsl:template>
173
174 <xsl:template match="EnumValueDescriptorProto">
175 <xsl:text>
176 </xsl:text>
177 <xsl:value-of select="name"/>
178 <xsl:text xml:space="preserve"> = </xsl:text><xsl:choose>
179 <xsl:when test="number"><xsl:value-of select="number"/></xsl:when>
180 <xsl:otherwise>0</xsl:otherwise>
181 </xsl:choose><xsl:if test="position()!=last()">
182 </xsl:if>
183 </xsl:template>
184
185 <xsl:template match="FieldDescriptorProto" mode="field">
186 <xsl:choose>
187 <xsl:when test="not(key('fieldNames',concat('_',name)))"><xsl:value-of select="concat('_',name)"/></xsl:when>
188 <xsl:when test="not(key('fieldNames',concat(name,'Field')))"><xsl:value-of select="concat(name,'Field')"/></xsl:when>
189 <xsl:otherwise><xsl:value-of select="concat('_',generate-id())"/></xsl:otherwise>
190 </xsl:choose>
191 </xsl:template>
192
193 <xsl:template match="FieldDescriptorProto" mode="format">
194 <xsl:choose>
195 <xsl:when test="type='TYPE_DOUBLE' or type='TYPE_FLOAT'
196 or type='TYPE_FIXED32' or type='TYPE_FIXED64'
197 or type='TYPE_SFIXED32' or type='TYPE_SFIXED64'">FixedSize</xsl:when>
198 <xsl:when test="type='TYPE_GROUP'">Group</xsl:when>
199 <xsl:when test="not(type) or type='TYPE_INT32' or type='TYPE_INT64'
200 or type='TYPE_UINT32' or type='TYPE_UINT64'
201 or type='TYPE_ENUM'">TwosComplement</xsl:when>
202 <xsl:when test="type='TYPE_SINT32' or type='TYPE_SINT64'">ZigZag</xsl:when>
203 <xsl:otherwise>Default</xsl:otherwise>
204 </xsl:choose>
205 </xsl:template>
206 <xsl:template match="FieldDescriptorProto" mode="primitiveType">
207 <xsl:choose>
208 <xsl:when test="not(type)">struct</xsl:when>
209 <xsl:when test="type='TYPE_DOUBLE'">struct</xsl:when>
210 <xsl:when test="type='TYPE_FLOAT'">struct</xsl:when>
211 <xsl:when test="type='TYPE_INT64'">struct</xsl:when>
212 <xsl:when test="type='TYPE_UINT64'">struct</xsl:when>
213 <xsl:when test="type='TYPE_INT32'">struct</xsl:when>
214 <xsl:when test="type='TYPE_FIXED64'">struct</xsl:when>
215 <xsl:when test="type='TYPE_FIXED32'">struct</xsl:when>
216 <xsl:when test="type='TYPE_BOOL'">struct</xsl:when>
217 <xsl:when test="type='TYPE_STRING'">class</xsl:when>
218 <xsl:when test="type='TYPE_BYTES'">class</xsl:when>
219 <xsl:when test="type='TYPE_UINT32'">struct</xsl:when>
220 <xsl:when test="type='TYPE_SFIXED32'">struct</xsl:when>
221 <xsl:when test="type='TYPE_SFIXED64'">struct</xsl:when>
222 <xsl:when test="type='TYPE_SINT32'">struct</xsl:when>
223 <xsl:when test="type='TYPE_SINT64'">struct</xsl:when>
224 <xsl:when test="type='TYPE_ENUM'">struct</xsl:when>
225 <xsl:when test="type='TYPE_GROUP' or type='TYPE_MESSAGE'">none</xsl:when>
226 <xsl:otherwise>
227 <xsl:message terminate="yes">
228 Field type not implemented: <xsl:value-of select="type"/> (<xsl:value-of select="../../name"/>.<xsl:value-of select="name"/>)
229 </xsl:message>
230 </xsl:otherwise>
231 </xsl:choose>
232 </xsl:template>
233 <xsl:template match="FieldDescriptorProto" mode="type">
234 <xsl:choose>
235 <xsl:when test="not(type)">double</xsl:when>
236 <xsl:when test="type='TYPE_DOUBLE'">Double</xsl:when>
237 <xsl:when test="type='TYPE_FLOAT'">Single</xsl:when>
238 <xsl:when test="type='TYPE_INT64'">Long</xsl:when>
239 <xsl:when test="type='TYPE_UINT64'">ULong</xsl:when>
240 <xsl:when test="type='TYPE_INT32'">Integer</xsl:when>
241 <xsl:when test="type='TYPE_FIXED64'">ULong</xsl:when>
242 <xsl:when test="type='TYPE_FIXED32'">UInteger</xsl:when>
243 <xsl:when test="type='TYPE_BOOL'">Boolean</xsl:when>
244 <xsl:when test="type='TYPE_STRING'">String</xsl:when>
245 <xsl:when test="type='TYPE_BYTES'">Byte()</xsl:when>
246 <xsl:when test="type='TYPE_UINT32'">UInteger</xsl:when>
247 <xsl:when test="type='TYPE_SFIXED32'">Integer</xsl:when>
248 <xsl:when test="type='TYPE_SFIXED64'">Long</xsl:when>
249 <xsl:when test="type='TYPE_SINT32'">Integer</xsl:when>
250 <xsl:when test="type='TYPE_SINT64'">Long</xsl:when>
251 <xsl:when test="type='TYPE_GROUP' or type='TYPE_MESSAGE' or type='TYPE_ENUM'"><xsl:call-template name="pascal">
252 <xsl:with-param name="value" select="substring-after(type_name,'.')"/>
253 </xsl:call-template></xsl:when>
254 <xsl:otherwise>
255 <xsl:message terminate="yes">
256 Field type not implemented: <xsl:value-of select="type"/> (<xsl:value-of select="../../name"/>.<xsl:value-of select="name"/>)
257 </xsl:message>
258 </xsl:otherwise>
259 </xsl:choose>
260
261 </xsl:template>
262
263 <xsl:template match="FieldDescriptorProto[default_value]" mode="defaultValue">
264 <xsl:choose>
265 <xsl:when test="type='TYPE_STRING'">"<xsl:value-of select="default_value"/>"</xsl:when>
266 <xsl:when test="type='TYPE_ENUM'"><xsl:apply-templates select="." mode="type"/>.<xsl:value-of select="default_value"/></xsl:when>
267 <xsl:when test="type='TYPE_BYTES'"> ' <xsl:value-of select="default_value"/></xsl:when>
268 <xsl:otherwise>CType(<xsl:value-of select="default_value"/>, <xsl:apply-templates select="." mode="type"/>)</xsl:otherwise>
269 </xsl:choose>
270 </xsl:template>
271
272 <!--
273 We need to find the first enum value given .foo.bar.SomeEnum - but the enum itself
274 only knows about SomeEnum; we need to look at all parent DescriptorProto nodes, and
275 the FileDescriptorProto for the namespace.
276
277 This does an annoying up/down recursion... a bit expensive, but *generally* OK.
278 Could perhaps index the last part of the enum name to reduce overhead?
279 -->
280 <xsl:template name="GetFirstEnumValue">
281 <xsl:variable name="hunt" select="type_name"/>
282 <xsl:for-each select="//EnumDescriptorProto">
283 <xsl:variable name="fullName">
284 <xsl:for-each select="ancestor::FileDescriptorProto">.<xsl:value-of select="package"/></xsl:for-each>
285 <xsl:for-each select="ancestor::DescriptorProto">.<xsl:value-of select="name"/></xsl:for-each>
286 <xsl:value-of select="concat('.',name)"/>
287 </xsl:variable>
288 <xsl:if test="$fullName=$hunt"><xsl:value-of select="(value/EnumValueDescriptorProto)[1]/name"/></xsl:if>
289 </xsl:for-each>
290 </xsl:template>
291
292 <xsl:template match="FieldDescriptorProto[not(default_value)]" mode="defaultValue">
293 <xsl:choose>
294 <xsl:when test="type='TYPE_DOUBLE'">0.0</xsl:when>
295 <xsl:when test="type='TYPE_FLOAT'">0.0F</xsl:when>
296 <xsl:when test="type='TYPE_INT64'">0L</xsl:when>
297 <xsl:when test="type='TYPE_UINT64'">0L</xsl:when>
298 <xsl:when test="type='TYPE_INT32'">0</xsl:when>
299 <xsl:when test="type='TYPE_FIXED64'">0L</xsl:when>
300 <xsl:when test="type='TYPE_FIXED32'">0</xsl:when>
301 <xsl:when test="type='TYPE_BOOL'">False</xsl:when>
302 <xsl:when test="type='TYPE_STRING'">""</xsl:when>
303 <xsl:when test="type='TYPE_BYTES'">Nothing</xsl:when>
304 <xsl:when test="type='TYPE_UINT32'">0</xsl:when>
305 <xsl:when test="type='TYPE_SFIXED32'">0</xsl:when>
306 <xsl:when test="type='TYPE_SFIXED64'">0L</xsl:when>
307 <xsl:when test="type='TYPE_SINT32'">0</xsl:when>
308 <xsl:when test="type='TYPE_SINT64'">0L</xsl:when>
309 <xsl:when test="type='TYPE_MESSAGE'">Nothing</xsl:when>
310 <xsl:when test="type='TYPE_ENUM'"><xsl:apply-templates select="." mode="type"/>.<xsl:call-template name="GetFirstEnumValue"/></xsl:when>
311 <xsl:otherwise>Nothing</xsl:otherwise>
312 </xsl:choose>
313 </xsl:template>
314
315 <xsl:template match="FieldDescriptorProto[label='LABEL_OPTIONAL' or not(label)]">
316 <xsl:variable name="propType"><xsl:apply-templates select="." mode="type"/></xsl:variable>
317 <xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
318 <xsl:variable name="primitiveType"><xsl:apply-templates select="." mode="primitiveType"/></xsl:variable>
319 <xsl:variable name="defaultValue"><xsl:apply-templates select="." mode="defaultValue"/></xsl:variable>
320 <xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
321 <xsl:variable name="specified" select="$optionDetectMissing and ($primitiveType='struct' or $primitiveType='class')"/>
322 <xsl:variable name="fieldType"><xsl:if test="$specified and $primitiveType='struct'">Nullable(Of </xsl:if><xsl:value-of select="$propType"/><xsl:if test="$specified and $primitiveType='struct'">)</xsl:if></xsl:variable>
323
324 <xsl:choose>
325 <xsl:when test="substring-after($fieldType, 'google.protobuf.')">
326 Private <xsl:value-of select="concat($field,' As ',substring-after($fieldType, 'google.protobuf.'))"/><xsl:if test="not($specified)"> =<xsl:value-of select="$defaultValue"/></xsl:if>
327 </xsl:when>
328 <xsl:otherwise>
329 Private <xsl:value-of select="concat($field,' As ',$fieldType)"/><xsl:if test="not($specified)"> =<xsl:value-of select="$defaultValue"/></xsl:if>
330 </xsl:otherwise>
331 </xsl:choose>
332 <xsl:choose>
333 <xsl:when test="not($specified) and $optionXml">
334 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=False, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
335 <xsl:choose>
336 <xsl:when test="substring-after($fieldType, 'google.protobuf.')">
337 <Global.System.ComponentModel.DefaultValue(CType(<xsl:value-of select="$defaultValue"/>, <xsl:value-of select="substring-after($fieldType, 'google.protobuf.')"/>))> _
338 </xsl:when>
339 <xsl:otherwise>
340 <Global.System.ComponentModel.DefaultValue(CType(<xsl:value-of select="$defaultValue"/>, <xsl:value-of select="$fieldType"/>))> _
341 </xsl:otherwise>
342 </xsl:choose>
343 <Global.System.Xml.Serialization.XmlElement("<xsl:value-of select="name"/>", Order:=<xsl:value-of select="number"/>)> _ <!--
344 --></xsl:when>
345 <xsl:when test="not($specified) and $optionDataContract">
346 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=False, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
347 <xsl:choose>
348 <xsl:when test="substring-after($fieldType, 'google.protobuf.')">
349 <Global.System.ComponentModel.DefaultValue(CType(<xsl:value-of select="$defaultValue"/>, <xsl:value-of select="substring-after($fieldType, 'google.protobuf.')"/>))> _
350 </xsl:when>
351 <xsl:otherwise>
352 <Global.System.ComponentModel.DefaultValue(CType(<xsl:value-of select="$defaultValue"/>, <xsl:value-of select="$fieldType"/>))> _
353 </xsl:otherwise>
354 </xsl:choose>
355 <Global.System.Runtime.Serialization.DataMember(Name:="<xsl:value-of select="name"/>", Order:=<xsl:value-of select="number"/>, IsRequired:=False)> _ <!--
356 --></xsl:when>
357 <xsl:when test="not($specified)">
358 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=False, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _ <!--
359 --><xsl:choose>
360 <xsl:when test="substring-after($fieldType, 'google.protobuf.')">
361 <Global.System.ComponentModel.DefaultValue(CType(<xsl:value-of select="$defaultValue"/>, <xsl:value-of select="substring-after($fieldType, 'google.protobuf.')"/>))> _ <!--
362 --></xsl:when>
363 <xsl:otherwise>
364 <Global.System.ComponentModel.DefaultValue(CType(<xsl:value-of select="$defaultValue"/>, <xsl:value-of select="$fieldType"/>))> _ <!--
365 --></xsl:otherwise>
366 </xsl:choose><!--
367 --></xsl:when>
368 <xsl:when test="$optionDataContract">
369 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=False, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
370 <Global.System.Runtime.Serialization.DataMember(Name:="<xsl:value-of select="name"/>", Order:=<xsl:value-of select="number"/>, IsRequired:=False)> _ <!--
371 --></xsl:when>
372 <xsl:when test="$optionXml">
373 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=False, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
374 <Global.System.Xml.Serialization.XmlElement("<xsl:value-of select="name"/>", Order:=<xsl:value-of select="number"/>)> _ <!--
375 --></xsl:when>
376 <xsl:otherwise>
377 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=False, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _ <!--
378 --></xsl:otherwise>
379 </xsl:choose><!--
380 --><xsl:call-template name="WriteGetSet">
381 <xsl:with-param name="fieldType" select="$fieldType"/>
382 <xsl:with-param name="propType" select="$propType"/>
383 <xsl:with-param name="name"><xsl:call-template name="pascalPropName"/></xsl:with-param>
384 <xsl:with-param name="field" select="$field"/>
385 <xsl:with-param name="defaultValue" select="$defaultValue"/>
386 <xsl:with-param name="specified" select="$specified"/>
387 </xsl:call-template>
388 </xsl:template>
389
390 <xsl:template name="pascalPropName">
391 <xsl:param name="value" select="name"/>
392 <xsl:param name="delimiter" select="'_'"/>
393 <xsl:variable name="valueUC" select="translate($value,$alpha,$ALPHA)"/>
394 <xsl:variable name="finalName">
395 <xsl:choose>
396 <xsl:when test="$types[translate(name,$alpha,$ALPHA)=$valueUC]"><xsl:value-of select="concat($value,$delimiter,'Property')"/></xsl:when>
397 <xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
398 </xsl:choose>
399 </xsl:variable>
400 <xsl:call-template name="pascal">
401 <xsl:with-param name="value" select="$finalName"/>
402 <xsl:with-param name="delimiter" select="$delimiter"/>
403 </xsl:call-template>
404 </xsl:template>
405
406 <xsl:template match="FieldDescriptorProto[label='LABEL_REQUIRED']">
407 <xsl:variable name="type"><xsl:apply-templates select="." mode="type"/></xsl:variable>
408 <xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
409 <xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
410 Private <xsl:value-of select="concat($field, ' As ', $type)"/>
411 <xsl:choose>
412 <xsl:when test="$optionDataContract">
413 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=True, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
414 <Global.System.Runtime.Serialization.DataMember(Name:="<xsl:value-of select="name"/>", Order:=<xsl:value-of select="number"/>, IsRequired:=True)> _ <!--
415 --></xsl:when>
416 <xsl:when test="$optionXml">
417 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=True, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
418 <Global.System.Xml.Serialization.XmlElement("<xsl:value-of select="name"/>", Order:=<xsl:value-of select="number"/>)> _ <!--
419 --></xsl:when>
420 <xsl:otherwise>
421 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired:=True, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _ <!--
422 --></xsl:otherwise>
423 </xsl:choose><!--
424 --><xsl:call-template name="WriteGetSet">
425 <xsl:with-param name="fieldType" select="$type"/>
426 <xsl:with-param name="propType" select="$type"/>
427 <xsl:with-param name="name" select="name"/>
428 <xsl:with-param name="field" select="$field"/>
429 </xsl:call-template>
430 </xsl:template>
431
432 <xsl:template name="WriteGetSet">
433 <xsl:param name="fieldType"/>
434 <xsl:param name="propType"/>
435 <xsl:param name="name"/>
436 <xsl:param name="field"/>
437 <xsl:param name="specified" select="false()"/>
438 <xsl:param name="defaultValue"/>
439 <xsl:variable name="primitiveType"><xsl:apply-templates select="." mode="primitiveType"/></xsl:variable>
440 <xsl:choose>
441 <xsl:when test="substring-after($fieldType, 'google.protobuf.')">
442 Public Property <xsl:value-of select="concat($name,' As ',substring-after($fieldType, 'google.protobuf.'))"/>
443 </xsl:when>
444 <xsl:otherwise>
445 Public Property <xsl:value-of select="concat($name,' As ',$fieldType)"/>
446 </xsl:otherwise>
447 </xsl:choose>
448 Get
449 <xsl:choose>
450 <xsl:when test="$specified and $primitiveType='struct'"><!--
451 -->Return <xsl:value-of select="$field"/><!--
452 --></xsl:when>
453 <xsl:when test="$specified">
454 If Not <xsl:value-of select="$field"/> Is Nothing Then
455 Return <xsl:value-of select="$field"/>
456 Else
457 Return <xsl:value-of select="$defaultValue"/>
458 End If<!--
459 --></xsl:when>
460 <xsl:otherwise><!--
461 -->Return <xsl:value-of select="$field"/><!--
462 --></xsl:otherwise>
463 </xsl:choose>
464 End Get
465 <xsl:choose>
466 <xsl:when test="substring-after($fieldType, 'google.protobuf.')">
467 Set(<xsl:value-of select="concat('value As ',substring-after($fieldType, 'google.protobuf.'))"/>)
468 </xsl:when>
469 <xsl:otherwise>
470 Set(<xsl:value-of select="concat('value As ',$fieldType)"/>)
471 </xsl:otherwise>
472 </xsl:choose>
473 <xsl:if test="$optionPartialMethods">On<xsl:value-of select="$name"/>Changing(value)
474 </xsl:if><xsl:if test="$optionPreObservable">OnPropertyChanging("<xsl:value-of select="$name"/>")
475 </xsl:if><xsl:value-of select="$field"/> = value
476 <xsl:if test="$optionObservable">OnPropertyChanged("<xsl:value-of select="$name"/>") </xsl:if><xsl:if test="$optionPartialMethods">On<xsl:value-of select="$name"/>Changed()</xsl:if>
477 End Set
478 End Property
479 <xsl:if test="$optionPartialMethods">
480 partial void On<xsl:value-of select="$name"/>Changing(<xsl:value-of select="$propType"/> value);
481 partial void On<xsl:value-of select="$name"/>Changed();</xsl:if><xsl:if test="$specified">
482 <Global.System.Xml.Serialization.XmlIgnore> _
483 <xsl:if test="$optionFullFramework"><Global.System.ComponentModel.Browsable(false)> _ </xsl:if>
484 <xsl:choose>
485 <xsl:when test="$specified and $primitiveType='struct'">
486 Public Property <xsl:value-of select="$name"/>Specified As Boolean
487 Get
488 Return <xsl:value-of select="$field"/>.HasValue
489 End Get
490 Set (ByVal value As Boolean)
491 If Not <xsl:value-of select="$field"/>.HasValue Then
492 If value = True then <xsl:value-of select="$field"/> = <xsl:value-of select="$name"/>
493 Else
494 If value = False then <xsl:value-of select="$field"/> = Nothing
495 End If
496 End Set
497 End Property
498 </xsl:when>
499 <xsl:otherwise>
500 Public Property <xsl:value-of select="$name"/>Specified As Boolean
501 Get
502 Return <xsl:value-of select="$field"/> IsNot Nothing
503 End Get
504 Set (ByVal value As Boolean)
505 If <xsl:value-of select="$field"/> Is Nothing Then
506 If value = True then <xsl:value-of select="$field"/> = <xsl:value-of select="$name"/>
507 Else
508 If value = False then <xsl:value-of select="$field"/> = Nothing
509 End If
510 End Set
511 End Property
512 </xsl:otherwise>
513 </xsl:choose>
514 Private Function ShouldSerialize<xsl:value-of select="$name"/>() As Boolean
515 Return <xsl:value-of select="$name"/>Specified
516 End Function
517 Private Sub Reset<xsl:value-of select="$name"/>()
518 <xsl:value-of select="$name"/>Specified = false
519 End Sub
520 </xsl:if>
521 </xsl:template>
522 <xsl:template match="FieldDescriptorProto[label='LABEL_REPEATED']">
523 <xsl:variable name="type"><xsl:apply-templates select="." mode="type"/></xsl:variable>
524 <xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
525 <xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
526 <xsl:choose>
527 <xsl:when test="substring-after($type, 'google.protobuf.')">
528 Private <xsl:if test="not($optionXml)">ReadOnly </xsl:if> <xsl:value-of select="$field"/> as Global.System.Collections.Generic.List(Of <xsl:value-of select="substring-after($type, 'google.protobuf.')" />) = New Global.System.Collections.Generic.List(Of <xsl:value-of select="substring-after($type, 'google.protobuf.')"/>)()
529 </xsl:when>
530 <xsl:otherwise>
531 Private <xsl:if test="not($optionXml)">ReadOnly </xsl:if> <xsl:value-of select="$field"/> as Global.System.Collections.Generic.List(Of <xsl:value-of select="$type" />) = New Global.System.Collections.Generic.List(Of <xsl:value-of select="$type"/>)()
532 </xsl:otherwise>
533 </xsl:choose>
534 <xsl:choose>
535 <xsl:when test="$optionDataContract">
536 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
537 <Global.System.Runtime.Serialization.DataMember(Name:="<xsl:value-of select="name"/>", Order:=<xsl:value-of select="number"/>, IsRequired:=False)> _
538 </xsl:when>
539 <xsl:when test="$optionXml">
540 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
541 <Global.System.Xml.Serialization.XmlElement("<xsl:value-of select="name"/>", Order:=<xsl:value-of select="number"/>)> _
542 </xsl:when>
543 <xsl:otherwise>
544 <Global.ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, Name:="<xsl:value-of select="name"/>", DataFormat:=Global.ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)> _
545 </xsl:otherwise>
546 </xsl:choose><!--
547 --><xsl:choose>
548 <xsl:when test="substring-after($type, 'google.protobuf.')"><!--
549 -->Public <xsl:if test="not($optionXml)">ReadOnly </xsl:if>Property <xsl:value-of select="name"/> As Global.System.Collections.Generic.List(Of <xsl:value-of select="substring-after($type, 'google.protobuf.')" />)
550 </xsl:when>
551 <xsl:otherwise><!--
552 -->Public <xsl:if test="not($optionXml)">ReadOnly </xsl:if>Property <xsl:value-of select="name"/> As Global.System.Collections.Generic.List(Of <xsl:value-of select="$type" />)
553 </xsl:otherwise>
554 </xsl:choose>
555 Get
556 Return <xsl:value-of select="$field"/>
557 End Get
558 <!----><xsl:if test="$optionXml">
559 <xsl:choose>
560 <xsl:when test="substring-after($type, 'google.protobuf.')">
561 Set (value As Global.System.Collections.Generic.List(Of <xsl:value-of select="substring-after($type, 'google.protobuf.')" />))
562 </xsl:when>
563 <xsl:otherwise>
564 Set (value As Global.System.Collections.Generic.List(Of <xsl:value-of select="$type" />))
565 </xsl:otherwise>
566 </xsl:choose>
567 <xsl:value-of select="$field"/> = value
568 End Set
569 </xsl:if>
570 End Property
571 </xsl:template>
572
573 <xsl:template match="ServiceDescriptorProto">
574 <xsl:if test="($optionClientProxy or $optionDataContract)">
575 <Global.System.ServiceModel.ServiceContract(Name:="<xsl:value-of select="name"/>")> _
576 </xsl:if>
577 Public Interface I<xsl:value-of select="name"/>
578 <xsl:apply-templates select="method"/>
579 End Interface
580
581 <xsl:if test="$optionProtoRpc">
582 Public Class <xsl:value-of select="name"/>Client : Global.ProtoBuf.ServiceModel.RpcClient
583 public <xsl:value-of select="name"/>Client() : base(typeof(I<xsl:value-of select="name"/>)) { }
584
585 <xsl:apply-templates select="method/MethodDescriptorProto" mode="protoRpc"/>
586 End Class
587 </xsl:if>
588 <xsl:apply-templates select="." mode="clientProxy"/>
589
590 </xsl:template>
591
592 <xsl:template match="MethodDescriptorProto">
593 <xsl:if test="$optionDataContract">
594 <Global.System.ServiceModel.OperationContract(Name:="<xsl:value-of select="name"/>")> _
595 <Global.ProtoBuf.ServiceModel.ProtoBehavior()> _
596 </xsl:if>
597 <xsl:apply-templates select="output_type"/><xsl:text xml:space="preserve"> </xsl:text><xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request);
598 <xsl:if test="$optionAsynchronous and $optionDataContract">
599 <Global.System.ServiceModel.OperationContract(AsyncPattern:=True, Name:="<xsl:value-of select="name"/>")> _
600 Global.System.IAsyncResult Begin<xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request, Global.System.AsyncCallback callback, object state);
601 <xsl:apply-templates select="output_type"/> End<xsl:value-of select="name"/>(Global.System.IAsyncResult ar);
602 </xsl:if>
603 </xsl:template>
604
605 <xsl:template match="MethodDescriptorProto" mode="protoRpc">
606 <xsl:apply-templates select="output_type"/><xsl:text xml:space="preserve"> </xsl:text><xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request)
607 {
608 return (<xsl:apply-templates select="output_type"/>) Send("<xsl:value-of select="name"/>", request);
609 }
610 </xsl:template>
611
612 <xsl:template match="MethodDescriptorProto/input_type | MethodDescriptorProto/output_type">
613 <xsl:value-of select="substring-after(.,'.')"/>
614 </xsl:template>
615
616 <xsl:template match="MethodDescriptorProto" mode="CompleteEvent">
617 <xsl:if test="$optionAsynchronous and $optionDataContract">
618 Public Class <xsl:value-of select="name"/>CompletedEventArgs : Global.System.ComponentModel.AsyncCompletedEventArgs
619 private object[] results;
620
621 public <xsl:value-of select="name"/>CompletedEventArgs(object[] results, Global.System.Exception exception, bool cancelled, object userState)
622 : base(exception, cancelled, userState)
623 {
624 this.results = results;
625 }
626
627 public <xsl:apply-templates select="output_type"/> Result
628 {
629 get {
630 base.RaiseExceptionIfNecessary();
631 return (<xsl:apply-templates select="output_type"/>)(this.results[0]);
632 }
633 }
634 End Class
635 </xsl:if>
636 </xsl:template>
637
638 <xsl:template match="ServiceDescriptorProto" mode="clientProxy">
639 <xsl:if test="$optionAsynchronous and $optionDataContract and $optionClientProxy">
640 <xsl:apply-templates select="method/MethodDescriptorProto" mode="CompleteEvent"/>
641
642 <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
643 public partial class <xsl:value-of select="name"/>Client : Global.System.ServiceModel.ClientBase<I<xsl:value-of select="name"/>>, I<xsl:value-of select="name"/>
644 {
645
646 public <xsl:value-of select="name"/>Client()
647 {}
648 public <xsl:value-of select="name"/>Client(string endpointConfigurationName)
649 : base(endpointConfigurationName)
650 {}
651 public <xsl:value-of select="name"/>Client(string endpointConfigurationName, string remoteAddress)
652 : base(endpointConfigurationName, remoteAddress)
653 {}
654 public <xsl:value-of select="name"/>Client(string endpointConfigurationName, Global.System.ServiceModel.EndpointAddress remoteAddress)
655 : base(endpointConfigurationName, remoteAddress)
656 {}
657 public <xsl:value-of select="name"/>Client(Global.System.ServiceModel.Channels.Binding binding, Global.System.ServiceModel.EndpointAddress remoteAddress)
658 : base(binding, remoteAddress)
659 {}
660
661 <xsl:apply-templates select="method/MethodDescriptorProto" mode="clientProxy"/>
662 }
663 </xsl:if>
664 </xsl:template>
665
666 <xsl:template match="MethodDescriptorProto" mode="clientProxy">
667 <xsl:if test="$optionAsynchronous and $optionDataContract and $optionClientProxy">
668 private BeginOperationDelegate onBegin<xsl:value-of select="name"/>Delegate;
669 private EndOperationDelegate onEnd<xsl:value-of select="name"/>Delegate;
670 private Global.System.Threading.SendOrPostCallback on<xsl:value-of select="name"/>CompletedDelegate;
671
672 public event Global.System.EventHandler<<xsl:value-of select="name"/>CompletedEventArgs> <xsl:value-of select="name"/>Completed;
673
674 public <xsl:apply-templates select="output_type"/><xsl:text xml:space="preserve"> </xsl:text><xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request)
675 {
676 return base.Channel.<xsl:value-of select="name"/>(request);
677 }
678
679 <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
680 public Global.System.IAsyncResult Begin<xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request, Global.System.AsyncCallback callback, object asyncState)
681 {
682 return base.Channel.Begin<xsl:value-of select="name"/>(request, callback, asyncState);
683 }
684
685 <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
686 public <xsl:apply-templates select="output_type"/> End<xsl:value-of select="name"/>(Global.System.IAsyncResult result)
687 {
688 return base.Channel.End<xsl:value-of select="name"/>(result);
689 }
690
691 private Global.System.IAsyncResult OnBegin<xsl:value-of select="name"/>(object[] inValues, Global.System.AsyncCallback callback, object asyncState)
692 {
693 <xsl:apply-templates select="input_type"/> request = ((<xsl:apply-templates select="input_type"/>)(inValues[0]));
694 return this.Begin<xsl:value-of select="name"/>(request, callback, asyncState);
695 }
696
697 private object[] OnEnd<xsl:value-of select="name"/>(Global.System.IAsyncResult result)
698 {
699 <xsl:apply-templates select="output_type"/> retVal = this.End<xsl:value-of select="name"/>(result);
700 return new object[] {
701 retVal};
702 }
703
704 private void On<xsl:value-of select="name"/>Completed(object state)
705 {
706 if ((this.<xsl:value-of select="name"/>Completed != null))
707 {
708 InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
709 this.<xsl:value-of select="name"/>Completed(this, new <xsl:value-of select="name"/>CompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
710 }
711 }
712
713 public void <xsl:value-of select="name"/>Async(<xsl:apply-templates select="input_type"/> request)
714 {
715 this.<xsl:value-of select="name"/>Async(request, null);
716 }
717
718 public void <xsl:value-of select="name"/>Async(<xsl:apply-templates select="input_type"/> request, object userState)
719 {
720 if ((this.onBegin<xsl:value-of select="name"/>Delegate == null))
721 {
722 this.onBegin<xsl:value-of select="name"/>Delegate = new BeginOperationDelegate(this.OnBegin<xsl:value-of select="name"/>);
723 }
724 if ((this.onEnd<xsl:value-of select="name"/>Delegate == null))
725 {
726 this.onEnd<xsl:value-of select="name"/>Delegate = new EndOperationDelegate(this.OnEnd<xsl:value-of select="name"/>);
727 }
728 if ((this.on<xsl:value-of select="name"/>CompletedDelegate == null))
729 {
730 this.on<xsl:value-of select="name"/>CompletedDelegate = new Global.System.Threading.SendOrPostCallback(this.On<xsl:value-of select="name"/>Completed);
731 }
732 base.InvokeAsync(this.onBegin<xsl:value-of select="name"/>Delegate, new object[] {
733 request}, this.onEnd<xsl:value-of select="name"/>Delegate, this.on<xsl:value-of select="name"/>CompletedDelegate, userState);
734 }
735 </xsl:if>
736 </xsl:template>
737
738 <xsl:template name="escapeKeyword"><xsl:param name="value"/><xsl:choose>
739 <xsl:when test="contains($keywordsUpper,concat('|',translate($value, $alpha, $ALPHA),'|'))">[<xsl:value-of select="$value"/>]</xsl:when>
740 <xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
741 </xsl:choose></xsl:template>
742 <xsl:variable name="keywords">|AddHandler|AddressOf|Alias|And|AndAlso|As|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|CDec|CDbl|Char|CInt|Class|CLng|CObj|Const|Continue|CSByte|CShort|CSng|CStr|CType|CUInt|CULng|CUShort|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else|ElseIf|End|EndIf|Enum|Erase|Error|Event|Exit|False|Finally|For|Friend|Function|Get|GetType|GetXMLNamespace|Global|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|Let|Lib|Like|Long|Loop|Me|Mod|Module|MustInherit|MustOverride|MyBase|MyClass|Namespace|Narrowing|New|Next|Not|Nothing|NotInheritable|NotOverridable|Object|Of|On|Operator|Option|Optional|Or|OrElse|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|REM|RemoveHandler|Resume|Return|SByte|Select|Set|Shadows|Shared|Short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|True|Try|TryCast|TypeOf|Variant|Wend|UInteger|ULong|UShort|Using|When|While|Widening|With|WithEvents|WriteOnly|Xor|</xsl:variable>
743 <xsl:variable name="keywordsUpper" select="translate($keywords, $alpha, $ALPHA)"/>
744
745</xsl:stylesheet>