@@ -64,8 +64,9 @@ public static bool Is64BitProcess()
64
64
/// <summary>
65
65
/// Gets a content of the embedded resource as string
66
66
/// </summary>
67
- /// <param name="resourceName">Resource name</param>
68
- /// <param name="type">Type from assembly that containing an embedded resource</param>
67
+ /// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param>
68
+ /// <param name="type">The type, that determines the assembly and whose namespace is used to scope
69
+ /// the resource name</param>
69
70
/// <returns>Сontent of the embedded resource as string</returns>
70
71
public static string GetResourceAsString ( string resourceName , Type type )
71
72
{
@@ -89,26 +90,16 @@ public static string GetResourceAsString(string resourceName, Type type)
89
90
90
91
Assembly assembly = type . GetTypeInfo ( ) . Assembly ;
91
92
string nameSpace = type . Namespace ;
93
+ string resourceFullName = nameSpace != null ? nameSpace + "." + resourceName : resourceName ;
92
94
93
- if ( nameSpace != null && resourceName . StartsWith ( nameSpace , StringComparison . Ordinal ) )
94
- {
95
- using ( Stream stream = assembly . GetManifestResourceStream ( resourceName ) )
96
- {
97
- return ReadResourceAsString ( resourceName , stream ) ;
98
- }
99
- }
100
-
101
- using ( Stream stream = assembly . GetManifestResourceStream ( type , resourceName ) )
102
- {
103
- return ReadResourceAsString ( resourceName , stream ) ;
104
- }
95
+ return InnerGetResourceAsString ( resourceFullName , assembly ) ;
105
96
}
106
97
107
98
/// <summary>
108
99
/// Gets a content of the embedded resource as string
109
100
/// </summary>
110
- /// <param name="resourceName">Resource name</param>
111
- /// <param name="assembly">Assembly that containing an embedded resource</param>
101
+ /// <param name="resourceName">The case-sensitive resource name</param>
102
+ /// <param name="assembly">The assembly, which contains the embedded resource</param>
112
103
/// <returns>Сontent of the embedded resource as string</returns>
113
104
public static string GetResourceAsString ( string resourceName , Assembly assembly )
114
105
{
@@ -130,23 +121,23 @@ public static string GetResourceAsString(string resourceName, Assembly assembly)
130
121
string . Format ( Strings . Common_ArgumentIsEmpty , "resourceName" ) , "resourceName" ) ;
131
122
}
132
123
133
- using ( Stream stream = assembly . GetManifestResourceStream ( resourceName ) )
134
- {
135
- return ReadResourceAsString ( resourceName , stream ) ;
136
- }
124
+ return InnerGetResourceAsString ( resourceName , assembly ) ;
137
125
}
138
126
139
- private static string ReadResourceAsString ( string resourceName , Stream stream )
127
+ private static string InnerGetResourceAsString ( string resourceName , Assembly assembly )
140
128
{
141
- if ( stream == null )
129
+ using ( Stream stream = assembly . GetManifestResourceStream ( resourceName ) )
142
130
{
143
- throw new NullReferenceException (
144
- string . Format ( Strings . Resources_ResourceIsNull , resourceName ) ) ;
145
- }
131
+ if ( stream == null )
132
+ {
133
+ throw new NullReferenceException (
134
+ string . Format ( Strings . Resources_ResourceIsNull , resourceName ) ) ;
135
+ }
146
136
147
- using ( var reader = new StreamReader ( stream ) )
148
- {
149
- return reader . ReadToEnd ( ) ;
137
+ using ( var reader = new StreamReader ( stream ) )
138
+ {
139
+ return reader . ReadToEnd ( ) ;
140
+ }
150
141
}
151
142
}
152
143
0 commit comments