本文整理汇总了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();
}
}
示例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);
}
}
示例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;
}
示例5: A
public static void A(string text)
{
EnvironmentPermission p = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "foo");
p.Assert();
}