コード例 #1
0
        internal DomAttribute AttributeByNameOrCreate(DomName name, bool insertFirst = false)
        {
            var attr = Attributes[name];

            if (attr == null)
            {
                // Owner doc could be null (rare)
                var doc = OwnerDocument;
                if (doc == null)
                {
                    attr = DomProviderFactory.ForProviderObject(this).CreateNodeFactory(null).CreateAttribute(name);
                }
                else
                {
                    attr = doc.CreateAttribute(name);
                }
                if (insertFirst)
                {
                    Attributes.Insert(0, attr);
                }
                else
                {
                    Attributes.Add(attr);
                }
            }
            return(attr);
        }
コード例 #2
0
        public static DomReader Create(TextReader reader, DomReaderSettings settings)
        {
            if (settings == null)
            {
                return(Create(XmlReader.Create(reader)));
            }

            var pro = DomProviderFactory.ForProviderObject(settings) ?? DomProviderFactory.Default;

            return(pro.CreateReader(reader, settings));
        }
コード例 #3
0
        public static DomWriter Create(TextWriter writer, DomWriterSettings settings)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            if (settings == null)
            {
                return(Create(XmlWriter.Create(writer)));
            }

            var pro = DomProviderFactory.ForProviderObject(settings) ?? DomProviderFactory.Default;

            return(pro.CreateWriter(writer, settings));
        }
コード例 #4
0
        internal static DomProviderFactory ForFileName(object settings, string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw Failure.NullOrEmptyString(nameof(fileName));
            }

            var result       = (settings != null ? DomProviderFactory.ForProviderObject(settings) : null);
            var fromCriteria = FromCriteria(new {
                Extension = Path.GetExtension(fileName)
            });

            // If the one from criteria is more specific, prefer it
            if (result is DefaultDomProviderFactory)
            {
                return(fromCriteria ?? result);
            }
            return(result ?? fromCriteria ?? Default);
        }
コード例 #5
0
ファイル: DomObject.cs プロジェクト: Carbonfrost/f-web-dom
        internal static T RequireFactoryGeneratedName <T>(Type type, Func <IDomNodeTypeProvider, Type, T> generator)
        {
            Type inputType = type;

            while (type != typeof(object))
            {
                var fac = DomProviderFactory.ForProviderObject(type);
                if (fac != null)
                {
                    var name = generator(fac.NodeTypeProvider, inputType);
                    if (name != null)
                    {
                        return(name);
                    }
                    if (fac is DefaultDomProviderFactory)
                    {
                        break;
                    }
                }
                type = type.BaseType;
            }

            throw DomFailure.CannotGenerateName(inputType);
        }