當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。