AddPermission() публичный Метод

public AddPermission ( NetworkInformationAccess access ) : void
access NetworkInformationAccess
Результат void
 public override IPermission CreatePermission()
 {
     NetworkInformationPermission permission = null;
     if (base.Unrestricted)
     {
         return new NetworkInformationPermission(PermissionState.Unrestricted);
     }
     permission = new NetworkInformationPermission(PermissionState.None);
     if (this.access != null)
     {
         if (string.Compare(this.access, "Read", StringComparison.OrdinalIgnoreCase) == 0)
         {
             permission.AddPermission(NetworkInformationAccess.Read);
             return permission;
         }
         if (string.Compare(this.access, "Ping", StringComparison.OrdinalIgnoreCase) == 0)
         {
             permission.AddPermission(NetworkInformationAccess.Ping);
             return permission;
         }
         if (string.Compare(this.access, "None", StringComparison.OrdinalIgnoreCase) != 0)
         {
             throw new ArgumentException(SR.GetString("net_perm_invalid_val", new object[] { "Access", this.access }));
         }
         permission.AddPermission(NetworkInformationAccess.None);
     }
     return permission;
 }
 public override IPermission CreatePermission()
 {
     NetworkInformationPermission perm = null;
     if (Unrestricted) {
         perm = new NetworkInformationPermission(PermissionState.Unrestricted);
     }
     else {
         perm = new NetworkInformationPermission(PermissionState.None);
         if (access != null) {
             if (0 == string.Compare(access, "Read", StringComparison.OrdinalIgnoreCase)) {
                 perm.AddPermission(NetworkInformationAccess.Read);
             }
             else if (0 == string.Compare(access, "Ping", StringComparison.OrdinalIgnoreCase)) {
                 perm.AddPermission(NetworkInformationAccess.Ping);
             }
             else if (0 == string.Compare(access, "None", StringComparison.OrdinalIgnoreCase)) {
                 perm.AddPermission(NetworkInformationAccess.None);
             }
             else {
                 throw new ArgumentException(SR.GetString(SR.net_perm_invalid_val, strAccess, access));
             }
         }
     }
     return perm;
 }
Пример #3
0
        public override IPermission CreatePermission()
        {
            NetworkInformationPermission perm = null;

            if (Unrestricted)
            {
                perm = new NetworkInformationPermission(PermissionState.Unrestricted);
            }
            else
            {
                perm = new NetworkInformationPermission(PermissionState.None);
                if (access != null)
                {
                    if (0 == string.Compare(access, "Read", StringComparison.OrdinalIgnoreCase))
                    {
                        perm.AddPermission(NetworkInformationAccess.Read);
                    }
                    else if (0 == string.Compare(access, "Ping", StringComparison.OrdinalIgnoreCase))
                    {
                        perm.AddPermission(NetworkInformationAccess.Ping);
                    }
                    else if (0 == string.Compare(access, "None", StringComparison.OrdinalIgnoreCase))
                    {
                        perm.AddPermission(NetworkInformationAccess.None);
                    }
                    else
                    {
                        throw new ArgumentException(SR.GetString(SR.net_perm_invalid_val, strAccess, access));
                    }
                }
            }
            return(perm);
        }
        public override IPermission CreatePermission()
        {
            NetworkInformationPermission permission = null;

            if (base.Unrestricted)
            {
                return(new NetworkInformationPermission(PermissionState.Unrestricted));
            }
            permission = new NetworkInformationPermission(PermissionState.None);
            if (this.access != null)
            {
                if (string.Compare(this.access, "Read", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    permission.AddPermission(NetworkInformationAccess.Read);
                    return(permission);
                }
                if (string.Compare(this.access, "Ping", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    permission.AddPermission(NetworkInformationAccess.Ping);
                    return(permission);
                }
                if (string.Compare(this.access, "None", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new ArgumentException(SR.GetString("net_perm_invalid_val", new object[] { "Access", this.access }));
                }
                permission.AddPermission(NetworkInformationAccess.None);
            }
            return(permission);
        }
Пример #5
0
        public static void CreatePermission()
        {
            //<Snippet6>
            //<Snippet5>
            //<Snippet2>
            //<Snippet1>
            System.Net.NetworkInformation.NetworkInformationPermission unrestricted =
                new System.Net.NetworkInformation.NetworkInformationPermission(
                    System.Security.Permissions.PermissionState.Unrestricted);
            //</Snippet1>

            Console.WriteLine("Is unrestricted? " + unrestricted.IsUnrestricted());
            //</Snippet2>

            //<Snippet4>
            //<Snippet3>
            System.Net.NetworkInformation.NetworkInformationPermission read =
                new System.Net.NetworkInformation.NetworkInformationPermission(
                    System.Net.NetworkInformation.NetworkInformationAccess.Read);
            //</Snippet3>
            System.Net.NetworkInformation.NetworkInformationPermission copyPermission =
                (System.Net.NetworkInformation.NetworkInformationPermission)read.Copy();
            //</Snippet4>
            System.Net.NetworkInformation.NetworkInformationPermission unionPermission =
                (System.Net.NetworkInformation.NetworkInformationPermission)read.Union(unrestricted);
            Console.WriteLine("Is subset?" + read.IsSubsetOf(unionPermission));
            //</Snippet5>
            System.Net.NetworkInformation.NetworkInformationPermission intersectPermission =
                (System.Net.NetworkInformation.NetworkInformationPermission)read.Intersect(unrestricted);
            //</Snippet6>

            //<Snippet7>
            System.Net.NetworkInformation.NetworkInformationPermission permission =
                new System.Net.NetworkInformation.NetworkInformationPermission(
                    System.Security.Permissions.PermissionState.None);
            permission.AddPermission(
                System.Net.NetworkInformation.NetworkInformationAccess.Read);
            Console.WriteLine("Access is {0}", permission.Access);
            //</Snippet7>
        }