GetAttributeValue() публичный статический Метод

Get an optional attribute value from an XmlNode.
public static GetAttributeValue ( XmlNode node, string attrName ) : string
node System.Xml.XmlNode The XmlNode to look in.
attrName string The attribute to find.
Результат string
Пример #1
0
        /// <summary>
        /// Utility function to find a methodInfo for the named method.
        /// It is a static method of the class specified in the EditRowClass of the EditRowAssembly.
        /// </summary>
        /// <param name="methodName"></param>
        /// <returns></returns>
        public static System.Reflection.MethodInfo GetStaticMethod(XmlNode node, string sAssemblyAttr, string sClassAttr,
                                                                   string sMethodName, out System.Type typeFound)
        {
            string sAssemblyName = XmlUtils.GetAttributeValue(node, sAssemblyAttr);
            string sClassName    = XmlUtils.GetAttributeValue(node, sClassAttr);

            System.Reflection.MethodInfo mi = GetStaticMethod(sAssemblyName, sClassName, sMethodName,
                                                              "node " + node.OuterXml, out typeFound);
            return(mi);
        }
Пример #2
0
        public void AddList(XmlNodeList nodes)
        {
            foreach (XmlNode node in nodes)
            {
                string assemblyName = XmlUtils.GetAttributeValue(node, "assemblyPath").Trim();
                // Prepend the directory where the current DLL lives.  This should fix
                // LT-1541 (and similar bugs) once and for all!
                // (Note that CodeBase prepends "file:/", which must be removed.)
                string baseDir = System.IO.Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().CodeBase).Substring(6);
                string assemblyPath = System.IO.Path.Combine(baseDir, assemblyName);
                string className    = XmlUtils.GetAttributeValue(node, "class").Trim();
                string field        = XmlUtils.GetAttributeValue(node, "field").Trim();

                Assembly assembly = null;
                try
                {
                    assembly = Assembly.LoadFrom(assemblyPath);
                    if (assembly == null)
                    {
                        throw new ApplicationException();                         //will be caught and described in the catch
                    }
                }
                catch (Exception error)
                {
                    throw new RuntimeConfigurationException("XCore Could not load the  DLL at :" + assemblyPath, error);
                }

                //make the  holder
                object holder = assembly.CreateInstance(className);
                if (holder == null)
                {
                    throw new RuntimeConfigurationException("XCore could not create the class: " + className + ". Make sure capitalization is correct and that you include the name space (e.g. XCore.ImageHolder).");
                }

                //get the named ImageList
                FieldInfo info = holder.GetType().GetField(field);

                if (info == null)
                {
                    throw new RuntimeConfigurationException("XCore could not find the field '" + field + "' in the class: " + className + ". Make sure that the field is marked 'public' and that capitalization is correct.");
                }

                ImageList images = (ImageList)info.GetValue(holder);

                string[] labels = XmlUtils.GetAttributeValue(node, "labels").Split(new char[] { ',' });
                if (labels.Length != images.Images.Count)
                {
                    throw new ConfigurationException("The number of image labels does not match the number of images in this <imageList>: " + node.OuterXml);
                }
                this.AddList(images, labels);
            }
        }