return success;
}
+ private string GetNameSpaceOfResource(EmbeddedResource resource)
+ {
+ var index = resource.Name.LastIndexOf('.');
+ var resourceNameWithoutSubfix = resource.Name.Substring(0, index);
+
+ index = resourceNameWithoutSubfix.LastIndexOf('.');
+ var nameSpace = resourceNameWithoutSubfix.Substring(0, index);
+
+ return nameSpace;
+ }
+
bool DoInjection(TypeDefinition typeDef, EmbeddedResource resource, out IList<Exception> thrownExceptions)
{
thrownExceptions = null;
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
Exception e;
- if (!TryCoreCompile(initComp, rootnode, out e))
+
+ var embeddedResourceNameSpace = GetNameSpaceOfResource(resource);
+ if (!TryCoreCompile(initComp, rootnode, embeddedResourceNameSpace, out e))
{
LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed.");
(thrownExceptions = thrownExceptions ?? new List<Exception>()).Add(e);
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
Exception e;
- var visitorContext = new EXamlContext(typeDef, typeDef.Module);
+ var embeddedResourceNameSpace = GetNameSpaceOfResource(resource);
+ var visitorContext = new EXamlContext(typeDef, typeDef.Module, embeddedResourceNameSpace);
if (!TryCoreCompile(rootnode, visitorContext, out e))
{
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
Exception e;
- var visitorContext = new EXamlContext(typeDef, module);
+ var visitorContext = new EXamlContext(typeDef, module, null);
if (!TryCoreCompile(rootnode, visitorContext, out e))
{
return true;
}
- bool TryCoreCompile(MethodDefinition initComp, ILRootNode rootnode, out Exception exception)
+ bool TryCoreCompile(MethodDefinition initComp, ILRootNode rootnode, string embeddedResourceNameSpace, out Exception exception)
{
try
{
List<Instruction> insOfAddEvent = new List<Instruction>();
- var visitorContext = new ILContext(il, body, insOfAddEvent, module);
+ var visitorContext = new ILContext(il, body, insOfAddEvent, module, embeddedResourceNameSpace);
rootnode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null);
rootnode.Accept(new ExpandMarkupsVisitor(visitorContext), null);