USER-DEFINED TYPES AND AGGREGATES } // parse the input Match m = vu.Match(s.Value); LDim d = new LDim(); // get the units // the string for units will have the proper // value because it was checked by the regex d.units = m.Result( ${u} ); // get the value. Again it will be a // floating point number, the regex // checked it d.value = double.Parse(m.Result( ${v} )); return d; } Notice that the regular expression used to test and parse the input is held in a static read-only member of LDim. There is a cost in constructing a regular expression, and putting it into a static member of the class means it need be constructed only once and can then be reused every time Parseis called. Once the input string has been validated as having the proper format, the regular expression is used again to crack out the value and the units. Notice that the double.Parse at the end of the implementation can never fail, because its input has already been validated as being a floating point number. Implementing IBinarySerialize Implementing IBinarySerialize is the most difficult part of creating a user-defined type. The implementation not only determines how an instance of a user-defined type will be saved on disk, it also determines how it will be sorted. IBinarySerialize is not implemented for user- defined types that set the SqlUserDefinedTypeAttribute Format property to Format.Native, which is the prime reason to use Nativewhen it is possible. The IBinarySerializeinterface has two methods: Read, which passes in a System.IO.BinaryReader, and Write, which passes in a System. IO.BinaryWriter. When SQL Server needs to read the data it has stored on disk for a user- defined type, it calls the Read method. The implementation of the Read method reads the stream, passes it through the BinaryReader, and reconstructs the state of the user-defined type. When SQL Server needs to write a user-defined type to disk, it calls the Write method, and the implementation of the Write method writes into the BinaryWriterthe state of the user-defined type.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

Bookmark the permalink.

Comments are closed.