コード例 #1
0
        private static object[] CreateArgs(XmlNode configuration)
        {
            List <object> argList = new List <object>();

            // see if we can find "args" children that specify arguments to pass in.
            if (configuration != null && configuration.HasChildNodes)
            {
                XmlNodeList argNodes = configuration.SelectNodes("args/arg");
                if (argNodes.Count > 0)
                {
                    Dictionary <string, string> argDict = new Dictionary <string, string>();
                    foreach (XmlNode argNode in argNodes)
                    {
                        string argName = XmlUtils.GetMandatoryAttributeValue(argNode, "name");
                        string argVal  = XmlUtils.GetMandatoryAttributeValue(argNode, "value");
                        argDict.Add(argName, argVal);
                    }
                    string argValue;
                    if (argDict.TryGetValue("xpathToConfigurationNode", out argValue))
                    {
                        // "xpathToConfigurationNode" is a special argument for passing the nodes
                        // that the object we're creating knows how to process.
                        // NOTE: assume the xpath is with respect to the dynamicloaderinfo "configuration" node
                        XmlNode configNodeForObject = configuration.SelectSingleNode(argValue);
                        if (configNodeForObject != null)
                        {
                            argList.Add(configNodeForObject);
                        }
                    }
                }
            }
            return(argList.Count > 0 ? argList.ToArray() : null);
        }
コード例 #2
0
        /// <summary>
        /// Dynamically find an assembly and create an object of the name to class.
        /// configuration has assemblyPath and class (fully qualified) as in other overloads.
        /// The constructor arguments are supplied explicitly.
        /// </summary>
        /// <returns></returns>
        static public Object CreateObject(XmlNode configuration, params object[] args)
        {
            string assemblyPath = XmlUtils.GetMandatoryAttributeValue(configuration, "assemblyPath");

            // JohnT: see AddAssemblyPathInfo. We use this when the object we're trying to persist
            // as a child of another object is null.
            if (assemblyPath == "null")
            {
                return(null);
            }
            string className = XmlUtils.GetMandatoryAttributeValue(configuration, "class");

            return(CreateObject(assemblyPath, className, args));
        }
コード例 #3
0
        // Return the class of object that will be created if CreateObjectUsingLoaderNode is called with this argument.
        // Return null if dynamic loader node not found or if it doesn't specify a valid class.
        static public Type TypeForLoaderNode(XmlNode parentConfigNode)
        {
            XmlNode configuration = parentConfigNode.SelectSingleNode("dynamicloaderinfo");

            if (configuration == null)
            {
                return(null);
            }
            string assemblyPath = XmlUtils.GetMandatoryAttributeValue(configuration, "assemblyPath");

            if (assemblyPath == "null")
            {
                return(null);
            }
            string   className = XmlUtils.GetMandatoryAttributeValue(configuration, "class");
            Assembly assembly;

            GetAssembly(assemblyPath, out assembly);
            return(assembly.GetType(className.Trim()));
        }