Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / SecurityKeyIdentifier.cs / 1305376 / SecurityKeyIdentifier.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.IdentityModel.Tokens
{
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Globalization;
public class SecurityKeyIdentifier : IEnumerable
{
const int InitialSize = 2;
readonly List clauses;
bool isReadOnly;
public SecurityKeyIdentifier()
{
this.clauses = new List(InitialSize);
}
public SecurityKeyIdentifier(params SecurityKeyIdentifierClause[] clauses)
{
if (clauses == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("clauses");
}
this.clauses = new List(clauses.Length);
for (int i = 0; i < clauses.Length; i++)
{
Add(clauses[i]);
}
}
public SecurityKeyIdentifierClause this[int index]
{
get { return this.clauses[index]; }
}
public bool CanCreateKey
{
get
{
for (int i = 0; i < this.Count; i++)
{
if (this[i].CanCreateKey)
{
return true;
}
}
return false;
}
}
public int Count
{
get { return this.clauses.Count; }
}
public bool IsReadOnly
{
get { return this.isReadOnly; }
}
public void Add(SecurityKeyIdentifierClause clause)
{
if (this.isReadOnly)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly)));
}
if (clause == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("clause"));
}
this.clauses.Add(clause);
}
public SecurityKey CreateKey()
{
for (int i = 0; i < this.Count; i++)
{
if (this[i].CanCreateKey)
{
return this[i].CreateKey();
}
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.KeyIdentifierCannotCreateKey)));
}
public TClause Find() where TClause : SecurityKeyIdentifierClause
{
TClause clause;
if (!TryFind(out clause))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.NoKeyIdentifierClauseFound, typeof(TClause)), "TClause"));
}
return clause;
}
public IEnumerator GetEnumerator()
{
return this.clauses.GetEnumerator();
}
public void MakeReadOnly()
{
this.isReadOnly = true;
}
public override string ToString()
{
using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
{
writer.WriteLine("SecurityKeyIdentifier");
writer.WriteLine(" (");
writer.WriteLine(" IsReadOnly = {0},", this.IsReadOnly);
writer.WriteLine(" Count = {0}{1}", this.Count, this.Count > 0 ? "," : "");
for (int i = 0; i < this.Count; i++)
{
writer.WriteLine(" Clause[{0}] = {1}{2}", i, this[i], i < this.Count - 1 ? "," : "");
}
writer.WriteLine(" )");
return writer.ToString();
}
}
public bool TryFind(out TClause clause) where TClause : SecurityKeyIdentifierClause
{
for (int i = 0; i < this.clauses.Count; i++)
{
TClause c = this.clauses[i] as TClause;
if (c != null)
{
clause = c;
return true;
}
}
clause = null;
return false;
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.IdentityModel.Tokens
{
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Globalization;
public class SecurityKeyIdentifier : IEnumerable
{
const int InitialSize = 2;
readonly List clauses;
bool isReadOnly;
public SecurityKeyIdentifier()
{
this.clauses = new List(InitialSize);
}
public SecurityKeyIdentifier(params SecurityKeyIdentifierClause[] clauses)
{
if (clauses == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("clauses");
}
this.clauses = new List(clauses.Length);
for (int i = 0; i < clauses.Length; i++)
{
Add(clauses[i]);
}
}
public SecurityKeyIdentifierClause this[int index]
{
get { return this.clauses[index]; }
}
public bool CanCreateKey
{
get
{
for (int i = 0; i < this.Count; i++)
{
if (this[i].CanCreateKey)
{
return true;
}
}
return false;
}
}
public int Count
{
get { return this.clauses.Count; }
}
public bool IsReadOnly
{
get { return this.isReadOnly; }
}
public void Add(SecurityKeyIdentifierClause clause)
{
if (this.isReadOnly)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly)));
}
if (clause == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("clause"));
}
this.clauses.Add(clause);
}
public SecurityKey CreateKey()
{
for (int i = 0; i < this.Count; i++)
{
if (this[i].CanCreateKey)
{
return this[i].CreateKey();
}
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.KeyIdentifierCannotCreateKey)));
}
public TClause Find() where TClause : SecurityKeyIdentifierClause
{
TClause clause;
if (!TryFind(out clause))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.NoKeyIdentifierClauseFound, typeof(TClause)), "TClause"));
}
return clause;
}
public IEnumerator GetEnumerator()
{
return this.clauses.GetEnumerator();
}
public void MakeReadOnly()
{
this.isReadOnly = true;
}
public override string ToString()
{
using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
{
writer.WriteLine("SecurityKeyIdentifier");
writer.WriteLine(" (");
writer.WriteLine(" IsReadOnly = {0},", this.IsReadOnly);
writer.WriteLine(" Count = {0}{1}", this.Count, this.Count > 0 ? "," : "");
for (int i = 0; i < this.Count; i++)
{
writer.WriteLine(" Clause[{0}] = {1}{2}", i, this[i], i < this.Count - 1 ? "," : "");
}
writer.WriteLine(" )");
return writer.ToString();
}
}
public bool TryFind(out TClause clause) where TClause : SecurityKeyIdentifierClause
{
for (int i = 0; i < this.clauses.Count; i++)
{
TClause c = this.clauses[i] as TClause;
if (c != null)
{
clause = c;
return true;
}
}
clause = null;
return false;
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
}
// 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
- SaveFileDialog.cs
- MdiWindowListStrip.cs
- XPathSingletonIterator.cs
- RSAOAEPKeyExchangeFormatter.cs
- SoapServerMethod.cs
- MinimizableAttributeTypeConverter.cs
- EnumerableRowCollectionExtensions.cs
- __FastResourceComparer.cs
- ThrowHelper.cs
- SoapExtension.cs
- ImageListUtils.cs
- ADMembershipProvider.cs
- AttributeQuery.cs
- PrinterUnitConvert.cs
- WrapPanel.cs
- Brush.cs
- DataViewSetting.cs
- StatusBar.cs
- DESCryptoServiceProvider.cs
- TraceSection.cs
- HtmlControlPersistable.cs
- BuildResultCache.cs
- BooleanProjectedSlot.cs
- MetadataCacheItem.cs
- BaseCodeDomTreeGenerator.cs
- Point3DCollectionConverter.cs
- documentsequencetextcontainer.cs
- DataBindingHandlerAttribute.cs
- DataGrid.cs
- CategoryAttribute.cs
- ForeignKeyConstraint.cs
- WmlTextBoxAdapter.cs
- FileEnumerator.cs
- SoapHeaderException.cs
- XmlSchemaExporter.cs
- XamlFigureLengthSerializer.cs
- MarshalDirectiveException.cs
- Variant.cs
- Asn1IntegerConverter.cs
- ByteAnimation.cs
- MatrixTransform.cs
- Error.cs
- MediaPlayer.cs
- Overlapped.cs
- BaseProcessor.cs
- LinqDataSourceStatusEventArgs.cs
- FixedSOMLineCollection.cs
- BaseTreeIterator.cs
- Timeline.cs
- UITypeEditor.cs
- Schema.cs
- GraphicsState.cs
- EmulateRecognizeCompletedEventArgs.cs
- WinCategoryAttribute.cs
- Char.cs
- SqlMethodAttribute.cs
- OpCellTreeNode.cs
- AutomationPatternInfo.cs
- OleDbInfoMessageEvent.cs
- SubMenuStyle.cs
- MouseBinding.cs
- GridSplitter.cs
- VectorAnimationBase.cs
- BuilderElements.cs
- BitmapFrameDecode.cs
- SoapMessage.cs
- MLangCodePageEncoding.cs
- UnrecognizedAssertionsBindingElement.cs
- CqlErrorHelper.cs
- FormViewModeEventArgs.cs
- TextEditorLists.cs
- Profiler.cs
- DataGridViewCellStateChangedEventArgs.cs
- DataColumnMapping.cs
- HashSetEqualityComparer.cs
- SoapAttributeAttribute.cs
- SrgsDocumentParser.cs
- FileSecurity.cs
- Image.cs
- EntityContainerAssociationSetEnd.cs
- PointAnimationUsingKeyFrames.cs
- SmtpDigestAuthenticationModule.cs
- Converter.cs
- PersonalizationStateQuery.cs
- SuppressIldasmAttribute.cs
- DataService.cs
- Geometry.cs
- XmlArrayAttribute.cs
- ManualResetEventSlim.cs
- SqlDataReader.cs
- PlainXmlSerializer.cs
- CommandField.cs
- DeviceSpecific.cs
- UnitySerializationHolder.cs
- CaseInsensitiveComparer.cs
- DispatcherObject.cs
- BufferAllocator.cs
- CompiledXpathExpr.cs
- StylusPlugin.cs
- DataGridParentRows.cs