• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET GacMembershipCondition类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Security.Policy.GacMembershipCondition的典型用法代码示例。如果您正苦于以下问题:VB.NET GacMembershipCondition类的具体用法?VB.NET GacMembershipCondition怎么用?VB.NET GacMembershipCondition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了GacMembershipCondition类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: GacMembershipConditionDemo

' 导入命名空间
Imports System.Security
Imports System.Security.Policy
Imports System.Collections

Public Class GacMembershipConditionDemo

    ' Demonstrate the Copy method, which creates an identical 
    ' copy of the current permission.
    Private Function CopyDemo() As Boolean
        Console.WriteLine( _
            "*************************************************************")
        Dim Gac1 As New GacMembershipCondition
        Console.WriteLine("Original membership condition = ")
        Console.WriteLine(Gac1.ToXml().ToString())
        Try
            Dim membershipCondition As IMembershipCondition = Gac1.Copy()
            Console.WriteLine("Result of Copy = ")
            Console.WriteLine(CType(membershipCondition, _
                GacMembershipCondition).ToXml().ToString())
        Catch e As Exception
            Console.WriteLine(("Copy failed : " & Gac1.ToString() & _
                e.ToString()))
            Return False
        End Try

        Return True
    End Function 'CopyDemo

    ' Demonstrate the Check method, which determines whether the specified 
    ' evidence satisfies the membership condition.
    Private Function CheckDemo() As Boolean
        Console.WriteLine( _
            "*************************************************************")
        Dim Gac1 As New GacMembershipCondition
        Dim myGac As New GacInstalled
        Try
            Dim hostEvidence() As Object = {myGac}
            Dim assemblyEvidence() As Object

            Dim myEvidence As New Evidence(hostEvidence, assemblyEvidence)
            Dim retCode As Boolean = Gac1.Check(myEvidence)
            Console.WriteLine(("Result of Check = " & retCode.ToString() _
                & ControlChars.Lf))
        Catch e As Exception
            Console.WriteLine(("Check failed : " & Gac1.ToString() & _ 
                e.ToString()))
            Return False
        End Try
        Return True
    End Function 'CheckDemo

    ' Demonstrate the GetHashCode method, which returns a hash code
    ' for the specified membership condition.
    Private Function GetHashCodeDemo() As Boolean
        Console.WriteLine( _
            "*************************************************************")
        Dim Gac1 As New GacMembershipCondition
        Try
            Console.WriteLine( _
                ("Result of GetHashCode for a GacMembershipCondition = " _
                & Gac1.GetHashCode().ToString() & ControlChars.Lf))
        Catch e As Exception
            Console.WriteLine(("GetHashCode failed : " & _
                Gac1.ToString() & e.ToString()))
            Return False
        End Try

        Return True
    End Function 'GetHashCodeDemo

    'Demonstrate the ToXml and FromXml methods, including the overloads. 
    ' ToXml creates an XML encoding of the membership condition and its 
    ' current state; FromXml reconstructs a membership condition with the 
    ' specified state from the XML encoding.
    Private Function ToFromXmlDemo() As Boolean
        Console.WriteLine( _
            "*************************************************************")
        Try
            Dim Gac1 As New GacMembershipCondition
            Dim Gac2 As New GacMembershipCondition

            ' Roundtrip a GacMembershipCondition to and from an XML encoding.
            Gac2.FromXml(Gac1.ToXml())
            Dim result As Boolean = Gac2.Equals(Gac1)
            If result Then
                Console.WriteLine(("Result of ToXml() = " & _ 
                    Gac2.ToXml().ToString()))
                Console.WriteLine(("Result of ToFromXml roundtrip = " & _ 
                    Gac2.ToString()))
            Else
                Console.WriteLine(Gac2.ToString())
                Console.WriteLine(Gac1.ToString())
                Return False
            End If

            Dim Gac3 As New GacMembershipCondition
            Dim Gac4 As New GacMembershipCondition
            Dim policyEnumerator As IEnumerator = _
                SecurityManager.PolicyHierarchy()
            While policyEnumerator.MoveNext()
                Dim currentLevel As PolicyLevel = _
                    CType(policyEnumerator.Current, PolicyLevel)
                If currentLevel.Label = "Machine" Then
                    Console.WriteLine(("Result of ToXml(level) = " & _
                        Gac3.ToXml(currentLevel).ToString()))
                    Gac4.FromXml(Gac3.ToXml(), currentLevel)
                    Console.WriteLine(("Result of FromXml(element, level) = " _
                        & Gac4.ToString()))
                End If
            End While
        Catch e As Exception
            Console.WriteLine(("ToFromXml failed. " & e.ToString()))
            Return False
        End Try

        Return True
    End Function 'ToFromXmlDemo

    ' Invoke all demos.
    Public Function RunDemo() As Boolean

        Dim returnCode As Boolean = True
        Dim tempReturnCode As Boolean

        ' Call the Copy demo.
        tempReturnCode = CopyDemo()
        If tempReturnCode = True Then
            Console.Out.WriteLine("Copy demo completed successfully.")
        Else
            Console.Out.WriteLine("Copy demo failed.")
        End If

        returnCode = tempReturnCode AndAlso returnCode

        ' Call the Check demo.
        tempReturnCode = CheckDemo()
        If tempReturnCode = True Then
            Console.Out.WriteLine("Check demo completed successfully.")
        Else
            Console.Out.WriteLine("Check demo failed.")
        End If

        returnCode = tempReturnCode AndAlso returnCode

        ' Call the GetHashCode demo.
        tempReturnCode = GetHashCodeDemo()
        If tempReturnCode = True Then
            Console.Out.WriteLine("GetHashCode demo completed successfully.")
        Else
            Console.Out.WriteLine("GetHashCode demo failed.")
        End If

        returnCode = tempReturnCode AndAlso returnCode

        ' Call the ToFromXml demo.
        tempReturnCode = ToFromXmlDemo()
        If tempReturnCode = True Then
            Console.Out.WriteLine("ToFromXml demo completed successfully.")
        Else
            Console.Out.WriteLine("ToFromXml demo failed.")
        End If

        returnCode = tempReturnCode AndAlso returnCode
        Return returnCode
    End Function 'RunDemo

    ' Test harness.
    Public Overloads Shared Sub Main(ByVal args() As [String])
        Try
            Dim testcase As New GacMembershipConditionDemo
            Dim returnCode As Boolean = testcase.RunDemo()
            If returnCode Then
                Console.Out.WriteLine( _
                    "The GacMembershipCondition demo completed successfully.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 100
            Else
                Console.Out.WriteLine("The GacMembershipCondition demo failed.")
                Console.Out.WriteLine("Press the ENTER key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 101
            End If
        Catch e As Exception
            Console.Out.WriteLine("The GacIdentityPermission demo failed.")
            Console.WriteLine(e.ToString())
            Console.Out.WriteLine("Press the Enter key to exit.")
            Dim consoleInput As String = Console.ReadLine()
            System.Environment.ExitCode = 101
        End Try
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Security.Policy,代码行数:193,代码来源:GacMembershipCondition



注:本文中的System.Security.Policy.GacMembershipCondition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET CallbackBehaviorAttribute类代码示例发布时间:2022-05-24
下一篇:
VB.NET KeyReference类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap