Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / MessageProperties.cs / 1 / MessageProperties.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.ServiceModel.Security;
public sealed class MessageProperties : IDictionary, IDisposable
{
Property[] properties;
int propertyCount;
MessageEncoder encoder;
Uri via;
object allowOutputBatching;
SecurityMessageProperty security;
bool disposed;
const int InitialPropertyCount = 2;
const int MaxRecycledArrayLength = 8;
const string ViaKey = "Via";
const string AllowOutputBatchingKey = "AllowOutputBatching";
const string SecurityKey = "Security";
const string EncoderKey = "Encoder";
const int NotFoundIndex = -1;
const int ViaIndex = -2;
const int AllowOutputBatchingIndex = -3;
const int SecurityIndex = -4;
const int EncoderIndex = -5;
static object trueBool = true;
static object falseBool = false;
public MessageProperties()
{
}
public MessageProperties(MessageProperties properties)
{
CopyProperties(properties);
}
internal MessageProperties(KeyValuePair[] array)
{
if (array == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("array"));
CopyProperties(array);
}
void ThrowDisposed()
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(string.Empty, SR.GetString(SR.ObjectDisposed, this.GetType().ToString())));
}
public object this[string name]
{
get
{
if (disposed)
ThrowDisposed();
object value;
if (!TryGetValue(name, out value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MessagePropertyNotFound, name)));
}
return value;
}
set
{
if (disposed)
ThrowDisposed();
UpdateProperty(name, value, false);
}
}
internal bool CanRecycle
{
get
{
return properties == null || properties.Length <= MaxRecycledArrayLength;
}
}
public int Count
{
get
{
if (disposed)
ThrowDisposed();
return propertyCount;
}
}
public MessageEncoder Encoder
{
get
{
if (disposed)
ThrowDisposed();
return encoder;
}
set
{
if (disposed)
ThrowDisposed();
AdjustPropertyCount((object)encoder == null, (object)value == null);
encoder = value;
}
}
public bool AllowOutputBatching
{
get
{
if (disposed)
ThrowDisposed();
return (object)allowOutputBatching == trueBool;
}
set
{
if (disposed)
ThrowDisposed();
AdjustPropertyCount((object)allowOutputBatching == null, false);
if (value)
{
allowOutputBatching = trueBool;
}
else
{
allowOutputBatching = falseBool;
}
}
}
public bool IsFixedSize
{
get
{
if (disposed)
ThrowDisposed();
return false;
}
}
public bool IsReadOnly
{
get
{
if (disposed)
ThrowDisposed();
return false;
}
}
public ICollection Keys
{
get
{
if (disposed)
ThrowDisposed();
List keys = new List();
if ((object)via != null)
{
keys.Add(ViaKey);
}
if ((object)allowOutputBatching != null)
{
keys.Add(AllowOutputBatchingKey);
}
if ((object)security != null)
{
keys.Add(SecurityKey);
}
if ((object)encoder != null)
{
keys.Add(EncoderKey);
}
if (properties != null)
{
for (int i = 0; i < properties.Length; i++)
{
string propertyName = properties[i].Name;
if (propertyName == null)
{
break;
}
keys.Add(propertyName);
}
}
return keys;
}
}
public SecurityMessageProperty Security
{
get
{
if (disposed)
ThrowDisposed();
return security;
}
set
{
if (disposed)
ThrowDisposed();
AdjustPropertyCount((object)security == null, (object)value == null);
security = value;
}
}
public ICollection