当前位置: 首页>>代码示例>>C#>>正文


C# EnvironmentPermission.Assert方法代码示例

本文整理汇总了C#中System.Security.Permissions.EnvironmentPermission.Assert方法的典型用法代码示例。如果您正苦于以下问题:C# EnvironmentPermission.Assert方法的具体用法?C# EnvironmentPermission.Assert怎么用?C# EnvironmentPermission.Assert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Permissions.EnvironmentPermission的用法示例。


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

示例1: EnvironmentSetting

        public static string EnvironmentSetting(string environmentVariable)
        {
            EnvironmentPermission envPermission = new EnvironmentPermission( EnvironmentPermissionAccess.Read,environmentVariable);
             envPermission.Assert();

             return Environment.GetEnvironmentVariable(environmentVariable);
        }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:7,代码来源:ca2122--do-not-indirectly-expose-methods-with-link-demands_1.cs

示例2: XamlSourceInfoHelper

 static XamlSourceInfoHelper()
 {
     // Check environment variable
     const string environmentVariable = "ENABLE_XAML_DIAGNOSTICS_SOURCE_INFO";
     EnvironmentPermission environmentPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, environmentVariable);
     environmentPermission.Assert();
     try
     {
         InitializeEnableXamlSourceInfo(Environment.GetEnvironmentVariable(environmentVariable));
     }
     finally
     {
         EnvironmentPermission.RevertAssert();
     }
 }
开发者ID:mind0n,项目名称:hive,代码行数:15,代码来源:XamlSourceInfoHelper.cs

示例3: TestAssertAndDeny

        public static void TestAssertAndDeny()
        {
            EnvironmentPermission envPermission = new EnvironmentPermission(
               EnvironmentPermissionAccess.Read,
               "COMPUTERNAME;USERNAME;USERDOMAIN");
             envPermission.Assert();
             try
             {
            SomeSecuredMethods.MethodProtectedByDemand();
            Console.WriteLine(
               "Caller's Deny has no effect on Demand " +
               "with the asserted permission.");

            SomeSecuredMethods.MethodProtectedByLinkDemand();
            Console.WriteLine(
               "Caller's Deny has no effect on LinkDemand " +
               "with the asserted permission.");
             }
             catch (SecurityException e)
             {
            Console.WriteLine(
               "Caller's Deny protected the library.{0}", e);
             }
        }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:24,代码来源:ca2107--review-deny-and-permit-only-usage_2.cs

示例4: GetWPFInstallPath

        private static string GetWPFInstallPath()
        {
            string path = null;

            // We support a "private CLR" which allows someone to use a different framework
            // location than what is specified in the registry.  The CLR support for this
            // involves two environment variable: COMPLUS_InstallRoot and COMPLUS_Version.
            EnvironmentPermission environmentPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, EnvironmentVariables);
            environmentPermission.Assert(); //Blessed Assert

            try
            {
                string version = Environment.GetEnvironmentVariable(COMPLUS_Version);
                if (!String.IsNullOrEmpty(version))
                {
                    path = Environment.GetEnvironmentVariable(COMPLUS_InstallRoot);
                    if (String.IsNullOrEmpty(path))
                    {
                        // The COMPLUS_Version environment variable was set, but the
                        // COMPLUS_InstallRoot environment variable was not.  We fall back
                        // to getting the framework install root from the registry, but
                        // still use the private CLR version.
                        path = ReadLocalMachineString(DOTNET_RegKey, DOTNET_Install_RegValue);
                    }

                    if (!String.IsNullOrEmpty(path))
                    {
                        path = Path.Combine(path, version);
                    }
                }
            }
            finally
            {
                EnvironmentPermission.RevertAssert();
            }

            if (String.IsNullOrEmpty(path))
            {
                // The COMPLUS_Version environment variable was not set.  We do not support
                // extracting the appropriate version ourselves, since this could come from
                // various places (app config, etc), so we default to 4.0.  The entire path
                // is stored in the registry, under the v4 key.
                path = ReadLocalMachineString(FRAMEWORK_RegKey, FRAMEWORK_InstallPath_RegValue);
            }

            // WPF chose to make a subdirectory for its own DLLs under the framework directory.
            path = Path.Combine(path, WPF_SUBDIR);

            return path;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:50,代码来源:NativeMethodsSetLastError.cs

示例5: A

 public static void A(string text)
 {
     EnvironmentPermission p = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "foo");
     p.Assert();
 }
开发者ID:dbremner,项目名称:smokey,代码行数:5,代码来源:SecureAssertsTest.cs


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