System.Security.PermissionToken.FromXml C# (CSharp) Method

FromXml() public method

public FromXml ( SecurityElement elRoot ) : void
elRoot SecurityElement
return void
        public void FromXml( SecurityElement elRoot )
        {
            // For the most part there is no parameter checking here since this is an
            // internal class and the serialization/deserialization path is controlled.

            if (!elRoot.Tag.Equals( "PermissionToken" ))
                BCLDebug.Assert( false, "Tried to deserialize non-PermissionToken element here" );

            String strName = elRoot.Attribute( "Name" );
            PermissionToken realToken;
            if (strName != null)
                realToken = GetToken( strName, true );
            else
                realToken = FindTokenByIndex( Int32.Parse( elRoot.Attribute( "Index" ), CultureInfo.InvariantCulture ) );
            
            this.m_index = realToken.m_index;
            this.m_type = (PermissionTokenType) Enum.Parse(typeof(PermissionTokenType), elRoot.Attribute("Type"));
            BCLDebug.Assert((this.m_type & PermissionTokenType.DontKnow) == 0, "Should have valid token type when FromXml is called.");
            this.m_strTypeName = realToken.m_strTypeName;
        }
    }

Usage Example

        [System.Security.SecurityCritical]  // auto-generated
        private static Object Deserialize(byte[] blob)
        {
            if (blob == null)
                return null;

            if (blob[0] == 0)
            {
                Parser parser = new Parser( blob, Tokenizer.ByteTokenEncoding.UTF8Tokens, 1 );
                SecurityElement root = parser.GetTopElement();
                if (root.Tag.Equals( "IPermission" ) || root.Tag.Equals( "Permission" ))
                {
                    IPermission ip = System.Security.Util.XMLUtil.CreatePermission( root, PermissionState.None, false );

                    if (ip == null)
                    {
                        return null;
                    }

                    ip.FromXml( root );

                    return ip;
                }
                else if (root.Tag.Equals( "PermissionSet" ))
                {
                    PermissionSet permissionSet = new PermissionSet();

                    permissionSet.FromXml( root, false, false );

                    return permissionSet;
                }
                else if (root.Tag.Equals( "PermissionToken" ))
                {
                    PermissionToken pToken = new PermissionToken();

                    pToken.FromXml( root );

                    return pToken;
                }
                else
                {
                    return null;
                }

            }
            else
            {
                Object obj = null;
                using(MemoryStream stream = new MemoryStream( blob, 1, blob.Length - 1 )) {
                    obj = CrossAppDomainSerializer.DeserializeObject(stream);
                }

                Contract.Assert( !(obj is IPermission), "IPermission should be xml deserialized" );
                Contract.Assert( !(obj is PermissionSet), "PermissionSet should be xml deserialized" );

                return obj;
            }
        }
All Usage Examples Of System.Security.PermissionToken::FromXml