PageRenderTime 54ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/packages/protobuf-net.1.0.0.280/Tools/csharp.xslt

https://bitbucket.org/sparktree/stackexchange.stackid
Extensible Stylesheet Language Transformations | 629 lines | 575 code | 54 blank | 0 comment | 0 complexity | ae57c404bc8be3ddb8f8b4214074b141 MD5 | raw file
  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. <xsl:param name="import"/>
  21. <xsl:key name="fieldNames" match="//FieldDescriptorProto" use="name"/>
  22. <xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
  23. <xsl:variable name="optionXml" select="$xml='true'"/>
  24. <xsl:variable name="optionDataContract" select="$datacontract='true'"/>
  25. <xsl:variable name="optionBinary" select="$binary='true'"/>
  26. <xsl:variable name="optionProtoRpc" select="$protoRpc='true'"/>
  27. <xsl:variable name="optionObservable" select="$observable='true'"/>
  28. <xsl:variable name="optionPreObservable" select="$preObservable='true'"/>
  29. <xsl:variable name="optionPartialMethods" select="$partialMethods='true'"/>
  30. <xsl:variable name="optionDetectMissing" select="$detectMissing='true'"/>
  31. <xsl:variable name="optionFullFramework" select="not($lightFramework='true')"/>
  32. <xsl:variable name="optionAsynchronous" select="$asynchronous='true'"/>
  33. <xsl:variable name="optionClientProxy" select="$clientProxy='true'"/>
  34. <xsl:template match="/">
  35. <xsl:text disable-output-escaping="yes">//------------------------------------------------------------------------------
  36. // &lt;auto-generated&gt;
  37. // This code was generated by a tool.
  38. //
  39. // Changes to this file may cause incorrect behavior and will be lost if
  40. // the code is regenerated.
  41. // &lt;/auto-generated&gt;
  42. //------------------------------------------------------------------------------
  43. </xsl:text><!--
  44. --><xsl:apply-templates select="*"/><!--
  45. --></xsl:template>
  46. <xsl:template name="WriteUsings">
  47. <xsl:param name="ns"/>
  48. <xsl:if test="$ns != ''"><xsl:choose>
  49. <xsl:when test="contains($ns,';')">
  50. using <xsl:value-of select="substring-before($ns,';')"/>;<!--
  51. --><xsl:call-template name="WriteUsings">
  52. <xsl:with-param name="ns" select="substring-after($ns,';')"/>
  53. </xsl:call-template>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. using <xsl:value-of select="$ns"/>;
  57. </xsl:otherwise>
  58. </xsl:choose></xsl:if></xsl:template>
  59. <xsl:template match="FileDescriptorSet">
  60. <xsl:if test="$help='true'">
  61. <xsl:message terminate="yes">
  62. CSharp template for protobuf-net.
  63. Options:
  64. General:
  65. "help" - this page
  66. Additional serializer support:
  67. "xml" - enable explicit xml support (XmlSerializer)
  68. "datacontract" - enable data-contract support (DataContractSerializer; requires .NET 3.0)
  69. "binary" - enable binary support (BinaryFormatter; not supported on Silverlight)
  70. Other:
  71. "protoRpc" - enable proto-rpc client
  72. "observable" - change notification (observer pattern) support
  73. "preObservable" - pre-change notification (observer pattern) support (requires .NET 3.5)
  74. "partialMethods" - provide partial methods for changes (requires C# 3.0)
  75. "detectMissing" - provide *Specified properties to indicate whether fields are present
  76. "lightFramework" - omit additional attributes not included in CF/Silverlight
  77. "asynchronous" - emit asynchronous methods for use with WCF
  78. "clientProxy" - emit asynchronous client proxy class
  79. "import" - additional namespaces to import (semicolon delimited)
  80. "fixCase" - change type/member names (types/properties become PascalCase; fields become camelCase)
  81. </xsl:message>
  82. </xsl:if>
  83. <xsl:if test="$optionXml and $optionDataContract">
  84. <xsl:message terminate="yes">
  85. Invalid options: xml and data-contract serialization are mutually exclusive.
  86. </xsl:message>
  87. </xsl:if>
  88. <xsl:if test="$optionXml">
  89. // Option: xml serialization ([XmlType]/[XmlElement]) enabled
  90. </xsl:if><xsl:if test="$optionDataContract">
  91. // Option: data-contract serialization ([DataContract]/[DataMember]) enabled
  92. </xsl:if><xsl:if test="$optionBinary">
  93. // Option: binary serialization (ISerializable) enabled
  94. </xsl:if><xsl:if test="$optionObservable">
  95. // Option: observable (OnPropertyChanged) enabled
  96. </xsl:if><xsl:if test="$optionPreObservable">
  97. // Option: pre-observable (OnPropertyChanging) enabled
  98. </xsl:if><xsl:if test="$partialMethods">
  99. // Option: partial methods (On*Changing/On*Changed) enabled
  100. </xsl:if><xsl:if test="$detectMissing">
  101. // Option: missing-value detection (*Specified/ShouldSerialize*/Reset*) enabled
  102. </xsl:if><xsl:if test="not($optionFullFramework)">
  103. // Option: light framework (CF/Silverlight) enabled
  104. </xsl:if><xsl:if test="$optionProtoRpc">
  105. // Option: proto-rpc enabled
  106. </xsl:if>
  107. <xsl:call-template name="WriteUsings">
  108. <xsl:with-param name="ns" select="$import"/>
  109. </xsl:call-template>
  110. <xsl:apply-templates select="file/FileDescriptorProto"/>
  111. </xsl:template>
  112. <xsl:template match="FileDescriptorProto">
  113. // Generated from: <xsl:value-of select="name"/>
  114. <xsl:apply-templates select="dependency/string[.!='']"/>
  115. <xsl:variable name="namespace"><xsl:call-template name="PickNamespace">
  116. <xsl:with-param name="defaultNamespace" select="$defaultNamespace"/>
  117. </xsl:call-template>
  118. </xsl:variable>
  119. <xsl:if test="string($namespace) != ''">
  120. namespace <xsl:value-of select="translate($namespace,':-/\','__..')"/>
  121. {</xsl:if>
  122. <xsl:apply-templates select="message_type | enum_type | service"/>
  123. <xsl:if test="string($namespace) != ''">
  124. }</xsl:if></xsl:template>
  125. <xsl:template match="FileDescriptorProto/dependency/string">
  126. // Note: requires additional types generated from: <xsl:value-of select="."/></xsl:template>
  127. <xsl:template name="camel">
  128. <xsl:param name="value" select="name"/>
  129. <xsl:param name="delimiter" select="'_'"/>
  130. <xsl:choose>
  131. <xsl:when test="$optionFixCase"><xsl:call-template name="toCamelCase">
  132. <xsl:with-param name="value" select="$value"/>
  133. <xsl:with-param name="delimiter" select="$delimiter"/>
  134. </xsl:call-template></xsl:when>
  135. <xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
  136. </xsl:choose>
  137. </xsl:template>
  138. <xsl:template match="DescriptorProto">
  139. [<xsl:if test="$optionFullFramework">global::System.Serializable, </xsl:if>global::ProtoBuf.ProtoContract(Name=@"<xsl:value-of select="name"/>")]
  140. <xsl:if test="$optionDataContract">[global::System.Runtime.Serialization.DataContract(Name=@"<xsl:value-of select="name"/>")]
  141. </xsl:if><xsl:if test="$optionXml">[global::System.Xml.Serialization.XmlType(TypeName=@"<xsl:value-of select="name"/>")]
  142. </xsl:if><!--
  143. -->public partial class <xsl:call-template name="pascal"/> : global::ProtoBuf.IExtensible<!--
  144. --><xsl:if test="$optionBinary">, global::System.Runtime.Serialization.ISerializable</xsl:if><!--
  145. --><xsl:if test="$optionObservable">, global::System.ComponentModel.INotifyPropertyChanged</xsl:if><!--
  146. --><xsl:if test="$optionPreObservable">, global::System.ComponentModel.INotifyPropertyChanging</xsl:if>
  147. {
  148. public <xsl:call-template name="pascal"/>() {}
  149. <xsl:apply-templates select="*"/><xsl:if test="$optionBinary">
  150. protected <xsl:call-template name="pascal"/>(global::System.Runtime.Serialization.SerializationInfo info, global::System.Runtime.Serialization.StreamingContext context)
  151. : this() { global::ProtoBuf.Serializer.Merge(info, this); }
  152. void global::System.Runtime.Serialization.ISerializable.GetObjectData(global::System.Runtime.Serialization.SerializationInfo info, global::System.Runtime.Serialization.StreamingContext context)
  153. { global::ProtoBuf.Serializer.Serialize(info, this); }
  154. </xsl:if><xsl:if test="$optionObservable">
  155. public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
  156. protected virtual void OnPropertyChanged(string propertyName)
  157. { if(PropertyChanged != null) PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(propertyName)); }
  158. </xsl:if><xsl:if test="$optionPreObservable">
  159. public event global::System.ComponentModel.PropertyChangingEventHandler PropertyChanging;
  160. protected virtual void OnPropertyChanging(string propertyName)
  161. { if(PropertyChanging != null) PropertyChanging(this, new global::System.ComponentModel.PropertyChangingEventArgs(propertyName)); }
  162. </xsl:if>
  163. private global::ProtoBuf.IExtension extensionObject;
  164. global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
  165. { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }
  166. }
  167. </xsl:template>
  168. <xsl:template match="DescriptorProto/name | DescriptorProto/extension_range | DescriptorProto/extension"/>
  169. <xsl:template match="
  170. FileDescriptorProto/message_type | FileDescriptorProto/enum_type | FileDescriptorProto/service
  171. | DescriptorProto/enum_type | DescriptorProto/message_type
  172. | DescriptorProto/nested_type | EnumDescriptorProto/value | ServiceDescriptorProto/method">
  173. <xsl:apply-templates select="*"/>
  174. </xsl:template>
  175. <xsl:template match="DescriptorProto/field">
  176. <xsl:apply-templates select="*"/>
  177. <xsl:variable name="extName" select="concat('.',(ancestor::FileDescriptorProto/package)[1],'.',../name)"/>
  178. <xsl:apply-templates select="//FieldDescriptorProto[extendee=$extName]"/>
  179. </xsl:template>
  180. <xsl:template match="EnumDescriptorProto">
  181. [global::ProtoBuf.ProtoContract(Name=@"<xsl:value-of select="name"/>")]
  182. <xsl:if test="$optionDataContract">[global::System.Runtime.Serialization.DataContract(Name=@"<xsl:value-of select="name"/>")]
  183. </xsl:if>
  184. <xsl:if test="$optionXml">[global::System.Xml.Serialization.XmlType(TypeName=@"<xsl:value-of select="name"/>")]
  185. </xsl:if><!--
  186. -->public enum <xsl:call-template name="pascal"/>
  187. {
  188. <xsl:apply-templates select="value"/>
  189. }
  190. </xsl:template>
  191. <xsl:template match="EnumValueDescriptorProto">
  192. <xsl:variable name="value"><xsl:choose>
  193. <xsl:when test="number"><xsl:value-of select="number"/></xsl:when>
  194. <xsl:otherwise>0</xsl:otherwise>
  195. </xsl:choose></xsl:variable>
  196. [global::ProtoBuf.ProtoEnum(Name=@"<xsl:value-of select="name"/>", Value=<xsl:value-of select="$value"/>)]<!--
  197. --><xsl:if test="$optionDataContract">
  198. [global::System.Runtime.Serialization.EnumMember(Value=@"<xsl:value-of select="name"/>")]</xsl:if><!--
  199. --><xsl:if test="$optionXml">
  200. [global::System.Xml.Serialization.XmlEnum(@"<xsl:value-of select="name"/>")]</xsl:if><!--
  201. --><xsl:text disable-output-escaping="yes">
  202. </xsl:text><xsl:call-template name="pascal"/><xsl:text xml:space="preserve"> = </xsl:text><xsl:value-of select="$value"/><xsl:if test="position()!=last()">,
  203. </xsl:if>
  204. </xsl:template>
  205. <xsl:template match="FieldDescriptorProto" mode="field">
  206. <xsl:variable name="field"><xsl:choose>
  207. <xsl:when test="$optionFixCase"><xsl:call-template name="toCamelCase">
  208. <xsl:with-param name="value" select="name"/>
  209. </xsl:call-template></xsl:when>
  210. <xsl:otherwise><xsl:value-of select="name"/></xsl:otherwise>
  211. </xsl:choose></xsl:variable>
  212. <xsl:call-template name="escapeKeyword">
  213. <xsl:with-param name="value"><xsl:choose>
  214. <xsl:when test="not(key('fieldNames',concat('_',$field)))"><xsl:value-of select="concat('_',$field)"/></xsl:when>
  215. <xsl:when test="not(key('fieldNames',concat($field,'Field')))"><xsl:value-of select="concat($field,'Field')"/></xsl:when>
  216. <xsl:otherwise><xsl:value-of select="concat('_',generate-id())"/></xsl:otherwise>
  217. </xsl:choose></xsl:with-param>
  218. </xsl:call-template>
  219. </xsl:template>
  220. <xsl:template name="escapeKeyword">
  221. <xsl:param name="value"/>
  222. <xsl:if test="contains($keywords,concat('|',$value,'|'))">@</xsl:if><xsl:value-of select="$value"/>
  223. </xsl:template>
  224. <xsl:variable name="keywords">|abstract|as|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|do|double|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|goto|if|implicit|in|int|interface|internal|is|lock|long|namespace|new|null|object|operator|out|override|params|private|protected|public|readonly|ref|return|sbyte|sealed|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|virtual|void|volatile|while|</xsl:variable>
  225. <xsl:template match="FieldDescriptorProto" mode="format">
  226. <xsl:choose>
  227. <xsl:when test="type='TYPE_DOUBLE' or type='TYPE_FLOAT'
  228. or type='TYPE_FIXED32' or type='TYPE_FIXED64'
  229. or type='TYPE_SFIXED32' or type='TYPE_SFIXED64'">FixedSize</xsl:when>
  230. <xsl:when test="type='TYPE_GROUP'">Group</xsl:when>
  231. <xsl:when test="not(type) or type='TYPE_INT32' or type='TYPE_INT64'
  232. or type='TYPE_UINT32' or type='TYPE_UINT64'
  233. or type='TYPE_ENUM'">TwosComplement</xsl:when>
  234. <xsl:when test="type='TYPE_SINT32' or type='TYPE_SINT64'">ZigZag</xsl:when>
  235. <xsl:otherwise>Default</xsl:otherwise>
  236. </xsl:choose>
  237. </xsl:template>
  238. <xsl:template match="FieldDescriptorProto" mode="primitiveType">
  239. <xsl:choose>
  240. <xsl:when test="not(type)">struct</xsl:when>
  241. <xsl:when test="type='TYPE_DOUBLE'">struct</xsl:when>
  242. <xsl:when test="type='TYPE_FLOAT'">struct</xsl:when>
  243. <xsl:when test="type='TYPE_INT64'">struct</xsl:when>
  244. <xsl:when test="type='TYPE_UINT64'">struct</xsl:when>
  245. <xsl:when test="type='TYPE_INT32'">struct</xsl:when>
  246. <xsl:when test="type='TYPE_FIXED64'">struct</xsl:when>
  247. <xsl:when test="type='TYPE_FIXED32'">struct</xsl:when>
  248. <xsl:when test="type='TYPE_BOOL'">struct</xsl:when>
  249. <xsl:when test="type='TYPE_STRING'">class</xsl:when>
  250. <xsl:when test="type='TYPE_BYTES'">class</xsl:when>
  251. <xsl:when test="type='TYPE_UINT32'">struct</xsl:when>
  252. <xsl:when test="type='TYPE_SFIXED32'">struct</xsl:when>
  253. <xsl:when test="type='TYPE_SFIXED64'">struct</xsl:when>
  254. <xsl:when test="type='TYPE_SINT32'">struct</xsl:when>
  255. <xsl:when test="type='TYPE_SINT64'">struct</xsl:when>
  256. <xsl:when test="type='TYPE_ENUM'">struct</xsl:when>
  257. <xsl:when test="type='TYPE_GROUP' or type='TYPE_MESSAGE'">none</xsl:when>
  258. <xsl:otherwise>
  259. <xsl:message terminate="yes">
  260. Field type not implemented: <xsl:value-of select="type"/> (<xsl:value-of select="../../name"/>.<xsl:value-of select="name"/>)
  261. </xsl:message>
  262. </xsl:otherwise>
  263. </xsl:choose>
  264. </xsl:template>
  265. <xsl:template match="FieldDescriptorProto" mode="type">
  266. <xsl:choose>
  267. <xsl:when test="not(type)">double</xsl:when>
  268. <xsl:when test="type='TYPE_DOUBLE'">double</xsl:when>
  269. <xsl:when test="type='TYPE_FLOAT'">float</xsl:when>
  270. <xsl:when test="type='TYPE_INT64'">long</xsl:when>
  271. <xsl:when test="type='TYPE_UINT64'">ulong</xsl:when>
  272. <xsl:when test="type='TYPE_INT32'">int</xsl:when>
  273. <xsl:when test="type='TYPE_FIXED64'">ulong</xsl:when>
  274. <xsl:when test="type='TYPE_FIXED32'">uint</xsl:when>
  275. <xsl:when test="type='TYPE_BOOL'">bool</xsl:when>
  276. <xsl:when test="type='TYPE_STRING'">string</xsl:when>
  277. <xsl:when test="type='TYPE_BYTES'">byte[]</xsl:when>
  278. <xsl:when test="type='TYPE_UINT32'">uint</xsl:when>
  279. <xsl:when test="type='TYPE_SFIXED32'">int</xsl:when>
  280. <xsl:when test="type='TYPE_SFIXED64'">long</xsl:when>
  281. <xsl:when test="type='TYPE_SINT32'">int</xsl:when>
  282. <xsl:when test="type='TYPE_SINT64'">long</xsl:when>
  283. <xsl:when test="type='TYPE_GROUP' or type='TYPE_MESSAGE' or type='TYPE_ENUM'"><xsl:call-template name="pascal">
  284. <xsl:with-param name="value" select="substring-after(type_name,'.')"/>
  285. </xsl:call-template></xsl:when>
  286. <xsl:otherwise>
  287. <xsl:message terminate="yes">
  288. Field type not implemented: <xsl:value-of select="type"/> (<xsl:value-of select="../../name"/>.<xsl:value-of select="name"/>)
  289. </xsl:message>
  290. </xsl:otherwise>
  291. </xsl:choose>
  292. </xsl:template>
  293. <xsl:template match="FieldDescriptorProto[default_value]" mode="defaultValue">
  294. <xsl:choose>
  295. <xsl:when test="type='TYPE_STRING'">@"<xsl:value-of select="default_value"/>"</xsl:when>
  296. <xsl:when test="type='TYPE_ENUM'"><xsl:apply-templates select="." mode="type"/>.<xsl:call-template name="pascal">
  297. <xsl:with-param name="value" select="default_value"/>
  298. </xsl:call-template></xsl:when>
  299. <xsl:when test="type='TYPE_BYTES'"> /*
  300. <xsl:value-of select="default_value"/>
  301. */ null </xsl:when>
  302. <xsl:otherwise>(<xsl:apply-templates select="." mode="type"/>)<xsl:value-of select="default_value"/></xsl:otherwise>
  303. </xsl:choose>
  304. </xsl:template>
  305. <!--
  306. We need to find the first enum value given .foo.bar.SomeEnum - but the enum itself
  307. only knows about SomeEnum; we need to look at all parent DescriptorProto nodes, and
  308. the FileDescriptorProto for the namespace.
  309. This does an annoying up/down recursion... a bit expensive, but *generally* OK.
  310. Could perhaps index the last part of the enum name to reduce overhead?
  311. -->
  312. <xsl:template name="GetFirstEnumValue">
  313. <xsl:variable name="hunt" select="type_name"/>
  314. <xsl:for-each select="//EnumDescriptorProto">
  315. <xsl:variable name="fullName">
  316. <xsl:for-each select="ancestor::FileDescriptorProto">.<xsl:value-of select="package"/></xsl:for-each>
  317. <xsl:for-each select="ancestor::DescriptorProto">.<xsl:value-of select="name"/></xsl:for-each>
  318. <xsl:value-of select="'.'"/>
  319. <xsl:call-template name="pascal"/>
  320. </xsl:variable>
  321. <xsl:if test="$fullName=$hunt"><xsl:value-of select="(value/EnumValueDescriptorProto)[1]/name"/></xsl:if>
  322. </xsl:for-each>
  323. </xsl:template>
  324. <xsl:template match="FieldDescriptorProto[not(default_value)]" mode="defaultValue">
  325. <xsl:choose>
  326. <xsl:when test="type='TYPE_STRING'">""</xsl:when>
  327. <xsl:when test="type='TYPE_MESSAGE'">null</xsl:when>
  328. <xsl:when test="type='TYPE_BYTES'">null</xsl:when>
  329. <xsl:when test="type='TYPE_ENUM'"><xsl:apply-templates select="." mode="type"/>.<xsl:call-template name="GetFirstEnumValue"/></xsl:when>
  330. <xsl:otherwise>default(<xsl:apply-templates select="." mode="type"/>)</xsl:otherwise>
  331. </xsl:choose>
  332. </xsl:template>
  333. <xsl:template match="FieldDescriptorProto" mode="checkDeprecated"><!--
  334. --><xsl:if test="options/deprecated='true'">global::System.Obsolete, </xsl:if><!--
  335. --></xsl:template>
  336. <xsl:template match="FieldDescriptorProto[label='LABEL_OPTIONAL' or not(label)]">
  337. <xsl:variable name="propType"><xsl:apply-templates select="." mode="type"/></xsl:variable>
  338. <xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
  339. <xsl:variable name="primitiveType"><xsl:apply-templates select="." mode="primitiveType"/></xsl:variable>
  340. <xsl:variable name="defaultValue"><xsl:apply-templates select="." mode="defaultValue"/></xsl:variable>
  341. <xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
  342. <xsl:variable name="specified" select="$optionDetectMissing and ($primitiveType='struct' or $primitiveType='class')"/>
  343. <xsl:variable name="fieldType"><xsl:value-of select="$propType"/><xsl:if test="$specified and $primitiveType='struct'">?</xsl:if></xsl:variable>
  344. private <xsl:value-of select="concat($fieldType,' ',$field)"/><xsl:if test="not($specified)"> = <xsl:value-of select="$defaultValue"/></xsl:if>;
  345. [<xsl:apply-templates select="." mode="checkDeprecated"/>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"/>)]<!--
  346. --><xsl:if test="not($specified)">
  347. [global::System.ComponentModel.DefaultValue(<xsl:value-of select="$defaultValue"/>)]</xsl:if><!--
  348. --><xsl:if test="$optionXml">
  349. [global::System.Xml.Serialization.XmlElement(@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>)]
  350. </xsl:if><xsl:if test="$optionDataContract">
  351. [global::System.Runtime.Serialization.DataMember(Name=@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>, IsRequired = false)]
  352. </xsl:if><xsl:call-template name="WriteGetSet">
  353. <xsl:with-param name="fieldType" select="$fieldType"/>
  354. <xsl:with-param name="propType" select="$propType"/>
  355. <xsl:with-param name="name"><xsl:call-template name="pascal"/></xsl:with-param>
  356. <xsl:with-param name="field" select="$field"/>
  357. <xsl:with-param name="defaultValue" select="$defaultValue"/>
  358. <xsl:with-param name="specified" select="$specified"/>
  359. </xsl:call-template>
  360. </xsl:template>
  361. <xsl:template match="FieldDescriptorProto[label='LABEL_REQUIRED']">
  362. <xsl:variable name="type"><xsl:apply-templates select="." mode="type"/></xsl:variable>
  363. <xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
  364. <xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
  365. private <xsl:value-of select="concat($type, ' ', $field)"/>;
  366. [<xsl:apply-templates select="." mode="checkDeprecated"/>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"/>)]<!--
  367. --><xsl:if test="$optionXml">
  368. [global::System.Xml.Serialization.XmlElement(@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>)]
  369. </xsl:if><xsl:if test="$optionDataContract">
  370. [global::System.Runtime.Serialization.DataMember(Name=@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>, IsRequired = true)]
  371. </xsl:if><xsl:call-template name="WriteGetSet">
  372. <xsl:with-param name="fieldType" select="$type"/>
  373. <xsl:with-param name="propType" select="$type"/>
  374. <xsl:with-param name="name"><xsl:call-template name="pascal"/></xsl:with-param>
  375. <xsl:with-param name="field" select="$field"/>
  376. </xsl:call-template>
  377. </xsl:template>
  378. <xsl:template name="stripKeyword">
  379. <xsl:param name="value"/>
  380. <xsl:choose>
  381. <xsl:when test="starts-with($value,'@')"><xsl:value-of select="substring-after($value,'@')"/></xsl:when>
  382. <xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
  383. </xsl:choose>
  384. </xsl:template>
  385. <xsl:template name="WriteGetSet">
  386. <xsl:param name="fieldType"/>
  387. <xsl:param name="propType"/>
  388. <xsl:param name="name"/>
  389. <xsl:param name="field"/>
  390. <xsl:param name="specified" select="false()"/>
  391. <xsl:param name="defaultValue"/>
  392. <xsl:variable name="nameNoKeyword">
  393. <xsl:call-template name="stripKeyword">
  394. <xsl:with-param name="value" select="$name"/>
  395. </xsl:call-template></xsl:variable>
  396. public <xsl:value-of select="concat($propType,' ',$name)"/>
  397. {
  398. get { return <xsl:value-of select="$field"/> <xsl:if test="$specified">?? <xsl:value-of select="$defaultValue"/></xsl:if>; }
  399. set { <xsl:if test="$optionPartialMethods">On<xsl:value-of select="$nameNoKeyword"/>Changing(value); </xsl:if><xsl:if test="$optionPreObservable">OnPropertyChanging(@"<xsl:value-of select="$nameNoKeyword"/>"); </xsl:if><xsl:value-of select="$field"/> = value; <xsl:if test="$optionObservable">OnPropertyChanged(@"<xsl:value-of select="$nameNoKeyword"/>"); </xsl:if><xsl:if test="$optionPartialMethods">On<xsl:value-of select="$nameNoKeyword"/>Changed();</xsl:if>}
  400. }<xsl:if test="$optionPartialMethods">
  401. partial void On<xsl:value-of select="$nameNoKeyword"/>Changing(<xsl:value-of select="$propType"/> value);
  402. partial void On<xsl:value-of select="$nameNoKeyword"/>Changed();</xsl:if><xsl:if test="$specified">
  403. [global::System.Xml.Serialization.XmlIgnore]
  404. <xsl:if test="$optionFullFramework">[global::System.ComponentModel.Browsable(false)]</xsl:if>
  405. public bool <xsl:value-of select="$nameNoKeyword"/>Specified
  406. {
  407. get { return <xsl:value-of select="$field"/> != null; }
  408. set { if (value == (<xsl:value-of select="$field"/>== null)) <xsl:value-of select="$field"/> = value ? <xsl:value-of select="$name"/> : (<xsl:value-of select="$fieldType"/>)null; }
  409. }
  410. private bool ShouldSerialize<xsl:value-of select="$nameNoKeyword"/>() { return <xsl:value-of select="$nameNoKeyword"/>Specified; }
  411. private void Reset<xsl:value-of select="$nameNoKeyword"/>() { <xsl:value-of select="$nameNoKeyword"/>Specified = false; }
  412. </xsl:if>
  413. </xsl:template>
  414. <xsl:template match="FieldDescriptorProto[label='LABEL_REPEATED']">
  415. <xsl:variable name="type"><xsl:apply-templates select="." mode="type"/></xsl:variable>
  416. <xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
  417. <xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
  418. private <xsl:if test="not($optionXml)">readonly</xsl:if> global::System.Collections.Generic.List&lt;<xsl:value-of select="$type" />&gt; <xsl:value-of select="$field"/> = new global::System.Collections.Generic.List&lt;<xsl:value-of select="$type"/>&gt;();
  419. [<xsl:apply-templates select="." mode="checkDeprecated"/>global::ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, Name=@"<xsl:value-of select="name"/>", DataFormat = global::ProtoBuf.DataFormat.<xsl:value-of select="$format"/><xsl:if test="options/packed='true'">, Options = global::ProtoBuf.MemberSerializationOptions.Packed</xsl:if>)]<!--
  420. --><xsl:if test="$optionDataContract">
  421. [global::System.Runtime.Serialization.DataMember(Name=@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>, IsRequired = false)]
  422. </xsl:if><xsl:if test="$optionXml">
  423. [global::System.Xml.Serialization.XmlElement(@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>)]
  424. </xsl:if>
  425. public global::System.Collections.Generic.List&lt;<xsl:value-of select="$type" />&gt; <xsl:call-template name="pascal"/>
  426. {
  427. get { return <xsl:value-of select="$field"/>; }<!--
  428. --><xsl:if test="$optionXml">
  429. set { <xsl:value-of select="$field"/> = value; }</xsl:if>
  430. }
  431. </xsl:template>
  432. <xsl:template match="ServiceDescriptorProto">
  433. <xsl:if test="($optionClientProxy or $optionDataContract)">
  434. [global::System.ServiceModel.ServiceContract(Name = @"<xsl:value-of select="name"/>")]</xsl:if>
  435. public interface I<xsl:value-of select="name"/>
  436. {
  437. <xsl:apply-templates select="method"/>
  438. }
  439. <xsl:if test="$optionProtoRpc">
  440. public class <xsl:value-of select="name"/>Client : global::ProtoBuf.ServiceModel.RpcClient
  441. {
  442. public <xsl:value-of select="name"/>Client() : base(typeof(I<xsl:value-of select="name"/>)) { }
  443. <xsl:apply-templates select="method/MethodDescriptorProto" mode="protoRpc"/>
  444. }
  445. </xsl:if>
  446. <xsl:apply-templates select="." mode="clientProxy"/>
  447. </xsl:template>
  448. <xsl:template match="MethodDescriptorProto">
  449. <xsl:if test="($optionClientProxy or $optionDataContract)">
  450. [global::System.ServiceModel.OperationContract(Name = @"<xsl:value-of select="name"/>")]
  451. <xsl:if test="$optionFullFramework">[global::ProtoBuf.ServiceModel.ProtoBehavior]</xsl:if>
  452. </xsl:if>
  453. <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);
  454. <xsl:if test="$optionAsynchronous and ($optionClientProxy or $optionDataContract)">
  455. [global::System.ServiceModel.OperationContract(AsyncPattern = true, Name = @"<xsl:value-of select="name"/>")]
  456. global::System.IAsyncResult Begin<xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request, global::System.AsyncCallback callback, object state);
  457. <xsl:apply-templates select="output_type"/> End<xsl:value-of select="name"/>(global::System.IAsyncResult ar);
  458. </xsl:if>
  459. </xsl:template>
  460. <xsl:template match="MethodDescriptorProto" mode="protoRpc">
  461. <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)
  462. {
  463. return (<xsl:apply-templates select="output_type"/>) Send(@"<xsl:value-of select="name"/>", request);
  464. }
  465. </xsl:template>
  466. <xsl:template match="MethodDescriptorProto/input_type | MethodDescriptorProto/output_type">
  467. <xsl:value-of select="substring-after(.,'.')"/>
  468. </xsl:template>
  469. <xsl:template match="MethodDescriptorProto" mode="CompleteEvent">
  470. <xsl:if test="$optionAsynchronous and $optionDataContract">
  471. public partial class <xsl:value-of select="name"/>CompletedEventArgs : global::System.ComponentModel.AsyncCompletedEventArgs
  472. {
  473. private object[] results;
  474. public <xsl:value-of select="name"/>CompletedEventArgs(object[] results, global::System.Exception exception, bool cancelled, object userState)
  475. : base(exception, cancelled, userState)
  476. {
  477. this.results = results;
  478. }
  479. public <xsl:apply-templates select="output_type"/> Result
  480. {
  481. get {
  482. base.RaiseExceptionIfNecessary();
  483. return (<xsl:apply-templates select="output_type"/>)(this.results[0]);
  484. }
  485. }
  486. }
  487. </xsl:if>
  488. </xsl:template>
  489. <xsl:template match="ServiceDescriptorProto" mode="clientProxy">
  490. <xsl:if test="$optionAsynchronous and $optionDataContract and $optionClientProxy">
  491. <xsl:apply-templates select="method/MethodDescriptorProto" mode="CompleteEvent"/>
  492. [global::System.Diagnostics.DebuggerStepThroughAttribute()]
  493. public partial class <xsl:value-of select="name"/>Client : global::System.ServiceModel.ClientBase&lt;I<xsl:value-of select="name"/>&gt;, I<xsl:value-of select="name"/>
  494. {
  495. public <xsl:value-of select="name"/>Client()
  496. {}
  497. public <xsl:value-of select="name"/>Client(string endpointConfigurationName)
  498. : base(endpointConfigurationName)
  499. {}
  500. public <xsl:value-of select="name"/>Client(string endpointConfigurationName, string remoteAddress)
  501. : base(endpointConfigurationName, remoteAddress)
  502. {}
  503. public <xsl:value-of select="name"/>Client(string endpointConfigurationName, global::System.ServiceModel.EndpointAddress remoteAddress)
  504. : base(endpointConfigurationName, remoteAddress)
  505. {}
  506. public <xsl:value-of select="name"/>Client(global::System.ServiceModel.Channels.Binding binding, global::System.ServiceModel.EndpointAddress remoteAddress)
  507. : base(binding, remoteAddress)
  508. {}
  509. <xsl:apply-templates select="method/MethodDescriptorProto" mode="clientProxy"/>
  510. }
  511. </xsl:if>
  512. </xsl:template>
  513. <xsl:template match="MethodDescriptorProto" mode="clientProxy">
  514. <xsl:if test="$optionAsynchronous and $optionDataContract and $optionClientProxy">
  515. private BeginOperationDelegate onBegin<xsl:value-of select="name"/>Delegate;
  516. private EndOperationDelegate onEnd<xsl:value-of select="name"/>Delegate;
  517. private global::System.Threading.SendOrPostCallback on<xsl:value-of select="name"/>CompletedDelegate;
  518. public event global::System.EventHandler&lt;<xsl:value-of select="name"/>CompletedEventArgs&gt; <xsl:value-of select="name"/>Completed;
  519. 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)
  520. {
  521. return base.Channel.<xsl:value-of select="name"/>(request);
  522. }
  523. [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
  524. public global::System.IAsyncResult Begin<xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request, global::System.AsyncCallback callback, object asyncState)
  525. {
  526. return base.Channel.Begin<xsl:value-of select="name"/>(request, callback, asyncState);
  527. }
  528. [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
  529. public <xsl:apply-templates select="output_type"/> End<xsl:value-of select="name"/>(global::System.IAsyncResult result)
  530. {
  531. return base.Channel.End<xsl:value-of select="name"/>(result);
  532. }
  533. private global::System.IAsyncResult OnBegin<xsl:value-of select="name"/>(object[] inValues, global::System.AsyncCallback callback, object asyncState)
  534. {
  535. <xsl:apply-templates select="input_type"/> request = ((<xsl:apply-templates select="input_type"/>)(inValues[0]));
  536. return this.Begin<xsl:value-of select="name"/>(request, callback, asyncState);
  537. }
  538. private object[] OnEnd<xsl:value-of select="name"/>(global::System.IAsyncResult result)
  539. {
  540. <xsl:apply-templates select="output_type"/> retVal = this.End<xsl:value-of select="name"/>(result);
  541. return new object[] {
  542. retVal};
  543. }
  544. private void On<xsl:value-of select="name"/>Completed(object state)
  545. {
  546. if ((this.<xsl:value-of select="name"/>Completed != null))
  547. {
  548. InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
  549. this.<xsl:value-of select="name"/>Completed(this, new <xsl:value-of select="name"/>CompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
  550. }
  551. }
  552. public void <xsl:value-of select="name"/>Async(<xsl:apply-templates select="input_type"/> request)
  553. {
  554. this.<xsl:value-of select="name"/>Async(request, null);
  555. }
  556. public void <xsl:value-of select="name"/>Async(<xsl:apply-templates select="input_type"/> request, object userState)
  557. {
  558. if ((this.onBegin<xsl:value-of select="name"/>Delegate == null))
  559. {
  560. this.onBegin<xsl:value-of select="name"/>Delegate = new BeginOperationDelegate(this.OnBegin<xsl:value-of select="name"/>);
  561. }
  562. if ((this.onEnd<xsl:value-of select="name"/>Delegate == null))
  563. {
  564. this.onEnd<xsl:value-of select="name"/>Delegate = new EndOperationDelegate(this.OnEnd<xsl:value-of select="name"/>);
  565. }
  566. if ((this.on<xsl:value-of select="name"/>CompletedDelegate == null))
  567. {
  568. this.on<xsl:value-of select="name"/>CompletedDelegate = new global::System.Threading.SendOrPostCallback(this.On<xsl:value-of select="name"/>Completed);
  569. }
  570. base.InvokeAsync(this.onBegin<xsl:value-of select="name"/>Delegate, new object[] {
  571. request}, this.onEnd<xsl:value-of select="name"/>Delegate, this.on<xsl:value-of select="name"/>CompletedDelegate, userState);
  572. }
  573. </xsl:if>
  574. </xsl:template>
  575. </xsl:stylesheet>