Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / Policy / AppDomainEvidenceFactory.cs / 1305376 / AppDomainEvidenceFactory.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Reflection;
namespace System.Security.Policy
{
///
/// Factory class which creates evidence on demand for an AppDomain
///
internal sealed class AppDomainEvidenceFactory : IRuntimeEvidenceFactory
{
private AppDomain m_targetDomain;
private Evidence m_entryPointEvidence;
internal AppDomainEvidenceFactory(AppDomain target)
{
Contract.Assert(target != null);
Contract.Assert(target == AppDomain.CurrentDomain, "AppDomainEvidenceFactory should not be used across domains.");
m_targetDomain = target;
}
///
/// AppDomain this factory generates evidence for
///
public IEvidenceFactory Target
{
get { return m_targetDomain; }
}
///
/// Return any evidence supplied by the AppDomain itself
///
public IEnumerable GetFactorySuppliedEvidence()
{
// AppDomains do not contain serialized evidence
return new EvidenceBase[] { };
}
///
/// Generate evidence on demand for an AppDomain
///
[SecuritySafeCritical]
public EvidenceBase GenerateEvidence(Type evidenceType)
{
// For v1.x compatibility, the default AppDomain has the same evidence as the entry point
// assembly. Since other AppDomains inherit their evidence from the default AppDomain by
// default, they also use the entry point assembly.
BCLDebug.Assert(m_targetDomain == AppDomain.CurrentDomain, "AppDomainEvidenceFactory should not be used across domains.");
if (m_targetDomain.IsDefaultAppDomain())
{
// If we don't already know the evidence for the entry point assembly, get that now. If we
// have a RuntimeAssembly go directly to its EvidenceNoDemand property to avoid the full
// demand that it will do on access to its Evidence property.
if (m_entryPointEvidence == null)
{
Assembly entryAssembly = Assembly.GetEntryAssembly();
RuntimeAssembly entryRuntimeAssembly = entryAssembly as RuntimeAssembly;
if (entryRuntimeAssembly != null)
{
m_entryPointEvidence = entryRuntimeAssembly.EvidenceNoDemand.Clone();
}
else if (entryAssembly != null)
{
m_entryPointEvidence = entryAssembly.Evidence;
}
}
// If the entry point assembly provided evidence, then we use that for the AppDomain
if (m_entryPointEvidence != null)
{
return m_entryPointEvidence.GetHostEvidence(evidenceType);
}
}
else
{
// If we're not the default domain, then we should inherit our evidence from the default
// domain -- so ask it what evidence it has of this type.
AppDomain defaultDomain = AppDomain.GetDefaultDomain();
return defaultDomain.GetHostEvidence(evidenceType);
}
// AppDomains do not generate any evidence on demand
return null;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Reflection;
namespace System.Security.Policy
{
///
/// Factory class which creates evidence on demand for an AppDomain
///
internal sealed class AppDomainEvidenceFactory : IRuntimeEvidenceFactory
{
private AppDomain m_targetDomain;
private Evidence m_entryPointEvidence;
internal AppDomainEvidenceFactory(AppDomain target)
{
Contract.Assert(target != null);
Contract.Assert(target == AppDomain.CurrentDomain, "AppDomainEvidenceFactory should not be used across domains.");
m_targetDomain = target;
}
///
/// AppDomain this factory generates evidence for
///
public IEvidenceFactory Target
{
get { return m_targetDomain; }
}
///
/// Return any evidence supplied by the AppDomain itself
///
public IEnumerable GetFactorySuppliedEvidence()
{
// AppDomains do not contain serialized evidence
return new EvidenceBase[] { };
}
///
/// Generate evidence on demand for an AppDomain
///
[SecuritySafeCritical]
public EvidenceBase GenerateEvidence(Type evidenceType)
{
// For v1.x compatibility, the default AppDomain has the same evidence as the entry point
// assembly. Since other AppDomains inherit their evidence from the default AppDomain by
// default, they also use the entry point assembly.
BCLDebug.Assert(m_targetDomain == AppDomain.CurrentDomain, "AppDomainEvidenceFactory should not be used across domains.");
if (m_targetDomain.IsDefaultAppDomain())
{
// If we don't already know the evidence for the entry point assembly, get that now. If we
// have a RuntimeAssembly go directly to its EvidenceNoDemand property to avoid the full
// demand that it will do on access to its Evidence property.
if (m_entryPointEvidence == null)
{
Assembly entryAssembly = Assembly.GetEntryAssembly();
RuntimeAssembly entryRuntimeAssembly = entryAssembly as RuntimeAssembly;
if (entryRuntimeAssembly != null)
{
m_entryPointEvidence = entryRuntimeAssembly.EvidenceNoDemand.Clone();
}
else if (entryAssembly != null)
{
m_entryPointEvidence = entryAssembly.Evidence;
}
}
// If the entry point assembly provided evidence, then we use that for the AppDomain
if (m_entryPointEvidence != null)
{
return m_entryPointEvidence.GetHostEvidence(evidenceType);
}
}
else
{
// If we're not the default domain, then we should inherit our evidence from the default
// domain -- so ask it what evidence it has of this type.
AppDomain defaultDomain = AppDomain.GetDefaultDomain();
return defaultDomain.GetHostEvidence(evidenceType);
}
// AppDomains do not generate any evidence on demand
return null;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RequestSecurityToken.cs
- ReferenceConverter.cs
- ProxyHwnd.cs
- CharEntityEncoderFallback.cs
- DataPagerCommandEventArgs.cs
- SettingsBindableAttribute.cs
- DisplayToken.cs
- RegexRunnerFactory.cs
- AuthenticationModulesSection.cs
- Serializer.cs
- PrincipalPermission.cs
- DataGridViewCheckBoxColumn.cs
- QilStrConcatenator.cs
- AutomationFocusChangedEventArgs.cs
- RadioButton.cs
- ReaderWriterLockWrapper.cs
- RC2.cs
- SelectedDatesCollection.cs
- DbProviderFactories.cs
- WebProxyScriptElement.cs
- ImageSourceConverter.cs
- DesigntimeLicenseContextSerializer.cs
- WebPartDisplayMode.cs
- RowVisual.cs
- ParameterCollection.cs
- DesignColumn.cs
- WebServiceParameterData.cs
- Location.cs
- ToolTipService.cs
- HelloMessageCD1.cs
- TrackingParameters.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- XPathArrayIterator.cs
- WorkItem.cs
- Configuration.cs
- DatatypeImplementation.cs
- TemplateControlParser.cs
- TransportConfigurationTypeElement.cs
- LockCookie.cs
- SoapParser.cs
- HtmlTableCell.cs
- NamespaceEmitter.cs
- Figure.cs
- cookiecollection.cs
- QueryResults.cs
- CompilerCollection.cs
- CqlParserHelpers.cs
- RequestCache.cs
- XmlSchemaSet.cs
- PackageRelationshipSelector.cs
- DirectoryInfo.cs
- TextSearch.cs
- HostingEnvironmentSection.cs
- NotConverter.cs
- cookiecontainer.cs
- DataColumnMapping.cs
- DatagridviewDisplayedBandsData.cs
- AutoGeneratedField.cs
- SendKeys.cs
- HttpWebRequestElement.cs
- ClonableStack.cs
- COM2Properties.cs
- DownloadProgressEventArgs.cs
- glyphs.cs
- CommentEmitter.cs
- TextBlockAutomationPeer.cs
- AccessorTable.cs
- TraceHelpers.cs
- StylusPoint.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- ContextMarshalException.cs
- LogLogRecordEnumerator.cs
- Rectangle.cs
- UrlAuthFailedErrorFormatter.cs
- WorkflowWebService.cs
- TimeSpanValidatorAttribute.cs
- DispatcherHookEventArgs.cs
- ResumeStoryboard.cs
- WizardPanel.cs
- HandleCollector.cs
- ObjectStateEntry.cs
- ComplusTypeValidator.cs
- XmlDomTextWriter.cs
- ResourcesBuildProvider.cs
- WebPartTransformer.cs
- TrustLevel.cs
- EventMappingSettings.cs
- BatchServiceHost.cs
- TypeSystem.cs
- WebPartConnectionsConfigureVerb.cs
- SyndicationDeserializer.cs
- CatalogPart.cs
- SqlConnectionStringBuilder.cs
- WindowsMenu.cs
- IDQuery.cs
- SolidBrush.cs
- TemplatedWizardStep.cs
- PathFigure.cs
- Invariant.cs
- DownloadProgressEventArgs.cs