Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / Policy / EvidenceTypeDescriptor.cs / 1305376 / EvidenceTypeDescriptor.cs
// ==--==
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// [....]
//
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.Serialization;
namespace System.Security.Policy
{
///
/// Descriptor stored in the Evidence collection to detail the information we have about a type of
/// evidence. This descriptor also stores any evidence that's been generated of the specific type.
///
[Serializable]
internal sealed class EvidenceTypeDescriptor
{
[NonSerialized]
private bool m_hostCanGenerate;
[NonSerialized]
private bool m_generated;
private EvidenceBase m_hostEvidence;
private EvidenceBase m_assemblyEvidence;
// EvidenceTypeDescriptors are stored in Evidence indexed by the type they describe, so this
// information is redundant. We keep it around in checked builds to help debugging, but we can drop
// it from retial builds.
#if _DEBUG
[NonSerialized]
private Type m_evidenceType;
#endif // _DEBUG
public EvidenceTypeDescriptor()
{
}
///
/// Make a deep copy of a type descriptor
///
private EvidenceTypeDescriptor(EvidenceTypeDescriptor descriptor)
{
Contract.Assert(descriptor != null);
m_hostCanGenerate = descriptor.m_hostCanGenerate;
if (descriptor.m_assemblyEvidence != null)
{
m_assemblyEvidence = descriptor.m_assemblyEvidence.Clone() as EvidenceBase;
}
if (descriptor.m_hostEvidence != null)
{
m_hostEvidence = descriptor.m_hostEvidence.Clone() as EvidenceBase;
}
#if _DEBUG
m_evidenceType = descriptor.m_evidenceType;
#endif // _DEBUG
}
///
/// Evidence of this type supplied by the assembly
///
public EvidenceBase AssemblyEvidence
{
get { return m_assemblyEvidence; }
set
{
Contract.Assert(value != null);
#if _DEBUG
Contract.Assert(CheckEvidenceType(value), "Incorrect type of AssemblyEvidence set");
#endif
m_assemblyEvidence = value;
}
}
///
/// Flag indicating that we've already attempted to generate this type of evidence
///
public bool Generated
{
get { return m_generated; }
set
{
Contract.Assert(value, "Attempt to clear the Generated flag");
m_generated = value;
}
}
///
/// Has the HostSecurityManager has told us that it can potentially generate evidence of this type
///
public bool HostCanGenerate
{
get { return m_hostCanGenerate; }
set
{
Contract.Assert(value, "Attempt to clear HostCanGenerate flag");
m_hostCanGenerate = value;
}
}
///
/// Evidence of this type supplied by the CLR or the host
///
public EvidenceBase HostEvidence
{
get { return m_hostEvidence; }
set
{
Contract.Assert(value != null);
#if _DEBUG
Contract.Assert(CheckEvidenceType(value), "Incorrect type of HostEvidence set");
#endif
m_hostEvidence = value;
}
}
#if _DEBUG
///
/// Verify that evidence being stored in this descriptor is of the correct type
///
private bool CheckEvidenceType(EvidenceBase evidence)
{
Contract.Assert(evidence != null);
ILegacyEvidenceAdapter legacyAdapter = evidence as ILegacyEvidenceAdapter;
Type storedType = legacyAdapter == null ? evidence.GetType() : legacyAdapter.EvidenceType;
return m_evidenceType == null || m_evidenceType.IsAssignableFrom(storedType);
}
#endif // _DEBUG
///
/// Make a deep copy of this descriptor
///
public EvidenceTypeDescriptor Clone()
{
return new EvidenceTypeDescriptor(this);
}
#if _DEBUG
///
/// Set the type that this evidence descriptor refers to.
///
internal void SetEvidenceType(Type evidenceType)
{
Contract.Assert(evidenceType != null);
Contract.Assert(m_evidenceType == null, "Attempt to reset evidence type");
m_evidenceType = evidenceType;
}
#endif // _DEBUG
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==--==
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// [....]
//
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.Serialization;
namespace System.Security.Policy
{
///
/// Descriptor stored in the Evidence collection to detail the information we have about a type of
/// evidence. This descriptor also stores any evidence that's been generated of the specific type.
///
[Serializable]
internal sealed class EvidenceTypeDescriptor
{
[NonSerialized]
private bool m_hostCanGenerate;
[NonSerialized]
private bool m_generated;
private EvidenceBase m_hostEvidence;
private EvidenceBase m_assemblyEvidence;
// EvidenceTypeDescriptors are stored in Evidence indexed by the type they describe, so this
// information is redundant. We keep it around in checked builds to help debugging, but we can drop
// it from retial builds.
#if _DEBUG
[NonSerialized]
private Type m_evidenceType;
#endif // _DEBUG
public EvidenceTypeDescriptor()
{
}
///
/// Make a deep copy of a type descriptor
///
private EvidenceTypeDescriptor(EvidenceTypeDescriptor descriptor)
{
Contract.Assert(descriptor != null);
m_hostCanGenerate = descriptor.m_hostCanGenerate;
if (descriptor.m_assemblyEvidence != null)
{
m_assemblyEvidence = descriptor.m_assemblyEvidence.Clone() as EvidenceBase;
}
if (descriptor.m_hostEvidence != null)
{
m_hostEvidence = descriptor.m_hostEvidence.Clone() as EvidenceBase;
}
#if _DEBUG
m_evidenceType = descriptor.m_evidenceType;
#endif // _DEBUG
}
///
/// Evidence of this type supplied by the assembly
///
public EvidenceBase AssemblyEvidence
{
get { return m_assemblyEvidence; }
set
{
Contract.Assert(value != null);
#if _DEBUG
Contract.Assert(CheckEvidenceType(value), "Incorrect type of AssemblyEvidence set");
#endif
m_assemblyEvidence = value;
}
}
///
/// Flag indicating that we've already attempted to generate this type of evidence
///
public bool Generated
{
get { return m_generated; }
set
{
Contract.Assert(value, "Attempt to clear the Generated flag");
m_generated = value;
}
}
///
/// Has the HostSecurityManager has told us that it can potentially generate evidence of this type
///
public bool HostCanGenerate
{
get { return m_hostCanGenerate; }
set
{
Contract.Assert(value, "Attempt to clear HostCanGenerate flag");
m_hostCanGenerate = value;
}
}
///
/// Evidence of this type supplied by the CLR or the host
///
public EvidenceBase HostEvidence
{
get { return m_hostEvidence; }
set
{
Contract.Assert(value != null);
#if _DEBUG
Contract.Assert(CheckEvidenceType(value), "Incorrect type of HostEvidence set");
#endif
m_hostEvidence = value;
}
}
#if _DEBUG
///
/// Verify that evidence being stored in this descriptor is of the correct type
///
private bool CheckEvidenceType(EvidenceBase evidence)
{
Contract.Assert(evidence != null);
ILegacyEvidenceAdapter legacyAdapter = evidence as ILegacyEvidenceAdapter;
Type storedType = legacyAdapter == null ? evidence.GetType() : legacyAdapter.EvidenceType;
return m_evidenceType == null || m_evidenceType.IsAssignableFrom(storedType);
}
#endif // _DEBUG
///
/// Make a deep copy of this descriptor
///
public EvidenceTypeDescriptor Clone()
{
return new EvidenceTypeDescriptor(this);
}
#if _DEBUG
///
/// Set the type that this evidence descriptor refers to.
///
internal void SetEvidenceType(Type evidenceType)
{
Contract.Assert(evidenceType != null);
Contract.Assert(m_evidenceType == null, "Attempt to reset evidence type");
m_evidenceType = evidenceType;
}
#endif // _DEBUG
}
}
// 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
- MessageQueuePermissionEntry.cs
- QilGeneratorEnv.cs
- MailWebEventProvider.cs
- QilExpression.cs
- externdll.cs
- PtsPage.cs
- WebHttpSecurity.cs
- FixedDocument.cs
- DataList.cs
- XmlSchemaRedefine.cs
- LineServicesRun.cs
- OleDbErrorCollection.cs
- NavigateEvent.cs
- ResourceContainerWrapper.cs
- DocumentCollection.cs
- HashHelper.cs
- KoreanCalendar.cs
- NotFiniteNumberException.cs
- BindableTemplateBuilder.cs
- SqlDataSourceFilteringEventArgs.cs
- XAMLParseException.cs
- SearchExpression.cs
- List.cs
- XmlSchemaSet.cs
- TextParagraphView.cs
- IndicShape.cs
- LongMinMaxAggregationOperator.cs
- Validator.cs
- LinkLabel.cs
- SqlConnectionPoolProviderInfo.cs
- LazyTextWriterCreator.cs
- UriExt.cs
- TextTreePropertyUndoUnit.cs
- StreamGeometry.cs
- RegistryKey.cs
- Form.cs
- AnnotationDocumentPaginator.cs
- WindowsUserNameCachingSecurityTokenAuthenticator.cs
- HMACMD5.cs
- TextEditorCharacters.cs
- EditBehavior.cs
- DBConnectionString.cs
- SoapIncludeAttribute.cs
- ConfigurationConverterBase.cs
- Package.cs
- ChannelPoolSettingsElement.cs
- FreeIndexList.cs
- PointValueSerializer.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- RolePrincipal.cs
- SecurityCriticalDataForSet.cs
- TargetConverter.cs
- DbModificationClause.cs
- PermissionAttributes.cs
- TreeNodeCollection.cs
- DataListCommandEventArgs.cs
- StrongNameIdentityPermission.cs
- HideDisabledControlAdapter.cs
- EventWaitHandleSecurity.cs
- CoordinationService.cs
- MappingSource.cs
- ReaderWriterLockWrapper.cs
- SettingsAttributeDictionary.cs
- TransformValueSerializer.cs
- NotifyIcon.cs
- CharacterMetricsDictionary.cs
- FastEncoder.cs
- PersonalizationEntry.cs
- RawStylusSystemGestureInputReport.cs
- SqlUnionizer.cs
- DocumentOrderComparer.cs
- regiisutil.cs
- PasswordBoxAutomationPeer.cs
- Models.cs
- DynamicFilter.cs
- MasterPage.cs
- TextTabProperties.cs
- ConnectionManagementSection.cs
- StringExpressionSet.cs
- FontFaceLayoutInfo.cs
- ZipArchive.cs
- DataGridViewImageCell.cs
- DependencyObjectPropertyDescriptor.cs
- XslTransform.cs
- AdapterUtil.cs
- SqlConnectionManager.cs
- TextServicesHost.cs
- TextTreeInsertElementUndoUnit.cs
- EventHandlerList.cs
- SqlNotificationEventArgs.cs
- ListSourceHelper.cs
- GlyphElement.cs
- ExpressionPrinter.cs
- Geometry.cs
- HttpHeaderCollection.cs
- BrowserCapabilitiesCompiler.cs
- SchemaCollectionCompiler.cs
- DefaultEventAttribute.cs
- ADMembershipProvider.cs
- PartitionResolver.cs