Skip to content

Commit 0f34090

Browse files
authored
Delete VB examples with BinaryFormatter (dotnet#9076)
1 parent 8d5e58d commit 0f34090

File tree

81 files changed

+24
-11369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+24
-11369
lines changed

snippets/visualbasic/System.DateTime/Persistence.vb

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ Module Persistence
2323
File.Delete(filenameXml)
2424

2525
File.Delete(filenameBin)
26-
PersistBinary()
27-
File.Delete(filenameBin)
28-
29-
SaveDateWithTimeZone()
30-
RestoreDateWithTimeZone()
3126
End Sub
3227

3328
' <Snippet1>
@@ -296,132 +291,6 @@ Module Persistence
296291

297292
Private Const filenameBin As String = ".\Dates.bin"
298293

299-
' <Snippet5>
300-
Public Sub PersistBinary()
301-
SaveDatesBinary()
302-
RestoreDatesBinary()
303-
End Sub
304-
305-
Private Sub SaveDatesBinary()
306-
Dim dates As Date() = {#6/14/2014 6:32AM#, #7/10/2014 11:49PM#,
307-
#1/10/2015 1:16AM#, #12/20/2014 9:45PM#,
308-
#6/2/2014 3:14PM#}
309-
Dim fs As New FileStream(filenameBin, FileMode.Create)
310-
Dim bin As New BinaryFormatter()
311-
312-
Console.WriteLine($"Current Time Zone: {TimeZoneInfo.Local.DisplayName}")
313-
Console.WriteLine("The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:")
314-
For ctr As Integer = 0 To dates.Length - 1
315-
Console.WriteLine(dates(ctr).ToString("f"))
316-
dates(ctr) = dates(ctr).ToUniversalTime()
317-
Next
318-
bin.Serialize(fs, dates)
319-
fs.Close()
320-
Console.WriteLine("Saved dates...")
321-
End Sub
322-
323-
Private Sub RestoreDatesBinary()
324-
TimeZoneInfo.ClearCachedData()
325-
Console.WriteLine("Current Time Zone: {TimeZoneInfo.Local.DisplayName}")
326-
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB")
327-
328-
Dim fs As New FileStream(filenameBin, FileMode.Open)
329-
Dim bin As New BinaryFormatter()
330-
Dim dates As DateTime() = DirectCast(bin.Deserialize(fs), Date())
331-
fs.Close()
332-
333-
Console.WriteLine("The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:")
334-
For Each value In dates
335-
Console.WriteLine(value.ToLocalTime().ToString("f"))
336-
Next
337-
Console.WriteLine("Restored dates...")
338-
End Sub
339-
' When saved on an en-US system, the example displays the following output:
340-
' Current Time Zone: (UTC-08:00) Pacific Time (US & Canada)
341-
' The dates on an en-US system:
342-
' Saturday, June 14, 2014 6:32 AM
343-
' Thursday, July 10, 2014 11:49 PM
344-
' Saturday, January 10, 2015 1:16 AM
345-
' Saturday, December 20, 2014 9:45 PM
346-
' Monday, June 02, 2014 3:14 PM
347-
' Saved dates...
348-
'
349-
' When restored on an en-GB system, the example displays the following output:
350-
' Current Time Zone: (UTC-6:00) Central Time (US & Canada)
351-
' The dates on an en-GB system:
352-
' 14 June 2014 08:32
353-
' 11 July 2014 01:49
354-
' 10 January 2015 03:16
355-
' 20 December 2014 11:45
356-
' 02 June 2014 17:14
357-
' Restored dates...
358-
' </Snippet5>
359-
360-
' <Snippet7>
361-
Public Sub SaveDateWithTimeZone()
362-
Dim dates As DateWithTimeZone() = {New DateWithTimeZone(#8/9/2014 7:30PM#,
363-
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")),
364-
New DateWithTimeZone(#8/15/2014 7:00PM#,
365-
TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")),
366-
New DateWithTimeZone(#8/22/2014 7:30PM#,
367-
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")),
368-
New DateWithTimeZone(#8/28/2014 7:00PM#,
369-
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"))}
370-
Dim fs As New FileStream(".\Schedule.bin", FileMode.Create)
371-
Dim formatter As New BinaryFormatter()
372-
Try
373-
formatter.Serialize(fs, dates)
374-
Catch e As SerializationException
375-
Console.WriteLine($"Serialization failed. Reason: {e.Message}")
376-
Finally
377-
If fs IsNot Nothing Then fs.Close()
378-
End Try
379-
' Display dates.
380-
For Each dateInfo In dates
381-
Dim tz As TimeZoneInfo = dateInfo.TimeZone
382-
Console.WriteLine($"{dateInfo.DateTime} {If(tz.IsDaylightSavingTime(dateInfo.DateTime), tz.DaylightName, tz.StandardName)}")
383-
Next
384-
End Sub
385-
' The example displays the following output:
386-
' 8/9/2014 7:30:00 PM Eastern Daylight Time
387-
' 8/15/2014 7:00:00 PM Pacific Daylight Time
388-
' 8/22/2014 7:30:00 PM Eastern Daylight Time
389-
' 8/28/2014 7:00:00 PM Eastern Daylight Time
390-
' </Snippet7>
391-
392294
Private Const filename As String = ".\Schedule.bin"
393295

394-
' <Snippet8>
395-
Public Sub RestoreDateWithTimeZone()
396-
Dim fs As FileStream
397-
If File.Exists(filename) Then
398-
fs = New FileStream(filename, FileMode.Open)
399-
Else
400-
Console.WriteLine("Unable to find file to deserialize.")
401-
Exit Sub
402-
End If
403-
404-
Dim formatter As New BinaryFormatter()
405-
Dim dates As DateWithTimeZone ()= Nothing
406-
Try
407-
dates = DirectCast(formatter.Deserialize(fs), DateWithTimeZone())
408-
' Display dates.
409-
For Each dateInfo In dates
410-
Dim tz As TimeZoneInfo = dateInfo.TimeZone
411-
Console.WriteLine($"{dateInfo.DateTime} {If(tz.IsDaylightSavingTime(dateInfo.DateTime), tz.DaylightName, tz.StandardName)}")
412-
Next
413-
Catch e As SerializationException
414-
Console.WriteLine("Deserialization failed. Reason: {e.Message}")
415-
Finally
416-
If fs IsNot Nothing Then fs.Close()
417-
End Try
418-
End Sub
419-
' The example displays the following output:
420-
' 8/9/2014 7:30:00 PM Eastern Daylight Time
421-
' 8/15/2014 7:00:00 PM Pacific Daylight Time
422-
' 8/22/2014 7:30:00 PM Eastern Daylight Time
423-
' 8/28/2014 7:00:00 PM Eastern Daylight Time
424-
' </Snippet8>
425-
426-
427296
End Module

snippets/visualbasic/VS_Snippets_CFX/isafeserializationdata/vb/makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

snippets/visualbasic/VS_Snippets_CFX/isafeserializationdata/vb/source.vb

Lines changed: 0 additions & 176 deletions
This file was deleted.

0 commit comments

Comments
 (0)