本文整理汇总了C#中ResourceManager.GetStream方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceManager.GetStream方法的具体用法?C# ResourceManager.GetStream怎么用?C# ResourceManager.GetStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourceManager
的用法示例。
在下文中一共展示了ResourceManager.GetStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//.........这里部分代码省略.........
}
#if NET_2_0
rm = ResourceManager.CreateFileBasedResourceManager (
"FileComponentB.resources.resources",
AppDomain.CurrentDomain.BaseDirectory,
typeof (ResourceSet));
try {
rm.GetString ("$this.name");
Assert.Fail ("#H1");
} catch (MissingManifestResourceException ex) {
string expected = CreateMissingOnDisk (
"FileComponentB.resources.resources");
Assert.AreEqual (expected, ex.Message, "#H2");
}
#else
try {
ResourceManager.CreateFileBasedResourceManager (
"FileComponentB.resources.resources",
AppDomain.CurrentDomain.BaseDirectory,
typeof (ResourceSet));
Assert.Fail ("#I1");
} catch (ArgumentException ex) {
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#I2");
Assert.IsNull (ex.InnerException, "#I3");
Assert.IsNotNull (ex.Message, "#I4");
Assert.AreEqual (baseNameErrorMsg, ex.Message, "#I5");
Assert.IsNull (ex.ParamName, "#I6");
}
#endif
#if NET_2_0
rm = ResourceManager.CreateFileBasedResourceManager (
"FileComponentA.resources",
AppDomain.CurrentDomain.BaseDirectory,
typeof (ResourceSet));
try {
rm.GetString ("$this.name");
Assert.Fail ("#J1");
} catch (MissingManifestResourceException ex) {
string expected = CreateMissingOnDisk (
"FileComponentA.resources");
Assert.AreEqual (expected, ex.Message, "#J2");
}
#else
try {
ResourceManager.CreateFileBasedResourceManager (
"FileComponentA.resources",
AppDomain.CurrentDomain.BaseDirectory,
typeof (ResourceSet));
Assert.Fail ("#K1");
} catch (ArgumentException ex) {
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#K2");
Assert.IsNull (ex.InnerException, "#K3");
Assert.IsNotNull (ex.Message, "#K4");
Assert.AreEqual (baseNameErrorMsg, ex.Message, "#K5");
Assert.IsNull (ex.ParamName, "#K6");
}
#endif
rm = ResourceManager.CreateFileBasedResourceManager (
".resources",
AppDomain.CurrentDomain.BaseDirectory,
typeof (ResourceSet));
try {
rm.GetString ("$this.name");
Assert.Fail ("#L1");
} catch (MissingManifestResourceException ex) {
string expected = CreateMissingOnDisk (
".resources");
Assert.AreEqual (expected, ex.Message, "#J2");
}
rm = new ResourceManager (typeof (Mono.ResourceTest));
try {
rm.GetString ("$this.name");
Assert.Fail ("#M1");
} catch (MissingManifestResourceException ex) {
string expected = CreateMissingInAssembly (
typeof (Mono.ResourceTest));
Assert.AreEqual (expected, ex.Message, "#M2");
}
#if NET_2_0
rm = ResourceManager.CreateFileBasedResourceManager (
"DoesNotExist",
AppDomain.CurrentDomain.BaseDirectory,
typeof (ResourceSet));
try {
rm.GetStream ("$this.name");
Assert.Fail ("#N1");
} catch (MissingManifestResourceException ex) {
string expected = CreateMissingOnDisk (
"DoesNotExist");
Assert.AreEqual (expected, ex.Message, "#N2");
}
#endif
return 0;
}
示例2: GetStream
public static void GetStream()
{
var manager = new ResourceManager("System.Resources.Tests.Resources.TestResx.netstandard17", typeof(ResourceManagerTests).GetTypeInfo().Assembly);
var culture = new CultureInfo("en-US");
var expectedBytes = new byte[] { 41, 42, 43, 44, 192, 168, 1, 1 };
using (Stream stream = manager.GetStream("ByteStream"))
{
foreach (byte b in expectedBytes)
{
Assert.Equal(b, stream.ReadByte());
}
}
using (Stream stream = manager.GetStream("ByteStream", culture))
{
foreach (byte b in expectedBytes)
{
Assert.Equal(b, stream.ReadByte());
}
}
}