Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,63 @@
// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace System.Runtime.Serialization
{
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.Security.Permissions;
static class AppSettings
{
internal const string MaxMimePartsAppSettingsString = "microsoft:xmldictionaryreader:maxmimeparts";
const int DefaultMaxMimeParts = 1000;
static int maxMimeParts;
static volatile bool settingsInitalized = false;
static object appSettingsLock = new object();
internal static int MaxMimeParts
{
get
{
EnsureSettingsLoaded();
return maxMimeParts;
}
}
[SuppressMessage(FxCop.Category.ReliabilityBasic, "Reliability104:CaughtAndHandledExceptionsRule",
Justification = "Handle the configuration exceptions here to avoid regressions on customer's existing scenarios")]
static void EnsureSettingsLoaded()
{
if (!settingsInitalized)
{
lock (appSettingsLock)
{
if (!settingsInitalized)
{
NameValueCollection appSettingsSection = null;
try
{
appSettingsSection = ConfigurationManager.AppSettings;
}
catch (ConfigurationErrorsException)
{
}
finally
{
if ((appSettingsSection == null) || !int.TryParse(appSettingsSection[MaxMimePartsAppSettingsString], out maxMimeParts))
{
maxMimeParts = DefaultMaxMimeParts;
}
settingsInitalized = true;
}
}
}
}
}
}
}

View File

@@ -0,0 +1,168 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization
{
using System.Security;
using System.Xml;
class Attributes
{
[Fx.Tag.SecurityNote(Critical = "Static field used to store the attribute names to read during deserialization."
+ " Static fields are marked SecurityCritical or readonly to prevent"
+ " data from being modified or leaked to other components in appdomain.")]
[SecurityCritical]
static XmlDictionaryString[] serializationLocalNames;
[Fx.Tag.SecurityNote(Critical = "Static field used to store the attribute names to read during deserialization."
+ " Static fields are marked SecurityCritical or readonly to prevent"
+ " data from being modified or leaked to other components in appdomain.")]
[SecurityCritical]
static XmlDictionaryString[] schemaInstanceLocalNames;
[Fx.Tag.SecurityNote(Critical = "Initializes critical static fields.",
Safe = "Doesn't leak anything.")]
[SecuritySafeCritical]
static Attributes()
{
serializationLocalNames = new XmlDictionaryString[]
{
DictionaryGlobals.IdLocalName,
DictionaryGlobals.ArraySizeLocalName,
DictionaryGlobals.RefLocalName,
DictionaryGlobals.ClrTypeLocalName,
DictionaryGlobals.ClrAssemblyLocalName,
DictionaryGlobals.ISerializableFactoryTypeLocalName
};
schemaInstanceLocalNames = new XmlDictionaryString[]
{
DictionaryGlobals.XsiNilLocalName,
DictionaryGlobals.XsiTypeLocalName
};
}
internal string Id;
internal string Ref;
internal string XsiTypeName;
internal string XsiTypeNamespace;
internal string XsiTypePrefix;
internal bool XsiNil;
internal string ClrAssembly;
internal string ClrType;
internal int ArraySZSize;
internal string FactoryTypeName;
internal string FactoryTypeNamespace;
internal string FactoryTypePrefix;
internal bool UnrecognizedAttributesFound;
[SecuritySafeCritical]
internal void Read(XmlReaderDelegator reader)
{
Reset();
while (reader.MoveToNextAttribute())
{
switch (reader.IndexOfLocalName(serializationLocalNames, DictionaryGlobals.SerializationNamespace))
{
case 0:
ReadId(reader);
break;
case 1:
ReadArraySize(reader);
break;
case 2:
ReadRef(reader);
break;
case 3:
ClrType = reader.Value;
break;
case 4:
ClrAssembly = reader.Value;
break;
case 5:
ReadFactoryType(reader);
break;
default:
switch (reader.IndexOfLocalName(schemaInstanceLocalNames, DictionaryGlobals.SchemaInstanceNamespace))
{
case 0:
ReadXsiNil(reader);
break;
case 1:
ReadXsiType(reader);
break;
default:
if (!reader.IsNamespaceUri(DictionaryGlobals.XmlnsNamespace))
UnrecognizedAttributesFound = true;
break;
}
break;
}
}
reader.MoveToElement();
}
internal void Reset()
{
Id = Globals.NewObjectId;
Ref = Globals.NewObjectId;
XsiTypeName = null;
XsiTypeNamespace = null;
XsiTypePrefix = null;
XsiNil = false;
ClrAssembly = null;
ClrType = null;
ArraySZSize = -1;
FactoryTypeName = null;
FactoryTypeNamespace = null;
FactoryTypePrefix = null;
UnrecognizedAttributesFound = false;
}
void ReadId(XmlReaderDelegator reader)
{
Id = reader.ReadContentAsString();
if (string.IsNullOrEmpty(Id))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.InvalidXsIdDefinition, Id)));
}
}
void ReadRef(XmlReaderDelegator reader)
{
Ref = reader.ReadContentAsString();
if (string.IsNullOrEmpty(Ref))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.InvalidXsRefDefinition, Ref)));
}
}
void ReadXsiNil(XmlReaderDelegator reader)
{
XsiNil = reader.ReadContentAsBoolean();
}
void ReadArraySize(XmlReaderDelegator reader)
{
ArraySZSize = reader.ReadContentAsInt();
if (ArraySZSize < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.InvalidSizeDefinition, ArraySZSize)));
}
void ReadXsiType(XmlReaderDelegator reader)
{
string xsiTypeString = reader.Value;
if (xsiTypeString != null && xsiTypeString.Length > 0)
XmlObjectSerializerReadContext.ParseQualifiedName(xsiTypeString, reader, out XsiTypeName, out XsiTypeNamespace, out XsiTypePrefix);
}
void ReadFactoryType(XmlReaderDelegator reader)
{
string factoryTypeString = reader.Value;
if (factoryTypeString != null && factoryTypeString.Length > 0)
XmlObjectSerializerReadContext.ParseQualifiedName(factoryTypeString, reader, out FactoryTypeName, out FactoryTypeNamespace, out FactoryTypePrefix);
}
}
}

View File

@@ -0,0 +1,116 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization
{
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Security;
[Fx.Tag.SecurityNote(Miscellaneous = "RequiresReview (Critical) - works on CodeGenerator objects, which require Critical access.")]
class BitFlagsGenerator
{
int bitCount;
CodeGenerator ilg;
LocalBuilder[] locals;
public BitFlagsGenerator(int bitCount, CodeGenerator ilg, string localName)
{
this.ilg = ilg;
this.bitCount = bitCount;
int localCount = (bitCount + 7) / 8;
locals = new LocalBuilder[localCount];
for (int i = 0; i < locals.Length; i++)
{
locals[i] = ilg.DeclareLocal(typeof(byte), localName + i, (byte) 0);
}
}
public static bool IsBitSet(byte[] bytes, int bitIndex)
{
int byteIndex = GetByteIndex(bitIndex);
byte bitValue = GetBitValue(bitIndex);
return (bytes[byteIndex] & bitValue) == bitValue;
}
public static void SetBit(byte[] bytes, int bitIndex)
{
int byteIndex = GetByteIndex(bitIndex);
byte bitValue = GetBitValue(bitIndex);
bytes[byteIndex] |= bitValue;
}
public int GetBitCount()
{
return bitCount;
}
public LocalBuilder GetLocal(int i)
{
return locals[i];
}
public int GetLocalCount()
{
return locals.Length;
}
public void Load(int bitIndex)
{
LocalBuilder local = locals[GetByteIndex(bitIndex)];
byte bitValue = GetBitValue(bitIndex);
ilg.Load(local);
ilg.Load(bitValue);
ilg.And();
ilg.Load(bitValue);
ilg.Ceq();
}
public void LoadArray()
{
LocalBuilder localArray = ilg.DeclareLocal(Globals.TypeOfByteArray, "localArray");
ilg.NewArray(typeof(byte), locals.Length);
ilg.Store(localArray);
for (int i = 0; i < locals.Length; i++)
{
ilg.StoreArrayElement(localArray, i, locals[i]);
}
ilg.Load(localArray);
}
public void Store(int bitIndex, bool value)
{
LocalBuilder local = locals[GetByteIndex(bitIndex)];
byte bitValue = GetBitValue(bitIndex);
if (value)
{
ilg.Load(local);
ilg.Load(bitValue);
ilg.Or();
ilg.Stloc(local);
}
else
{
ilg.Load(local);
ilg.Load(bitValue);
ilg.Not();
ilg.And();
ilg.Stloc(local);
}
}
static byte GetBitValue(int bitIndex)
{
return (byte)(1 << (bitIndex & 7));
}
static int GetByteIndex(int bitIndex)
{
return bitIndex >> 3;
}
}
}

View File

@@ -0,0 +1 @@
11fe57088f3d68f73433e57c2be0bc65df9dc1b2

View File

@@ -0,0 +1,118 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Runtime.Serialization
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class CollectionDataContractAttribute : Attribute
{
string name;
string ns;
string itemName;
string keyName;
string valueName;
bool isReference;
bool isNameSetExplicit;
bool isNamespaceSetExplicit;
bool isReferenceSetExplicit;
bool isItemNameSetExplicit;
bool isKeyNameSetExplicit;
bool isValueNameSetExplicit;
public CollectionDataContractAttribute()
{
}
public string Namespace
{
get { return ns; }
set
{
ns = value;
isNamespaceSetExplicit = true;
}
}
internal bool IsNamespaceSetExplicit
{
get { return isNamespaceSetExplicit; }
}
public string Name
{
get { return name; }
set
{
name = value;
isNameSetExplicit = true;
}
}
internal bool IsNameSetExplicit
{
get { return isNameSetExplicit; }
}
public string ItemName
{
get { return itemName; }
set
{
itemName = value;
isItemNameSetExplicit = true;
}
}
internal bool IsItemNameSetExplicit
{
get { return isItemNameSetExplicit; }
}
public string KeyName
{
get { return keyName; }
set
{
keyName = value;
isKeyNameSetExplicit = true;
}
}
public bool IsReference
{
get { return isReference; }
set
{
isReference = value;
isReferenceSetExplicit = true;
}
}
internal bool IsReferenceSetExplicit
{
get { return isReferenceSetExplicit; }
}
internal bool IsKeyNameSetExplicit
{
get { return isKeyNameSetExplicit; }
}
public string ValueName
{
get { return valueName; }
set
{
valueName = value;
isValueNameSetExplicit = true;
}
}
internal bool IsValueNameSetExplicit
{
get { return isValueNameSetExplicit; }
}
}
}

View File

@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
internal static class ConfigurationStrings
{
static string GetSectionPath(string sectionName)
{
return string.Concat(ConfigurationStrings.SectionGroupName, "/", sectionName);
}
static internal string DataContractSerializerSectionPath
{
get { return ConfigurationStrings.GetSectionPath(ConfigurationStrings.DataContractSerializerSectionName); }
}
static internal string NetDataContractSerializerSectionPath
{
get { return ConfigurationStrings.GetSectionPath(ConfigurationStrings.NetDataContractSerializerSectionName); }
}
internal const string SectionGroupName = "system.runtime.serialization";
internal const string DefaultCollectionName = ""; // String.Empty
internal const string DeclaredTypes = "declaredTypes";
internal const string Index = "index";
internal const string Parameter = "parameter";
internal const string Type = "type";
internal const string EnableUnsafeTypeForwarding = "enableUnsafeTypeForwarding";
internal const string DataContractSerializerSectionName = "dataContractSerializer";
internal const string NetDataContractSerializerSectionName = "netDataContractSerializer";
}
}

View File

@@ -0,0 +1,45 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Security.Permissions;
using System.Security;
public sealed partial class DataContractSerializerSection : ConfigurationSection
{
public DataContractSerializerSection()
: base()
{
}
[Fx.Tag.SecurityNote(Critical = "Elevates in order to get the DataContractSerializerSection config section."
+ " Caller should not leak config section instance to untrusted code.")]
[SecurityCritical]
[ConfigurationPermission(SecurityAction.Assert, Unrestricted = true)]
internal static DataContractSerializerSection UnsafeGetSection()
{
DataContractSerializerSection section =
(DataContractSerializerSection)ConfigurationManager.GetSection(ConfigurationStrings.DataContractSerializerSectionPath);
if (section == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigDataContractSerializerSectionLoadError)));
}
return section;
}
[ConfigurationProperty(ConfigurationStrings.DeclaredTypes, DefaultValue = null)]
public DeclaredTypeElementCollection DeclaredTypes
{
get { return (DeclaredTypeElementCollection)base[ConfigurationStrings.DeclaredTypes]; }
}
}
}

View File

@@ -0,0 +1,61 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Configuration;
using System.Security.Permissions;
using System.Security;
public sealed partial class DeclaredTypeElement : ConfigurationElement
{
public DeclaredTypeElement()
{
}
public DeclaredTypeElement(string typeName)
: this()
{
if (String.IsNullOrEmpty(typeName))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
}
this.Type = typeName;
}
[ConfigurationProperty(ConfigurationStrings.DefaultCollectionName, DefaultValue = null, Options = ConfigurationPropertyOptions.IsDefaultCollection)]
public TypeElementCollection KnownTypes
{
get { return (TypeElementCollection)base[ConfigurationStrings.DefaultCollectionName]; }
}
[ConfigurationProperty(ConfigurationStrings.Type, DefaultValue = "", Options = ConfigurationPropertyOptions.IsKey)]
[DeclaredTypeValidator()]
public string Type
{
get { return (string)base[ConfigurationStrings.Type]; }
set { base[ConfigurationStrings.Type] = value; }
}
[Fx.Tag.SecurityNote(Critical = "Calls the critical methods of PartialTrustHelpers",
Safe = "PartialTrustHelpers.IsInFullTrust demands for FullTrust")]
[SecuritySafeCritical]
protected override void PostDeserialize()
{
// Perf optimization. If the configuration is coming from machine.config
// It is safe and we don't need to check for permissions.
if (EvaluationContext.IsMachineLevel)
{
return;
}
if (!PartialTrustHelpers.IsInFullTrust())
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigDataContractSerializerSectionLoadError)));
}
}
}
}

View File

@@ -0,0 +1,174 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Configuration;
using System.Globalization;
[ConfigurationCollection(typeof(DeclaredTypeElement))]
public sealed class DeclaredTypeElementCollection : ConfigurationElementCollection
{
public DeclaredTypeElementCollection()
{
}
public DeclaredTypeElement this[int index]
{
get
{
DeclaredTypeElement retval = (DeclaredTypeElement)BaseGet(index);
return retval;
}
set
{
// Only validate input if config is not Read-Only, otherwise
// let BaseAdd throw appropriate exception
if (!this.IsReadOnly())
{
if (value == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
}
if (BaseGet(index) != null)
{
BaseRemoveAt(index);
}
}
BaseAdd(index, value);
}
}
public new DeclaredTypeElement this[string typeName]
{
get
{
if (String.IsNullOrEmpty(typeName))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
}
DeclaredTypeElement retval = (DeclaredTypeElement)BaseGet(typeName);
return retval;
}
set
{
// Only validate input if config is not Read-Only, otherwise
// let Add throw appropriate exception
if (!this.IsReadOnly())
{
if (String.IsNullOrEmpty(typeName))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
}
if (value == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
}
if (BaseGet(typeName) != null)
{
BaseRemove(typeName);
}
else
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new IndexOutOfRangeException(SR.GetString(SR.ConfigIndexOutOfRange,
typeName)));
}
}
Add(value);
}
}
public void Add(DeclaredTypeElement element)
{
// Only validate input if config is not Read-Only, otherwise
// let BaseAdd throw appropriate exception
if (!this.IsReadOnly())
{
if (element == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
}
BaseAdd(element);
}
public void Clear()
{
BaseClear();
}
public bool Contains(string typeName)
{
if (String.IsNullOrEmpty(typeName))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
}
return this.BaseGet(typeName) != null;
}
protected override ConfigurationElement CreateNewElement()
{
DeclaredTypeElement retval = new DeclaredTypeElement();
return retval;
}
protected override Object GetElementKey(ConfigurationElement element)
{
if (element == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
return ((DeclaredTypeElement)element).Type;
}
public int IndexOf(DeclaredTypeElement element)
{
if (element == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
return BaseIndexOf(element);
}
public void Remove(DeclaredTypeElement element)
{
// Only validate input if config is not Read-Only, otherwise
// let BaseRemove throw appropriate exception
if (!this.IsReadOnly())
{
if (element == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
}
BaseRemove(this.GetElementKey(element));
}
public void Remove(string typeName)
{
// Only validate input if config is not Read-Only, otherwise
// let BaseRemove throw appropriate exception
if (!this.IsReadOnly())
{
if (String.IsNullOrEmpty(typeName))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
}
}
BaseRemove(typeName);
}
public void RemoveAt(int index)
{
BaseRemoveAt(index);
}
}
}

View File

@@ -0,0 +1,32 @@
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Configuration;
using System.Runtime.Serialization;
internal class DeclaredTypeValidator : ConfigurationValidatorBase
{
public override bool CanValidate(Type type)
{
return (typeof(string) == type);
}
public override void Validate(object value)
{
string type = (string)value;
if (type.StartsWith(Globals.TypeOfObject.FullName, StringComparison.Ordinal))
{
Type t = Type.GetType(type, false);
if (t != null && Globals.TypeOfObject.Equals(t))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.KnownTypeConfigObject));
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Configuration;
[AttributeUsage(AttributeTargets.Property)]
internal sealed class DeclaredTypeValidatorAttribute : ConfigurationValidatorAttribute
{
public override ConfigurationValidatorBase ValidatorInstance
{
get { return new DeclaredTypeValidator(); }
}
}
}

View File

@@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Security.Permissions;
using System.Security;
public sealed partial class NetDataContractSerializerSection : ConfigurationSection
{
public NetDataContractSerializerSection()
: base()
{
}
[Fx.Tag.SecurityNote(Critical = "Elevates in order to get the NetDataContractSerializerSection config section."
+ " Caller should not leak config section instance to untrusted code.")]
[SecurityCritical]
[ConfigurationPermission(SecurityAction.Assert, Unrestricted = true)]
internal static bool TryUnsafeGetSection(out NetDataContractSerializerSection section)
{
section = (NetDataContractSerializerSection)ConfigurationManager.GetSection(ConfigurationStrings.NetDataContractSerializerSectionPath);
return section != null;
}
[ConfigurationProperty(ConfigurationStrings.EnableUnsafeTypeForwarding, DefaultValue = false)]
public bool EnableUnsafeTypeForwarding
{
get { return (bool)base[ConfigurationStrings.EnableUnsafeTypeForwarding]; }
}
}
}

View File

@@ -0,0 +1,109 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Configuration;
using System.Xml;
using System.Security;
public sealed partial class ParameterElement : ConfigurationElement
{
public ParameterElement()
{
}
public ParameterElement(string typeName)
: this()
{
if (String.IsNullOrEmpty(typeName))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
}
this.Type = typeName;
}
public ParameterElement(int index)
: this()
{
this.Index = index;
}
[ConfigurationProperty(ConfigurationStrings.Index, DefaultValue = 0)]
[IntegerValidator(MinValue = 0)]
public int Index
{
get { return (int)base[ConfigurationStrings.Index]; }
set { base[ConfigurationStrings.Index] = value; }
}
[ConfigurationProperty(ConfigurationStrings.DefaultCollectionName, DefaultValue = null, Options = ConfigurationPropertyOptions.IsDefaultCollection)]
public ParameterElementCollection Parameters
{
get { return (ParameterElementCollection)base[ConfigurationStrings.DefaultCollectionName]; }
}
protected override void PostDeserialize()
{
this.Validate();
}
protected override void PreSerialize(XmlWriter writer)
{
this.Validate();
}
[ConfigurationProperty(ConfigurationStrings.Type, DefaultValue = "")]
[StringValidator(MinLength = 0)]
public string Type
{
get { return (string)base[ConfigurationStrings.Type]; }
set
{
if (String.IsNullOrEmpty(value))
{
value = String.Empty;
}
base[ConfigurationStrings.Type] = value;
}
}
void Validate()
{
PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
if ((propertyInfo[ConfigurationStrings.Index].ValueOrigin == PropertyValueOrigin.Default) &&
(propertyInfo[ConfigurationStrings.Type].ValueOrigin == PropertyValueOrigin.Default))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
SR.GetString(SR.ConfigMustSetTypeOrIndex)));
}
if ((propertyInfo[ConfigurationStrings.Index].ValueOrigin != PropertyValueOrigin.Default) &&
(propertyInfo[ConfigurationStrings.Type].ValueOrigin != PropertyValueOrigin.Default))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
SR.GetString(SR.ConfigMustOnlySetTypeOrIndex)));
}
if ((propertyInfo[ConfigurationStrings.Index].ValueOrigin != PropertyValueOrigin.Default) && this.Parameters.Count > 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
SR.GetString(SR.ConfigMustOnlyAddParamsWithType)));
}
}
internal readonly Guid identity = Guid.NewGuid();
[Fx.Tag.SecurityNote(Miscellaneous = "RequiresReview - Loads type given name in configuration."
+ " Since this information is used to determine whether a particular type is included as a known type,"
+ " changes to the logic should be reviewed.")]
internal Type GetType(string rootType, Type[] typeArgs)
{
return TypeElement.GetType(rootType, typeArgs, this.Type, this.Index, this.Parameters);
}
}
}

View File

@@ -0,0 +1,132 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Configuration;
using System.Globalization;
[ConfigurationCollection(typeof(ParameterElement), AddItemName = ConfigurationStrings.Parameter, CollectionType = ConfigurationElementCollectionType.BasicMap)]
public sealed class ParameterElementCollection : ConfigurationElementCollection
{
public ParameterElementCollection()
{
this.AddElementName = ConfigurationStrings.Parameter;
}
public ParameterElement this[int index]
{
get
{
ParameterElement retval = (ParameterElement)BaseGet(index);
return retval;
}
set
{
// Only validate input if config is not Read-Only, otherwise
// let BaseAdd throw appropriate exception
if (!this.IsReadOnly())
{
if (value == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
}
if (BaseGet(index) != null)
{
BaseRemoveAt(index);
}
}
BaseAdd(index, value);
}
}
public void Add(ParameterElement element)
{
// Only validate input if config is not Read-Only, otherwise
// let BaseAdd throw appropriate exception
if (!this.IsReadOnly())
{
if (element == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
}
BaseAdd(element);
}
public void Clear()
{
BaseClear();
}
public override ConfigurationElementCollectionType CollectionType
{
get { return ConfigurationElementCollectionType.BasicMap; }
}
public bool Contains(string typeName)
{
if (String.IsNullOrEmpty(typeName))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
}
return this.BaseGet(typeName) != null;
}
protected override ConfigurationElement CreateNewElement()
{
ParameterElement retval = new ParameterElement();
return retval;
}
protected override string ElementName
{
get { return ConfigurationStrings.Parameter; }
}
protected override Object GetElementKey(ConfigurationElement element)
{
if (element == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
return ((ParameterElement)element).identity;
}
public int IndexOf(ParameterElement element)
{
if (element == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
return BaseIndexOf(element);
}
public void Remove(ParameterElement element)
{
// Only validate input if config is not Read-Only, otherwise
// let BaseRemove throw appropriate exception
if (!this.IsReadOnly())
{
if (element == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
}
BaseRemove(this.GetElementKey(element));
}
public void RemoveAt(int index)
{
BaseRemoveAt(index);
}
}
}

View File

@@ -0,0 +1,147 @@
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
// This code was produced by a tool, ConfigPropertyGenerator.exe, by reflecting over
// System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
// Please add this file to the project that built the assembly.
// Doing so will provide better performance for retrieving the ConfigurationElement Properties.
// If compilation errors occur, make sure that the Properties property has not
// already been provided. If it has, decide if you want the version produced by
// this tool or by the developer.
// If build errors result, make sure the config class is marked with the partial keyword.
// To regenerate a new Properties.cs after changes to the configuration OM for
// this assembly, simply run Indigo\Suites\Configuration\Infrastructure\ConfigPropertyGenerator.
// If any changes affect this file, the suite will fail. Instructions on how to
// update Properties.cs will be included in the tests output file (ConfigPropertyGenerator.out).
using System.Configuration;
using System.Globalization;
// configType.Name: DeclaredTypeElement
namespace System.Runtime.Serialization.Configuration
{
public sealed partial class DeclaredTypeElement
{
ConfigurationPropertyCollection properties;
protected override ConfigurationPropertyCollection Properties
{
get
{
if (this.properties == null)
{
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
properties.Add(new ConfigurationProperty("", typeof(System.Runtime.Serialization.Configuration.TypeElementCollection), null, null, null, System.Configuration.ConfigurationPropertyOptions.IsDefaultCollection));
properties.Add(new ConfigurationProperty("type", typeof(System.String), string.Empty, null, new System.Runtime.Serialization.Configuration.DeclaredTypeValidator(), System.Configuration.ConfigurationPropertyOptions.IsKey));
this.properties = properties;
}
return this.properties;
}
}
}
}
// configType.Name: NetDataContractSerializerSection
namespace System.Runtime.Serialization.Configuration
{
public sealed partial class NetDataContractSerializerSection
{
ConfigurationPropertyCollection properties;
protected override ConfigurationPropertyCollection Properties
{
get
{
if (this.properties == null)
{
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
properties.Add(new ConfigurationProperty("enableUnsafeTypeForwarding", typeof(System.Boolean), false, null, null, System.Configuration.ConfigurationPropertyOptions.None));
this.properties = properties;
}
return this.properties;
}
}
}
}
// configType.Name: ParameterElement
namespace System.Runtime.Serialization.Configuration
{
public sealed partial class ParameterElement
{
ConfigurationPropertyCollection properties;
protected override ConfigurationPropertyCollection Properties
{
get
{
if (this.properties == null)
{
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
properties.Add(new ConfigurationProperty("index", typeof(System.Int32), 0, null, new System.Configuration.IntegerValidator(0, 2147483647, false), System.Configuration.ConfigurationPropertyOptions.None));
properties.Add(new ConfigurationProperty("", typeof(System.Runtime.Serialization.Configuration.ParameterElementCollection), null, null, null, System.Configuration.ConfigurationPropertyOptions.IsDefaultCollection));
properties.Add(new ConfigurationProperty("type", typeof(System.String), string.Empty, null, new System.Configuration.StringValidator(0, 2147483647, null), System.Configuration.ConfigurationPropertyOptions.None));
this.properties = properties;
}
return this.properties;
}
}
}
}
// configType.Name: DataContractSerializerSection
namespace System.Runtime.Serialization.Configuration
{
public sealed partial class DataContractSerializerSection
{
ConfigurationPropertyCollection properties;
protected override ConfigurationPropertyCollection Properties
{
get
{
if (this.properties == null)
{
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
properties.Add(new ConfigurationProperty("declaredTypes", typeof(System.Runtime.Serialization.Configuration.DeclaredTypeElementCollection), null, null, null, System.Configuration.ConfigurationPropertyOptions.None));
this.properties = properties;
}
return this.properties;
}
}
}
}
// configType.Name: TypeElement
namespace System.Runtime.Serialization.Configuration
{
public sealed partial class TypeElement
{
ConfigurationPropertyCollection properties;
protected override ConfigurationPropertyCollection Properties
{
get
{
if (this.properties == null)
{
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
properties.Add(new ConfigurationProperty("", typeof(System.Runtime.Serialization.Configuration.ParameterElementCollection), null, null, null, System.Configuration.ConfigurationPropertyOptions.IsDefaultCollection));
properties.Add(new ConfigurationProperty("type", typeof(System.String), string.Empty, null, new System.Configuration.StringValidator(0, 2147483647, null), System.Configuration.ConfigurationPropertyOptions.None));
properties.Add(new ConfigurationProperty("index", typeof(System.Int32), 0, null, new System.Configuration.IntegerValidator(0, 2147483647, false), System.Configuration.ConfigurationPropertyOptions.None));
this.properties = properties;
}
return this.properties;
}
}
}
}

View File

@@ -0,0 +1,34 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System.Configuration;
public sealed class SerializationSectionGroup : ConfigurationSectionGroup
{
static public SerializationSectionGroup GetSectionGroup(Configuration config)
{
if (config == null)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config");
}
#pragma warning suppress 56506 // [....], config is checked above
return (SerializationSectionGroup)config.SectionGroups[ConfigurationStrings.SectionGroupName];
}
public DataContractSerializerSection DataContractSerializer
{
get { return (DataContractSerializerSection)this.Sections[ConfigurationStrings.DataContractSerializerSectionName]; }
}
public NetDataContractSerializerSection NetDataContractSerializer
{
get { return (NetDataContractSerializerSection)this.Sections[ConfigurationStrings.NetDataContractSerializerSectionName]; }
}
}
}

View File

@@ -0,0 +1,122 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Runtime.Serialization.Configuration
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.ServiceModel.Diagnostics;
using System.Security;
public sealed partial class TypeElement : ConfigurationElement
{
public TypeElement()
{
}
public TypeElement(string typeName)
: this()
{
if (String.IsNullOrEmpty(typeName))
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
}
this.Type = typeName;
}
internal string Key
{
get { return this.key; }
}
[ConfigurationProperty(ConfigurationStrings.DefaultCollectionName, DefaultValue = null, Options = ConfigurationPropertyOptions.IsDefaultCollection)]
public ParameterElementCollection Parameters
{
get { return (ParameterElementCollection)base[ConfigurationStrings.DefaultCollectionName]; }
}
protected override void Reset(ConfigurationElement parentElement)
{
TypeElement parent = (TypeElement)parentElement;
this.key = parent.key;
base.Reset(parentElement);
}
[ConfigurationProperty(ConfigurationStrings.Type, DefaultValue = "")]
[StringValidator(MinLength = 0)]
public string Type
{
get { return (string)base[ConfigurationStrings.Type]; }
set { base[ConfigurationStrings.Type] = value; }
}
[ConfigurationProperty(ConfigurationStrings.Index, DefaultValue = 0)]
[IntegerValidator(MinValue = 0)]
public int Index
{
get { return (int)base[ConfigurationStrings.Index]; }
set { base[ConfigurationStrings.Index] = value; }
}
[Fx.Tag.SecurityNote(Miscellaneous = "RequiresReview - Loads type given name in configuration."
+ " Since this information is used to determine whether a particular type is included as a known type,"
+ " changes to the logic should be reviewed.")]
internal Type GetType(string rootType, Type[] typeArgs)
{
return GetType(rootType, typeArgs, this.Type, this.Index, this.Parameters);
}
[Fx.Tag.SecurityNote(Miscellaneous = "RequiresReview - Loads type given name in configuration."
+ " Since this information is used to determine whether a particular type is included as a known type,"
+ " changes to the logic should be reviewed.")]
internal static Type GetType(string rootType, Type[] typeArgs, string type, int index, ParameterElementCollection parameters)
{
if (String.IsNullOrEmpty(type))
{
if (typeArgs == null || index >= typeArgs.Length)
{
int typeArgsCount = typeArgs == null ? 0 : typeArgs.Length;
if (typeArgsCount == 0)
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.KnownTypeConfigIndexOutOfBoundsZero,
rootType,
typeArgsCount,
index));
}
else
{
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.KnownTypeConfigIndexOutOfBounds,
rootType,
typeArgsCount,
index));
}
}
return typeArgs[index];
}
Type t = System.Type.GetType(type, true);
if (t.IsGenericTypeDefinition)
{
if (parameters.Count != t.GetGenericArguments().Length)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.KnownTypeConfigGenericParamMismatch,
type,
t.GetGenericArguments().Length,
parameters.Count));
Type[] types = new Type[parameters.Count];
for (int i = 0; i < types.Length; ++i)
{
types[i] = parameters[i].GetType(rootType, typeArgs);
}
t = t.MakeGenericType(types);
}
return t;
}
string key = Guid.NewGuid().ToString();
}
}

Some files were not shown because too many files have changed in this diff Show More