{
Assembly assembly = type.Assembly;
- Stream stream = null;
-
- foreach (string str in assembly.GetManifestResourceNames())
- {
- string resourceClassName = str.Substring(0, str.LastIndexOf('.'));
- int index = resourceClassName.LastIndexOf('.');
- if (0 <= index && index < resourceClassName.Length)
- {
- resourceClassName = resourceClassName.Substring(index + 1);
-
- if (resourceClassName == type.Name)
- {
- stream = assembly.GetManifestResourceStream(str);
- break;
- }
- }
- }
-
- if (null == stream)
+ var resourceId = XamlResourceIdAttribute.GetResourceIdForType(type);
+ if (null == resourceId)
{
throw new XamlParseException(string.Format("Can't find type {0} in embedded resource", type.FullName), new XmlLineInfo());
}
else
{
- Byte[] buffer = new byte[stream.Length];
- stream.Read(buffer, 0, (int)stream.Length);
+ Stream stream = assembly.GetManifestResourceStream(resourceId);
- string ret = System.Text.Encoding.Default.GetString(buffer);
- return ret;
+ if (null != stream)
+ {
+ Byte[] buffer = new byte[stream.Length];
+ stream.Read(buffer, 0, (int)stream.Length);
+
+ string ret = System.Text.Encoding.Default.GetString(buffer);
+ return ret;
+ }
+ else
+ {
+ throw new XamlParseException(string.Format("Can't get xaml stream {0} in embedded resource", type.FullName), new XmlLineInfo());
+ }
}
}
-
- return null;
}
//if the assembly was generated using a version of XamlG that doesn't outputs XamlResourceIdAttributes, we still need to find the resource, and load it
if (ve != null && ve.IsResourcesCreated)
{
resources = resources ?? new Dictionary<string, object>();
+ if (null == resources)
+ {
+ return null;
+ }
+
if (ve.XamlResources != null)
{
foreach (KeyValuePair<string, object> res in ve.XamlResources.MergedResources)
}
}
}
+
var app = element as Application;
if (app != null && app.SystemResources != null)
{
resources = resources ?? new Dictionary<string, object>(8);
+ if (null == resources)
+ {
+ return null;
+ }
+
foreach (KeyValuePair<string, object> res in app.SystemResources)
if (!resources.ContainsKey(res.Key))
resources.Add(res.Key, res.Value);