static CodeMemberMethod GenerateInitialize(XPathModuleInfo module, CodeExpression moduleExpr) { var initializeMethod = new CodeMemberMethod { Name = "Initialize", Attributes = MemberAttributes.Public | MemberAttributes.Final }; for (int i = 0; i < module.Dependencies.Count; i++) { XPathDependencyInfo dependency = module.Dependencies[i]; initializeMethod.Parameters.Add(new CodeParameterDeclarationExpression { Type = new CodeTypeReference(dependency.Type), Name = "d" + (i + 1).ToStringInvariant() }); var paramRef = new CodeVariableReferenceExpression(initializeMethod.Parameters[i].Name); initializeMethod.Statements.Add(new CodeAssignStatement { Left = new CodePropertyReferenceExpression(moduleExpr, dependency.Property.Name), Right = paramRef }); } return(initializeMethod); }
object InitializeExtensionObject(Tuple <XPathModuleInfo, Type> info, XmlResolver resolver) { object instance = Activator.CreateInstance(info.Item2); XPathModuleInfo moduleInfo = info.Item1; if (moduleInfo == null) { var xpathFn = instance as extensions.XPathFunctions; if (xpathFn != null) { xpathFn.resolver = resolver; } } else if (moduleInfo.Dependencies.Count > 0) { object[] args = new object[info.Item1.Dependencies.Count]; for (int i = 0; i < info.Item1.Dependencies.Count; i++) { XPathDependencyInfo dependency = info.Item1.Dependencies[i]; if (dependency.Type == typeof(XPathItemFactory)) { args[i] = this.Processor.ItemFactory; continue; } if (dependency.Type == typeof(XmlResolver)) { args[i] = resolver; continue; } if (dependency.Type == typeof(IXsltProcessor)) { args[i] = this.Processor; continue; } args[i] = dependency.Type.IsValueType ? Activator.CreateInstance(dependency.Type) : null; } info.Item2.GetMethod("Initialize").Invoke(instance, args); } return(instance); }
CodeMemberMethod GenerateInitialize(XPathModuleInfo module, CodeExpression processorRef, CodeExpression staticBaseUriExpr) { var initializeMethod = new CodeMemberMethod { Name = "Initialize", Attributes = MemberAttributes.Private | MemberAttributes.Final, Parameters = { new CodeParameterDeclarationExpression(module.Type, "module") } }; for (int i = 0; i < module.Dependencies.Count; i++) { XPathDependencyInfo dependency = module.Dependencies[i]; CodeExpression expr = null; if (dependency.Type == typeof(IXsltProcessor) || dependency.Type == typeof(IXQueryProcessor)) { expr = processorRef; } else if (dependency.Type == typeof(XPathItemFactory)) { expr = GetItemFactoryReference(processorRef); } else if (dependency.Type == typeof(XmlResolver)) { expr = new CodeObjectCreateExpression(typeof(XmlDynamicResolver), staticBaseUriExpr); } if (expr != null) { initializeMethod.Statements.Add(new CodeAssignStatement { Left = new CodePropertyReferenceExpression( new CodeVariableReferenceExpression(initializeMethod.Parameters[0].Name), dependency.Property.Name ), Right = expr }); } } return(initializeMethod); }