Exemplo n.º 1
0
        /// <include file='doc\FileIOPermission.uex' path='docs/doc[@for="FileIOPermission.ToXml"]/*' />
        public override SecurityElement ToXml()
        {
            SecurityElement esd = CodeAccessPermission.CreatePermissionElement(this);

            if (!IsUnrestricted())
            {
                if (this.m_read != null && !this.m_read.IsEmpty())
                {
                    esd.AddAttribute("Read", SecurityElement.Escape(m_read.ToString()));
                }
                if (this.m_write != null && !this.m_write.IsEmpty())
                {
                    esd.AddAttribute("Write", SecurityElement.Escape(m_write.ToString()));
                }
                if (this.m_append != null && !this.m_append.IsEmpty())
                {
                    esd.AddAttribute("Append", SecurityElement.Escape(m_append.ToString()));
                }
                if (this.m_pathDiscovery != null && !this.m_pathDiscovery.IsEmpty())
                {
                    esd.AddAttribute("PathDiscovery", SecurityElement.Escape(m_pathDiscovery.ToString()));
                }
            }
            else
            {
                esd.AddAttribute("Unrestricted", "true");
            }
            return(esd);
        }
Exemplo n.º 2
0
        public override SecurityElement ToXml()
        {
            // SafeCritical: our string expression sets don't contain paths, so there's no information that
            // needs to be guarded in them.
            SecurityElement esd = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.RegistryPermission");

            if (!IsUnrestricted())
            {
                if (this.m_read != null && !this.m_read.IsEmpty())
                {
                    esd.AddAttribute("Read", SecurityElement.Escape(m_read.UnsafeToString()));
                }
                if (this.m_write != null && !this.m_write.IsEmpty())
                {
                    esd.AddAttribute("Write", SecurityElement.Escape(m_write.UnsafeToString()));
                }
                if (this.m_create != null && !this.m_create.IsEmpty())
                {
                    esd.AddAttribute("Create", SecurityElement.Escape(m_create.UnsafeToString()));
                }
                if (this.m_viewAcl != null && !this.m_viewAcl.IsEmpty())
                {
                    esd.AddAttribute("ViewAccessControl", SecurityElement.Escape(m_viewAcl.UnsafeToString()));
                }
                if (this.m_changeAcl != null && !this.m_changeAcl.IsEmpty())
                {
                    esd.AddAttribute("ChangeAccessControl", SecurityElement.Escape(m_changeAcl.UnsafeToString()));
                }
            }
            else
            {
                esd.AddAttribute("Unrestricted", "true");
            }
            return(esd);
        }
Exemplo n.º 3
0
        // trim(s) and strlen(s) built-in funcs; these are Format options
        public virtual string ToString(object o, string formatString, CultureInfo culture)
        {
            string s = (string)o;

            if (formatString == null)
            {
                return(s);
            }

            if (formatString.Equals("upper"))
            {
                return(culture.TextInfo.ToUpper(s));
            }

            if (formatString.Equals("lower"))
            {
                return(culture.TextInfo.ToLower(s));
            }

            if (formatString.Equals("cap"))
            {
                return(s.Length > 0 ? culture.TextInfo.ToUpper(s[0]) + s.Substring(1) : s);
            }

            if (formatString.Equals("url-encode"))
            {
                return(HttpUtility.UrlEncode(s, Encoding.UTF8));
            }

            if (formatString.Equals("xml-encode"))
            {
#if NETSTANDARD
                return(s.Replace("&", "&amp;")
                       .Replace("<", "&lt;")
                       .Replace(">", "&gt;")
                       .Replace("\"", "&quot;")
                       .Replace("'", "&apos;"));
#else
                return(SecurityElement.Escape(s));
#endif
            }

            return(string.Format(culture, formatString, s));
        }
Exemplo n.º 4
0
        internal SecurityElement ToXml()
        {
            SecurityElement root = new SecurityElement("Identity");

            if (m_authenticated)
            {
                root.AddAttribute("Authenticated", "true");
            }

            if (m_id != null)
            {
                root.AddAttribute("ID", SecurityElement.Escape(m_id));
            }

            if (m_role != null)
            {
                root.AddAttribute("Role", SecurityElement.Escape(m_role));
            }

            return(root);
        }
Exemplo n.º 5
0
        // trim(s) and strlen(s) built-in funcs; these are Format options
        public virtual string ToString(object o, string formatString, CultureInfo culture)
        {
            string s = (string)o;

            if (formatString == null)
            {
                return(s);
            }

            if (formatString.Equals("upper"))
            {
                return(s.ToUpper(culture));
            }

            if (formatString.Equals("lower"))
            {
                return(s.ToLower(culture));
            }

            if (formatString.Equals("cap"))
            {
                return(s.Length > 0 ? char.ToUpper(s[0], culture) + s.Substring(1) : s);
            }

            if (formatString.Equals("url-encode"))
            {
                return(HttpUtility.UrlEncode(s, Encoding.UTF8));
            }

            if (formatString.Equals("xml-encode"))
            {
                return(SecurityElement.Escape(s));
            }

            return(string.Format(culture, formatString, s));
        }