File: XmlElementElement.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,284,488 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (118 lines) | stat: -rw-r--r-- 4,013 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------------------------

namespace System.ServiceModel.Configuration
{
    using System;
    using System.Configuration;
    using System.Runtime;
    using System.Security;
    using System.Xml;

    public sealed partial class XmlElementElement : ConfigurationElement
    {
        public XmlElementElement()
        {
        }

        public XmlElementElement(XmlElement element) : this()
        {
            this.XmlElement = element;
        }

        public void Copy(XmlElementElement source)
        {
            if (this.IsReadOnly())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
            }
            if (null == source)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
            }

            if (null != source.XmlElement)
            {
                this.XmlElement = (XmlElement)source.XmlElement.Clone();
            }
        }

        [Fx.Tag.SecurityNote(Critical = "Uses the critical helper SetIsPresent.",
            Safe = "Controls how/when SetIsPresent is used, not arbitrarily callable from PT (method is protected and class is sealed).")]
        [SecuritySafeCritical]
        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            SetIsPresent();
            DeserializeElementCore(reader);
        }

        void DeserializeElementCore(XmlReader reader)
        {
            XmlDocument doc = new XmlDocument();
            this.XmlElement = (XmlElement)doc.ReadNode(reader);
        }

        internal void ResetInternal(XmlElementElement element)
        {
            this.Reset(element);
        }

        [Fx.Tag.SecurityNote(Critical = "Calls ConfigurationHelpers.SetIsPresent which elevates in order to set a property.",
            Safe = "Only passes 'this', does not let caller influence parameter.")]
        [SecurityCritical]
        void SetIsPresent()
        {
            ConfigurationHelpers.SetIsPresent(this);
        }

        protected override bool SerializeToXmlElement(XmlWriter writer, String elementName)
        {
            bool dataToWrite = this.XmlElement != null;
            if (dataToWrite && writer != null)
            {
                if (!String.Equals(elementName, ConfigurationStrings.XmlElement, StringComparison.Ordinal))
                {
                    writer.WriteStartElement(elementName);
                }

                using (XmlNodeReader reader = new XmlNodeReader(this.XmlElement))
                {
                    writer.WriteNode(reader, false);
                }

                if (!String.Equals(elementName, ConfigurationStrings.XmlElement, StringComparison.Ordinal))
                {
                    writer.WriteEndElement();
                }
            }
            return dataToWrite;
        }

        protected override void PostDeserialize()
        {
            this.Validate();
            base.PostDeserialize();
        }

        void Validate()
        {
            if (this.XmlElement == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigXmlElementMustBeSet),
                    this.ElementInformation.Source,
                    this.ElementInformation.LineNumber));
            }
        }

        [ConfigurationProperty(ConfigurationStrings.XmlElement, DefaultValue = null, Options = ConfigurationPropertyOptions.IsKey)]
        public XmlElement XmlElement
        {
            get { return (XmlElement)base[ConfigurationStrings.XmlElement]; }
            set { base[ConfigurationStrings.XmlElement] = value; }
        }
    }
}