本文整理汇总了VB.NET中System.Resources.ResourceReader类的典型用法代码示例。如果您正苦于以下问题:VB.NET ResourceReader类的具体用法?VB.NET ResourceReader怎么用?VB.NET ResourceReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceReader类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1:
' Instantiate a standalone .resources file from its filename.
Dim rr1 As New System.Resources.ResourceReader("Resources1.resources")
' Instantiate a standalone .resources file from a stream.
Dim fs As New System.IO.FileStream(".\Resources2.resources",
System.IO.FileMode.Open)
Dim rr2 As New System.Resources.ResourceReader(fs)
示例2:
Dim assem As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(".\MyLibrary.dll")
Dim fs As System.IO.Stream =
assem.GetManifestResourceStream("MyCompany.LibraryResources.resources")
Dim rr As New System.Resources.ResourceReader(fs)
示例3: Example
' 导入命名空间
Imports System.Collections
Imports System.Resources
Module Example
Public Sub Main()
Console.WriteLine("Resources in ApplicationResources.resources:")
Dim res As New ResourceReader(".\ApplicationResources.resources")
Dim dict As IDictionaryEnumerator = res.GetEnumerator()
Do While dict.MoveNext()
Console.WriteLine(" {0}: '{1}' (Type {2})", dict.Key, dict.Value, dict.Value.GetType().Name)
Loop
res.Close()
End Sub
End Module
输出:
Resources in ApplicationResources.resources: Label3: '"Last Name:"' (Type String) Label2: '"Middle Name:"' (Type String) Label1: '"First Name:"' (Type String) Label7: '"State:"' (Type String) Label6: '"City:"' (Type String) Label5: '"Street Address:"' (Type String) Label4: '"SSN:"' (Type String) Label9: '"Home Phone:"' (Type String) Label8: '"Zip Code:"' (Type String) Title: '"Contact Information"' (Type String) Label12: '"Other Phone:"' (Type String) Label13: '"Fax:"' (Type String) Label10: '"Business Phone:"' (Type String) Label11: '"Mobile Phone:"' (Type String) Label14: '"Email Address:"' (Type String) Label15: '"Alternate Email Address:"' (Type String)
示例4: New
<Serializable> Public Structure DateTimeTZI
Dim [Date] As DateTime
Dim TimeZone As TimeZoneInfo
Public Sub New([date] As DateTime, tz As TimeZoneInfo)
Me.[Date] = [date]
Me.TimeZone = tz
End Sub
Public Overrides Function ToString() As String
Return String.Format("{0:dd/MM/yyyy hh:mm:ss tt} {1}",
[Date], TimeZone.StandardName)
End Function
End Structure
示例5: Main
' 导入命名空间
Imports System.Drawing
Imports System.IO
Imports System.Resources
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Text
Module Example
Public Sub Main()
' Bitmap as stream.
Dim bitmapStream As New MemoryStream()
Dim bmp As New Bitmap(".\ContactsIcon.jpg")
bmp.Save(bitmapStream, Imaging.ImageFormat.jpeg)
' Define resources to be written.
Using rw As New ResourceWriter(".\ContactResources.resources")
rw.AddResource("Title", "Contact List")
rw.AddResource("NColumns", 5)
rw.AddResource("Icon", bitmapStream)
rw.AddResource("Header1", "Name")
rw.AddResource("Header2", "City")
rw.AddResource("Header3", "State")
rw.AddResource("VersionDate", New DateTimeTZI(#05/18/2012#,
TimeZoneInfo.Local))
rw.AddResource("ClientVersion", True)
rw.Generate()
End Using
End Sub
End Module
示例6: Example
' 导入命名空间
Imports System.Collections
Imports System.Drawing
Imports System.IO
Imports System.Resources
Imports System.Runtime.Serialization.Formatters.Binary
Module Example
Public Sub Main()
Dim rdr As New ResourceReader(".\ContactResources.resources")
Dim dict As IDictionaryEnumerator = rdr.GetEnumerator()
Do While dict.MoveNext()
Console.WriteLine("Resource Name: {0}", dict.Key)
Try
Console.WriteLine(" Value: {0}", dict.Value)
Catch e As FileNotFoundException
Console.WriteLine(" Exception: A file cannot be found.")
DisplayResourceInfo(rdr, CStr(dict.Key), False)
Catch e As FormatException
Console.WriteLine(" Exception: Corrupted data.")
DisplayResourceInfo(rdr, CStr(dict.Key), True)
Catch e As TypeLoadException
Console.WriteLine(" Exception: Cannot load the data type.")
DisplayResourceInfo(rdr, CStr(dict.Key), False)
End Try
Loop
End Sub
Private Sub DisplayResourceInfo(rr As ResourceReader,
key As String, loaded As Boolean)
Dim dataType As String = Nothing
Dim data() As Byte = Nothing
rr.GetResourceData(key, dataType, data)
' Display the data type.
Console.WriteLine(" Data Type: {0}", dataType)
' Display the bytes that form the available data.
Console.Write(" Data: ")
Dim lines As Integer = 0
For Each dataItem In data
lines += 1
Console.Write("{0:X2} ", dataItem)
If lines Mod 25 = 0 Then Console.Write("{0} ", vbCrLf)
Next
Console.WriteLine()
' Try to recreate current state of data.
' Do: Bitmap, DateTimeTZI
Select Case dataType
' Handle internally serialized string data (ResourceTypeCode members).
Case "ResourceTypeCode.String"
Dim reader As New BinaryReader(New MemoryStream(data))
Dim binData As String = reader.ReadString()
Console.WriteLine(" Recreated Value: {0}", binData)
Case "ResourceTypeCode.Int32"
Console.WriteLine(" Recreated Value: {0}",
BitConverter.ToInt32(data, 0))
Case "ResourceTypeCode.Boolean"
Console.WriteLine(" Recreated Value: {0}",
BitConverter.ToBoolean(data, 0))
' .jpeg image stored as a stream.
Case "ResourceTypeCode.Stream"
Const OFFSET As Integer = 4
Dim size As Integer = BitConverter.ToInt32(data, 0)
Dim value As New Bitmap(New MemoryStream(data, OFFSET, size))
Console.WriteLine(" Recreated Value: {0}", value)
' Our only other type is DateTimeTZI.
Case Else
' No point in deserializing data if the type is unavailable.
If dataType.Contains("DateTimeTZI") And loaded Then
Dim binFmt As New BinaryFormatter()
Dim value As Object = binFmt.Deserialize(New MemoryStream(data))
Console.WriteLine(" Recreated Value: {0}", value)
End If
End Select
Console.WriteLine()
End Sub
End Module