You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,192 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="IXmlSerializable.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization.Advanced {
|
||||
|
||||
using System.Xml.Schema;
|
||||
using System.Xml;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
/// <include file='doc\SchemaImporterExtension.uex' path='docs/doc[@for="SchemaImporterExtension"]/*' />
|
||||
///<internalonly/>
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public abstract class SchemaImporterExtension {
|
||||
/// <include file='doc\SchemaImporterExtension.uex' path='docs/doc[@for="SchemaImporterExtension.ImportSchemaType"]/*' />
|
||||
public virtual string ImportSchemaType(string name, string ns, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer,
|
||||
CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <include file='doc\SchemaImporterExtension.uex' path='docs/doc[@for="SchemaImporterExtension.ImportSchemaType1"]/*' />
|
||||
public virtual string ImportSchemaType(XmlSchemaType type, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer,
|
||||
CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <include file='doc\SchemaImporterExtension.uex' path='docs/doc[@for="SchemaImporterExtension.ImportSchemaType1"]/*' />
|
||||
public virtual string ImportAnyElement(XmlSchemaAny any, bool mixed, XmlSchemas schemas, XmlSchemaImporter importer,
|
||||
CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <include file='doc\SchemaImporterExtension.uex' path='docs/doc[@for="SchemaImporterExtension.ImportDefaultValue"]/*' />
|
||||
public virtual CodeExpression ImportDefaultValue(string value, string type) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class SchemaImporterExtensionCollection : CollectionBase {
|
||||
Hashtable exNames;
|
||||
|
||||
internal Hashtable Names {
|
||||
get {
|
||||
if (exNames == null)
|
||||
exNames = new Hashtable();
|
||||
return exNames;
|
||||
}
|
||||
}
|
||||
|
||||
public int Add(SchemaImporterExtension extension) {
|
||||
return Add(extension.GetType().FullName, extension);
|
||||
}
|
||||
|
||||
public int Add(string name, Type type) {
|
||||
if (type.IsSubclassOf(typeof(SchemaImporterExtension))) {
|
||||
return Add(name, (SchemaImporterExtension)Activator.CreateInstance(type));
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException(Res.GetString(Res.XmlInvalidSchemaExtension, type));
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(string name) {
|
||||
if (Names[name] != null) {
|
||||
List.Remove(Names[name]);
|
||||
Names[name] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public new void Clear() {
|
||||
Names.Clear();
|
||||
List.Clear();
|
||||
}
|
||||
|
||||
internal SchemaImporterExtensionCollection Clone() {
|
||||
SchemaImporterExtensionCollection clone = new SchemaImporterExtensionCollection();
|
||||
clone.exNames = (Hashtable)this.Names.Clone();
|
||||
foreach (object o in this.List) {
|
||||
clone.List.Add(o);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
public SchemaImporterExtension this[int index] {
|
||||
get { return (SchemaImporterExtension)List[index]; }
|
||||
set { List[index] = value; }
|
||||
}
|
||||
|
||||
internal int Add(string name, SchemaImporterExtension extension) {
|
||||
if (Names[name] != null) {
|
||||
if (Names[name].GetType() != extension.GetType()) {
|
||||
throw new InvalidOperationException(Res.GetString(Res.XmlConfigurationDuplicateExtension, name));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
Names[name] = extension;
|
||||
return List.Add(extension);
|
||||
}
|
||||
|
||||
public void Insert(int index, SchemaImporterExtension extension) {
|
||||
List.Insert(index, extension);
|
||||
}
|
||||
|
||||
public int IndexOf(SchemaImporterExtension extension) {
|
||||
return List.IndexOf(extension);
|
||||
}
|
||||
|
||||
public bool Contains(SchemaImporterExtension extension) {
|
||||
return List.Contains(extension);
|
||||
}
|
||||
|
||||
public void Remove(SchemaImporterExtension extension) {
|
||||
List.Remove(extension);
|
||||
}
|
||||
|
||||
public void CopyTo(SchemaImporterExtension[] array, int index) {
|
||||
List.CopyTo(array, index);
|
||||
}
|
||||
}
|
||||
|
||||
internal class MappedTypeDesc {
|
||||
string name;
|
||||
string ns;
|
||||
XmlSchemaType xsdType;
|
||||
XmlSchemaObject context;
|
||||
string clrType;
|
||||
SchemaImporterExtension extension;
|
||||
CodeNamespace code;
|
||||
bool exported = false;
|
||||
StringCollection references;
|
||||
|
||||
internal MappedTypeDesc(string clrType, string name, string ns, XmlSchemaType xsdType, XmlSchemaObject context, SchemaImporterExtension extension, CodeNamespace code, StringCollection references) {
|
||||
this.clrType = clrType.Replace('+', '.');
|
||||
this.name = name;
|
||||
this.ns = ns;
|
||||
this.xsdType = xsdType;
|
||||
this.context = context;
|
||||
this.code = code;
|
||||
this.references = references;
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
internal SchemaImporterExtension Extension { get { return extension; } }
|
||||
internal string Name { get { return clrType; } }
|
||||
|
||||
internal StringCollection ReferencedAssemblies {
|
||||
get {
|
||||
if (references == null)
|
||||
references = new StringCollection();
|
||||
return references;
|
||||
}
|
||||
}
|
||||
|
||||
internal CodeTypeDeclaration ExportTypeDefinition(CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit) {
|
||||
if (exported)
|
||||
return null;
|
||||
exported = true;
|
||||
|
||||
foreach(CodeNamespaceImport import in code.Imports) {
|
||||
codeNamespace.Imports.Add(import);
|
||||
}
|
||||
CodeTypeDeclaration codeClass = null;
|
||||
string comment = Res.GetString(Res.XmlExtensionComment, extension.GetType().FullName);
|
||||
foreach(CodeTypeDeclaration type in code.Types) {
|
||||
if (clrType == type.Name) {
|
||||
if (codeClass != null)
|
||||
throw new InvalidOperationException(Res.GetString(Res.XmlExtensionDuplicateDefinition, extension.GetType().FullName, clrType));
|
||||
codeClass = type;
|
||||
}
|
||||
type.Comments.Add(new CodeCommentStatement(comment, false));
|
||||
codeNamespace.Types.Add(type);
|
||||
}
|
||||
if (codeCompileUnit != null) {
|
||||
foreach(string reference in ReferencedAssemblies) {
|
||||
if (codeCompileUnit.ReferencedAssemblies.Contains(reference))
|
||||
continue;
|
||||
codeCompileUnit.ReferencedAssemblies.Add(reference);
|
||||
}
|
||||
}
|
||||
return codeClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="AppSettings.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization {
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Security.Permissions;
|
||||
|
||||
internal static class AppSettings {
|
||||
private const string UseLegacySerializerGenerationAppSettingsString = "System:Xml:Serialization:UseLegacySerializerGeneration";
|
||||
private static bool? useLegacySerializerGeneration;
|
||||
private static volatile bool settingsInitalized = false;
|
||||
private static object appSettingsLock = new object();
|
||||
|
||||
internal static bool? UseLegacySerializerGeneration {
|
||||
get {
|
||||
EnsureSettingsLoaded();
|
||||
return useLegacySerializerGeneration;
|
||||
}
|
||||
}
|
||||
|
||||
static void EnsureSettingsLoaded() {
|
||||
#if CONFIGURATION_DEP
|
||||
if (!settingsInitalized) {
|
||||
lock (appSettingsLock) {
|
||||
if (!settingsInitalized) {
|
||||
NameValueCollection appSettingsSection = null;
|
||||
try {
|
||||
appSettingsSection = ConfigurationManager.AppSettings;
|
||||
}
|
||||
catch (ConfigurationErrorsException) {
|
||||
}
|
||||
finally {
|
||||
bool tempUseLegacySerializerGeneration;
|
||||
if ((appSettingsSection == null) || !bool.TryParse(appSettingsSection[UseLegacySerializerGenerationAppSettingsString], out tempUseLegacySerializerGeneration)) {
|
||||
useLegacySerializerGeneration = null;
|
||||
}
|
||||
else {
|
||||
useLegacySerializerGeneration = (bool?)tempUseLegacySerializerGeneration;
|
||||
}
|
||||
|
||||
settingsInitalized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CodeExporter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.ComponentModel;
|
||||
using System.Xml.Schema;
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Reflection;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Permissions;
|
||||
|
||||
/// <include file='doc\CodeExporter.uex' path='docs/doc[@for="CodeExporter"]/*' />
|
||||
///<internalonly/>
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
[PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
|
||||
public abstract class CodeExporter {
|
||||
Hashtable exportedMappings;
|
||||
Hashtable exportedClasses; // TypeMapping -> CodeTypeDeclaration
|
||||
CodeNamespace codeNamespace;
|
||||
CodeCompileUnit codeCompileUnit;
|
||||
bool rootExported;
|
||||
TypeScope scope;
|
||||
CodeAttributeDeclarationCollection includeMetadata = new CodeAttributeDeclarationCollection();
|
||||
CodeGenerationOptions options;
|
||||
CodeDomProvider codeProvider;
|
||||
CodeAttributeDeclaration generatedCodeAttribute;
|
||||
|
||||
internal CodeExporter(CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit, CodeDomProvider codeProvider, CodeGenerationOptions options, Hashtable exportedMappings) {
|
||||
if (codeNamespace != null)
|
||||
CodeGenerator.ValidateIdentifiers(codeNamespace);
|
||||
this.codeNamespace = codeNamespace;
|
||||
if (codeCompileUnit != null) {
|
||||
if (!codeCompileUnit.ReferencedAssemblies.Contains("System.dll"))
|
||||
codeCompileUnit.ReferencedAssemblies.Add("System.dll");
|
||||
if (!codeCompileUnit.ReferencedAssemblies.Contains("System.Xml.dll"))
|
||||
codeCompileUnit.ReferencedAssemblies.Add("System.Xml.dll");
|
||||
}
|
||||
this.codeCompileUnit = codeCompileUnit;
|
||||
this.options = options;
|
||||
this.exportedMappings = exportedMappings;
|
||||
this.codeProvider = codeProvider;
|
||||
}
|
||||
|
||||
internal CodeCompileUnit CodeCompileUnit {
|
||||
get { return codeCompileUnit; }
|
||||
}
|
||||
|
||||
internal CodeNamespace CodeNamespace {
|
||||
get {
|
||||
if (codeNamespace == null)
|
||||
codeNamespace = new CodeNamespace();
|
||||
return codeNamespace;
|
||||
}
|
||||
}
|
||||
internal CodeDomProvider CodeProvider {
|
||||
get {
|
||||
if (codeProvider == null)
|
||||
codeProvider = new Microsoft.CSharp.CSharpCodeProvider();
|
||||
return codeProvider;
|
||||
}
|
||||
}
|
||||
|
||||
internal Hashtable ExportedClasses {
|
||||
get {
|
||||
if (exportedClasses == null)
|
||||
exportedClasses = new Hashtable();
|
||||
return exportedClasses;
|
||||
}
|
||||
}
|
||||
|
||||
internal Hashtable ExportedMappings {
|
||||
get {
|
||||
if (exportedMappings == null)
|
||||
exportedMappings = new Hashtable();
|
||||
return exportedMappings;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool GenerateProperties {
|
||||
get { return (options & CodeGenerationOptions.GenerateProperties) != 0; }
|
||||
}
|
||||
|
||||
internal CodeAttributeDeclaration GeneratedCodeAttribute {
|
||||
get {
|
||||
if (generatedCodeAttribute == null) {
|
||||
CodeAttributeDeclaration decl = new CodeAttributeDeclaration(typeof(GeneratedCodeAttribute).FullName);
|
||||
Assembly a = Assembly.GetEntryAssembly();
|
||||
if (a == null) {
|
||||
a = Assembly.GetExecutingAssembly();
|
||||
if (a == null) {
|
||||
a = typeof(CodeExporter).Assembly;
|
||||
}
|
||||
}
|
||||
AssemblyName assemblyName = a.GetName();
|
||||
decl.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(assemblyName.Name)));
|
||||
string version = GetProductVersion(a);
|
||||
decl.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(version == null ? assemblyName.Version.ToString() : version)));
|
||||
generatedCodeAttribute = decl;
|
||||
}
|
||||
return generatedCodeAttribute;
|
||||
}
|
||||
}
|
||||
|
||||
internal static CodeAttributeDeclaration FindAttributeDeclaration(Type type, CodeAttributeDeclarationCollection metadata) {
|
||||
foreach (CodeAttributeDeclaration attribute in metadata) {
|
||||
if (attribute.Name == type.FullName || attribute.Name == type.Name) {
|
||||
return attribute;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetProductVersion(Assembly assembly) {
|
||||
object[] attributes = assembly.GetCustomAttributes(true);
|
||||
for ( int i = 0; i<attributes.Length; i++ ) {
|
||||
if (attributes[i] is AssemblyInformationalVersionAttribute) {
|
||||
AssemblyInformationalVersionAttribute version = (AssemblyInformationalVersionAttribute)attributes[i];
|
||||
return version.InformationalVersion;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <include file='doc\XmlCodeExporter.uex' path='docs/doc[@for="XmlCodeExporter.IncludeMetadata"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public CodeAttributeDeclarationCollection IncludeMetadata {
|
||||
get { return includeMetadata; }
|
||||
}
|
||||
|
||||
internal TypeScope Scope {
|
||||
get { return scope; }
|
||||
}
|
||||
|
||||
internal void CheckScope(TypeScope scope) {
|
||||
if (this.scope == null) {
|
||||
this.scope = scope;
|
||||
}
|
||||
else if (this.scope != scope) {
|
||||
throw new InvalidOperationException(Res.GetString(Res.XmlMappingsScopeMismatch));
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract void ExportDerivedStructs(StructMapping mapping);
|
||||
internal abstract void EnsureTypesExported(Accessor[] accessors, string ns);
|
||||
|
||||
internal static void AddWarningComment(CodeCommentStatementCollection comments, string text) {
|
||||
Debug.Assert(comments != null);
|
||||
comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlCodegenWarningDetails, text), false));
|
||||
}
|
||||
|
||||
internal void ExportRoot(StructMapping mapping, Type includeType) {
|
||||
if (!rootExported) {
|
||||
rootExported = true;
|
||||
ExportDerivedStructs(mapping);
|
||||
|
||||
for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) {
|
||||
if (!derived.ReferencedByElement && derived.IncludeInSchema && !derived.IsAnonymousType) {
|
||||
CodeAttributeDeclaration include = new CodeAttributeDeclaration(includeType.FullName);
|
||||
include.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(derived.TypeDesc.FullName)));
|
||||
includeMetadata.Add(include);
|
||||
}
|
||||
}
|
||||
Hashtable typesIncluded = new Hashtable();
|
||||
foreach (TypeMapping m in Scope.TypeMappings) {
|
||||
if (m is ArrayMapping) {
|
||||
ArrayMapping arrayMapping = (ArrayMapping) m;
|
||||
if (ShouldInclude(arrayMapping) && !typesIncluded.Contains(arrayMapping.TypeDesc.FullName)) {
|
||||
CodeAttributeDeclaration include = new CodeAttributeDeclaration(includeType.FullName);
|
||||
include.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(arrayMapping.TypeDesc.FullName)));
|
||||
includeMetadata.Add(include);
|
||||
typesIncluded.Add(arrayMapping.TypeDesc.FullName, string.Empty);
|
||||
EnsureTypesExported(arrayMapping.Elements, arrayMapping.Namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ShouldInclude(ArrayMapping arrayMapping) {
|
||||
if (arrayMapping.ReferencedByElement)
|
||||
return false;
|
||||
if (arrayMapping.Next != null)
|
||||
return false;
|
||||
if (arrayMapping.Elements.Length == 1) {
|
||||
TypeKind kind = arrayMapping.Elements[0].Mapping.TypeDesc.Kind;
|
||||
if (kind == TypeKind.Node)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < arrayMapping.Elements.Length; i++) {
|
||||
if (arrayMapping.Elements[i].Name != arrayMapping.Elements[i].Mapping.DefaultElementName) {
|
||||
// in the case we need custom attributes to serialize an array instance, we cannot include arrau mapping without explicit reference.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal CodeTypeDeclaration ExportEnum(EnumMapping mapping, Type type) {
|
||||
CodeTypeDeclaration codeClass = new CodeTypeDeclaration(mapping.TypeDesc.Name);
|
||||
|
||||
codeClass.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
|
||||
codeClass.IsEnum = true;
|
||||
if (mapping.IsFlags && mapping.Constants.Length > 31) {
|
||||
codeClass.BaseTypes.Add(new CodeTypeReference(typeof(long)));
|
||||
}
|
||||
codeClass.TypeAttributes |= TypeAttributes.Public;
|
||||
CodeNamespace.Types.Add(codeClass);
|
||||
for (int i = 0; i < mapping.Constants.Length; i++) {
|
||||
ExportConstant(codeClass, mapping.Constants[i], type, mapping.IsFlags, 1L << i);
|
||||
}
|
||||
if (mapping.IsFlags) {
|
||||
// Add [FlagsAttribute]
|
||||
CodeAttributeDeclaration flags = new CodeAttributeDeclaration(typeof(FlagsAttribute).FullName);
|
||||
codeClass.CustomAttributes.Add(flags);
|
||||
}
|
||||
CodeGenerator.ValidateIdentifiers(codeClass);
|
||||
return codeClass;
|
||||
}
|
||||
|
||||
internal void AddTypeMetadata(CodeAttributeDeclarationCollection metadata, Type type, string defaultName, string name, string ns, bool includeInSchema) {
|
||||
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName);
|
||||
if (name == null || name.Length == 0) {
|
||||
attribute.Arguments.Add(new CodeAttributeArgument("AnonymousType", new CodePrimitiveExpression(true)));
|
||||
}
|
||||
else {
|
||||
if (defaultName != name) {
|
||||
attribute.Arguments.Add(new CodeAttributeArgument("TypeName", new CodePrimitiveExpression(name)));
|
||||
}
|
||||
}
|
||||
if (ns != null && ns.Length != 0) {
|
||||
attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
|
||||
}
|
||||
if (!includeInSchema) {
|
||||
attribute.Arguments.Add(new CodeAttributeArgument("IncludeInSchema", new CodePrimitiveExpression(false)));
|
||||
}
|
||||
if (attribute.Arguments.Count > 0) {
|
||||
metadata.Add(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void AddIncludeMetadata(CodeAttributeDeclarationCollection metadata, StructMapping mapping, Type type) {
|
||||
if (mapping.IsAnonymousType)
|
||||
return;
|
||||
for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) {
|
||||
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName);
|
||||
attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(derived.TypeDesc.FullName)));
|
||||
metadata.Add(attribute);
|
||||
AddIncludeMetadata(metadata, derived, type);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ExportConstant(CodeTypeDeclaration codeClass, ConstantMapping constant, Type type, bool init, long enumValue) {
|
||||
CodeMemberField field = new CodeMemberField(typeof(int).FullName, constant.Name);
|
||||
field.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
|
||||
if (init)
|
||||
field.InitExpression = new CodePrimitiveExpression(enumValue);
|
||||
codeClass.Members.Add(field);
|
||||
if (constant.XmlName != constant.Name) {
|
||||
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName);
|
||||
attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(constant.XmlName)));
|
||||
field.CustomAttributes.Add(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
internal static object PromoteType(Type type, object value) {
|
||||
if (type == typeof(sbyte)) {
|
||||
return ((IConvertible)value).ToInt16(null);
|
||||
}
|
||||
else if (type == typeof(UInt16)) {
|
||||
return ((IConvertible)value).ToInt32(null);
|
||||
}
|
||||
else if (type == typeof(UInt32)) {
|
||||
return ((IConvertible)value).ToInt64(null);
|
||||
}
|
||||
else if (type == typeof(UInt64)) {
|
||||
return ((IConvertible)value).ToDecimal(null);
|
||||
}
|
||||
else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
internal CodeMemberProperty CreatePropertyDeclaration(CodeMemberField field, string name, string typeName) {
|
||||
CodeMemberProperty prop = new CodeMemberProperty();
|
||||
prop.Type = new CodeTypeReference(typeName);
|
||||
prop.Name = name;
|
||||
prop.Attributes = (prop.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
|
||||
|
||||
//add get
|
||||
CodeMethodReturnStatement ret = new CodeMethodReturnStatement();
|
||||
ret.Expression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name);
|
||||
prop.GetStatements.Add(ret);
|
||||
|
||||
CodeAssignStatement propertySet = new CodeAssignStatement();
|
||||
CodeExpression left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name);
|
||||
CodeExpression right = new CodePropertySetValueReferenceExpression();
|
||||
propertySet.Left = left;
|
||||
propertySet.Right = right;
|
||||
|
||||
if (EnableDataBinding)
|
||||
{
|
||||
prop.SetStatements.Add(propertySet);
|
||||
prop.SetStatements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), RaisePropertyChangedEventMethod.Name, new CodePrimitiveExpression(name)));
|
||||
}
|
||||
else
|
||||
prop.SetStatements.Add(propertySet);
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
||||
internal static string MakeFieldName(string name) {
|
||||
return CodeIdentifier.MakeCamel(name) + "Field";
|
||||
}
|
||||
|
||||
internal void AddPropertyChangedNotifier(CodeTypeDeclaration codeClass)
|
||||
{
|
||||
if (EnableDataBinding && codeClass != null)
|
||||
{
|
||||
if (codeClass.BaseTypes.Count == 0)
|
||||
{
|
||||
codeClass.BaseTypes.Add(typeof(object));
|
||||
}
|
||||
codeClass.BaseTypes.Add(new CodeTypeReference(typeof(System.ComponentModel.INotifyPropertyChanged)));
|
||||
codeClass.Members.Add(PropertyChangedEvent);
|
||||
codeClass.Members.Add(RaisePropertyChangedEventMethod);
|
||||
}
|
||||
}
|
||||
|
||||
bool EnableDataBinding {
|
||||
get { return (options & CodeGenerationOptions.EnableDataBinding) != 0; }
|
||||
}
|
||||
|
||||
internal static CodeMemberMethod RaisePropertyChangedEventMethod
|
||||
{
|
||||
get
|
||||
{
|
||||
CodeMemberMethod raisePropertyChangedEventMethod = new CodeMemberMethod();
|
||||
raisePropertyChangedEventMethod.Name = "RaisePropertyChanged";
|
||||
raisePropertyChangedEventMethod.Attributes = MemberAttributes.Family | MemberAttributes.Final;
|
||||
CodeArgumentReferenceExpression propertyName = new CodeArgumentReferenceExpression("propertyName");
|
||||
raisePropertyChangedEventMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), propertyName.ParameterName));
|
||||
CodeVariableReferenceExpression propertyChanged = new CodeVariableReferenceExpression("propertyChanged");
|
||||
raisePropertyChangedEventMethod.Statements.Add(new CodeVariableDeclarationStatement(typeof(PropertyChangedEventHandler), propertyChanged.VariableName, new CodeEventReferenceExpression(new CodeThisReferenceExpression(), PropertyChangedEvent.Name)));
|
||||
CodeConditionStatement ifStatement = new CodeConditionStatement(new CodeBinaryOperatorExpression(propertyChanged, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)));
|
||||
raisePropertyChangedEventMethod.Statements.Add(ifStatement);
|
||||
ifStatement.TrueStatements.Add(new CodeDelegateInvokeExpression(propertyChanged, new CodeThisReferenceExpression(), new CodeObjectCreateExpression(typeof(PropertyChangedEventArgs), propertyName)));
|
||||
return raisePropertyChangedEventMethod;
|
||||
}
|
||||
}
|
||||
|
||||
internal static CodeMemberEvent PropertyChangedEvent
|
||||
{
|
||||
get
|
||||
{
|
||||
CodeMemberEvent propertyChangedEvent = new CodeMemberEvent();
|
||||
propertyChangedEvent.Attributes = MemberAttributes.Public;
|
||||
propertyChangedEvent.Name = "PropertyChanged";
|
||||
propertyChangedEvent.Type = new CodeTypeReference(typeof(PropertyChangedEventHandler));
|
||||
propertyChangedEvent.ImplementationTypes.Add(typeof(System.ComponentModel.INotifyPropertyChanged));
|
||||
return propertyChangedEvent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CodeGenerationOptions.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">ElenaK</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace System.Xml.Serialization
|
||||
{
|
||||
using System.ComponentModel;
|
||||
|
||||
/// <include file='doc\CodeGenerationOptions.uex' path='docs/doc[@for="CodeGenerationOptions"]/*' />
|
||||
/// <devdoc>
|
||||
/// Specifies varoius flavours of XmlCodeExporter generated code.
|
||||
/// </devdoc>
|
||||
[Flags]
|
||||
public enum CodeGenerationOptions
|
||||
{
|
||||
/// <include file='doc\CodeGenerationOptions.uex' path='docs/doc[@for="CodeGenerationOptions.None"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>
|
||||
/// Default: use clr primitives for xsd primitives, generate fields and arrays.
|
||||
/// </para>
|
||||
/// </devdoc>
|
||||
[XmlIgnore]
|
||||
None = 0,
|
||||
/// <include file='doc\CodeGenerationOptions.uex' path='docs/doc[@for="CodeGenerationOptions.GenerateProperties"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>
|
||||
/// Generate propertyes instead of fields.
|
||||
/// </para>
|
||||
/// </devdoc>
|
||||
[XmlEnum("properties")]
|
||||
GenerateProperties = 0x1,
|
||||
|
||||
/// <include file='doc\CodeGenerationOptions.uex' path='docs/doc[@for="CodeGenerationOptions.GenerateNewAsync"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>
|
||||
/// Generate new RAD asynchronous pattern. The feature allows customers to use an event-based model for invoking Web services asynchronously.
|
||||
/// </para>
|
||||
/// </devdoc>
|
||||
[XmlEnum("newAsync")]
|
||||
GenerateNewAsync = 0x2,
|
||||
|
||||
/// <include file='doc\CodeGenerationOptions.uex' path='docs/doc[@for="CodeGenerationOptions.GenerateOldAsync"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>
|
||||
/// Generate old asynchronous pattern: BeginXXX/EndXXX.
|
||||
/// </para>
|
||||
/// </devdoc>
|
||||
[XmlEnum("oldAsync")]
|
||||
GenerateOldAsync = 0x4,
|
||||
|
||||
|
||||
/// <include file='doc\CodeGenerationOptions.uex' path='docs/doc[@for="CodeGenerationOptions.GenerateOrder"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>
|
||||
/// Generate OM using explicit ordering feature.
|
||||
/// </para>
|
||||
/// </devdoc>
|
||||
[XmlEnum("order")]
|
||||
GenerateOrder = 0x08,
|
||||
|
||||
/// <include file='doc\CodeGenerationOptions.uex' path='docs/doc[@for="CodeGenerationOptions.EnableDataBinding"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>
|
||||
/// Generate OM INotifyPropertyChanged interface to enable data binding.
|
||||
/// </para>
|
||||
/// </devdoc>
|
||||
[XmlEnum("enableDataBinding")]
|
||||
EnableDataBinding = 0x10,
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,259 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CodeIdentifier.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization {
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using Microsoft.CSharp;
|
||||
|
||||
/// <include file='doc\CodeIdentifier.uex' path='docs/doc[@for="CodeIdentifier"]/*' />
|
||||
///<internalonly/>
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public class CodeIdentifier {
|
||||
internal static CodeDomProvider csharp = new CSharpCodeProvider();
|
||||
internal const int MaxIdentifierLength = 511;
|
||||
|
||||
[Obsolete("This class should never get constructed as it contains only static methods.")]
|
||||
public CodeIdentifier() {
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifier.uex' path='docs/doc[@for="CodeIdentifier.MakePascal"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public static string MakePascal(string identifier) {
|
||||
identifier = MakeValid(identifier);
|
||||
if (identifier.Length <= 2)
|
||||
return identifier.ToUpper(CultureInfo.InvariantCulture);
|
||||
else if (char.IsLower(identifier[0]))
|
||||
return char.ToUpper(identifier[0], CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture) + identifier.Substring(1);
|
||||
else
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifier.uex' path='docs/doc[@for="CodeIdentifier.MakeCamel"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public static string MakeCamel(string identifier) {
|
||||
identifier = MakeValid(identifier);
|
||||
if (identifier.Length <= 2)
|
||||
return identifier.ToLower(CultureInfo.InvariantCulture);
|
||||
else if (char.IsUpper(identifier[0]))
|
||||
return char.ToLower(identifier[0], CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture) + identifier.Substring(1);
|
||||
else
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifier.uex' path='docs/doc[@for="CodeIdentifier.MakeValid"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public static string MakeValid(string identifier) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < identifier.Length && builder.Length < MaxIdentifierLength; i++) {
|
||||
char c = identifier[i];
|
||||
if (IsValid(c)) {
|
||||
if (builder.Length == 0 && !IsValidStart(c)) {
|
||||
builder.Append("Item");
|
||||
}
|
||||
builder.Append(c);
|
||||
}
|
||||
}
|
||||
if (builder.Length == 0) return "Item";
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
internal static string MakeValidInternal(string identifier) {
|
||||
if (identifier.Length > 30) {
|
||||
return "Item";
|
||||
}
|
||||
return MakeValid(identifier);
|
||||
}
|
||||
|
||||
static bool IsValidStart(char c) {
|
||||
|
||||
// the given char is already a valid name character
|
||||
#if DEBUG
|
||||
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
|
||||
if (!IsValid(c)) throw new ArgumentException(Res.GetString(Res.XmlInternalErrorDetails, "Invalid identifier character " + ((Int16)c).ToString(CultureInfo.InvariantCulture)), "c");
|
||||
#endif
|
||||
|
||||
// First char cannot be a number
|
||||
if (Char.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IsValid(char c) {
|
||||
UnicodeCategory uc = Char.GetUnicodeCategory(c);
|
||||
// each char must be Lu, Ll, Lt, Lm, Lo, Nd, Mn, Mc, Pc
|
||||
//
|
||||
switch (uc) {
|
||||
case UnicodeCategory.UppercaseLetter: // Lu
|
||||
case UnicodeCategory.LowercaseLetter: // Ll
|
||||
case UnicodeCategory.TitlecaseLetter: // Lt
|
||||
case UnicodeCategory.ModifierLetter: // Lm
|
||||
case UnicodeCategory.OtherLetter: // Lo
|
||||
case UnicodeCategory.DecimalDigitNumber: // Nd
|
||||
case UnicodeCategory.NonSpacingMark: // Mn
|
||||
case UnicodeCategory.SpacingCombiningMark: // Mc
|
||||
case UnicodeCategory.ConnectorPunctuation: // Pc
|
||||
break;
|
||||
case UnicodeCategory.LetterNumber:
|
||||
case UnicodeCategory.OtherNumber:
|
||||
case UnicodeCategory.EnclosingMark:
|
||||
case UnicodeCategory.SpaceSeparator:
|
||||
case UnicodeCategory.LineSeparator:
|
||||
case UnicodeCategory.ParagraphSeparator:
|
||||
case UnicodeCategory.Control:
|
||||
case UnicodeCategory.Format:
|
||||
case UnicodeCategory.Surrogate:
|
||||
case UnicodeCategory.PrivateUse:
|
||||
case UnicodeCategory.DashPunctuation:
|
||||
case UnicodeCategory.OpenPunctuation:
|
||||
case UnicodeCategory.ClosePunctuation:
|
||||
case UnicodeCategory.InitialQuotePunctuation:
|
||||
case UnicodeCategory.FinalQuotePunctuation:
|
||||
case UnicodeCategory.OtherPunctuation:
|
||||
case UnicodeCategory.MathSymbol:
|
||||
case UnicodeCategory.CurrencySymbol:
|
||||
case UnicodeCategory.ModifierSymbol:
|
||||
case UnicodeCategory.OtherSymbol:
|
||||
case UnicodeCategory.OtherNotAssigned:
|
||||
return false;
|
||||
default:
|
||||
#if DEBUG
|
||||
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
|
||||
throw new ArgumentException(Res.GetString(Res.XmlInternalErrorDetails, "Unhandled category " + uc), "c");
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void CheckValidIdentifier(string ident) {
|
||||
if (!CodeGenerator.IsValidLanguageIndependentIdentifier(ident))
|
||||
throw new ArgumentException(Res.GetString(Res.XmlInvalidIdentifier, ident), "ident");
|
||||
}
|
||||
|
||||
internal static string GetCSharpName(string name) {
|
||||
//
|
||||
|
||||
return EscapeKeywords(name.Replace('+', '.'), csharp);
|
||||
}
|
||||
|
||||
static int GetCSharpName(Type t, Type[] parameters, int index, StringBuilder sb) {
|
||||
if (t.DeclaringType != null && t.DeclaringType != t) {
|
||||
index = GetCSharpName(t.DeclaringType, parameters, index, sb);
|
||||
sb.Append(".");
|
||||
}
|
||||
string name = t.Name;
|
||||
int nameEnd = name.IndexOf('`');
|
||||
if (nameEnd < 0) {
|
||||
nameEnd = name.IndexOf('!');
|
||||
}
|
||||
if (nameEnd > 0) {
|
||||
EscapeKeywords(name.Substring(0, nameEnd), csharp, sb);
|
||||
sb.Append("<");
|
||||
int arguments = Int32.Parse(name.Substring(nameEnd+1), CultureInfo.InvariantCulture) + index;
|
||||
for (; index < arguments; index++) {
|
||||
sb.Append(GetCSharpName(parameters[index]));
|
||||
if (index < arguments -1) {
|
||||
sb.Append(",");
|
||||
}
|
||||
}
|
||||
sb.Append(">");
|
||||
}
|
||||
else {
|
||||
EscapeKeywords(name, csharp, sb);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
internal static string GetCSharpName(Type t) {
|
||||
int rank = 0;
|
||||
while (t.IsArray) {
|
||||
t = t.GetElementType();
|
||||
rank++;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("global::");
|
||||
string ns = t.Namespace;
|
||||
if (ns != null && ns.Length > 0) {
|
||||
string[] parts = ns.Split(new char[] {'.'});
|
||||
for (int i = 0; i < parts.Length; i++) {
|
||||
EscapeKeywords(parts[i], csharp, sb);
|
||||
sb.Append(".");
|
||||
}
|
||||
}
|
||||
|
||||
Type[] arguments = t.IsGenericType || t.ContainsGenericParameters ? t.GetGenericArguments() : new Type[0];
|
||||
GetCSharpName(t, arguments, 0, sb);
|
||||
for (int i = 0; i < rank; i++) {
|
||||
sb.Append("[]");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
//
|
||||
/*
|
||||
internal static string GetTypeName(string name, CodeDomProvider codeProvider) {
|
||||
return codeProvider.GetTypeOutput(new CodeTypeReference(name));
|
||||
}
|
||||
*/
|
||||
|
||||
static void EscapeKeywords(string identifier, CodeDomProvider codeProvider, StringBuilder sb) {
|
||||
if (identifier == null || identifier.Length == 0)
|
||||
return;
|
||||
string originalIdentifier = identifier;
|
||||
int arrayCount = 0;
|
||||
while (identifier.EndsWith("[]", StringComparison.Ordinal)) {
|
||||
arrayCount++;
|
||||
identifier = identifier.Substring(0, identifier.Length - 2);
|
||||
}
|
||||
if (identifier.Length > 0) {
|
||||
CheckValidIdentifier(identifier);
|
||||
identifier = codeProvider.CreateEscapedIdentifier(identifier);
|
||||
sb.Append(identifier);
|
||||
}
|
||||
for (int i = 0; i < arrayCount; i++) {
|
||||
sb.Append("[]");
|
||||
}
|
||||
}
|
||||
|
||||
static string EscapeKeywords(string identifier, CodeDomProvider codeProvider) {
|
||||
if (identifier == null || identifier.Length == 0) return identifier;
|
||||
string originalIdentifier = identifier;
|
||||
string[] names = identifier.Split(new char[] {'.', ',', '<', '>'});
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int separator = -1;
|
||||
for (int i = 0; i < names.Length; i++) {
|
||||
if (separator >= 0) {
|
||||
sb.Append(originalIdentifier.Substring(separator, 1));
|
||||
}
|
||||
separator++;
|
||||
separator += names[i].Length;
|
||||
string escapedName = names[i].Trim();
|
||||
EscapeKeywords(escapedName, codeProvider, sb);
|
||||
}
|
||||
if (sb.Length != originalIdentifier.Length)
|
||||
return sb.ToString();
|
||||
return originalIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CodeIdentifiers.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
|
||||
class CaseInsensitiveKeyComparer : CaseInsensitiveComparer, IEqualityComparer{
|
||||
public CaseInsensitiveKeyComparer() : base(CultureInfo.CurrentCulture) {
|
||||
}
|
||||
|
||||
bool IEqualityComparer.Equals(Object x, Object y) {
|
||||
return (Compare(x, y) == 0);
|
||||
}
|
||||
|
||||
int IEqualityComparer.GetHashCode(Object obj) {
|
||||
string s = obj as string;
|
||||
if (s == null)
|
||||
throw new ArgumentException(null, "obj");
|
||||
|
||||
return s.ToUpper(CultureInfo.CurrentCulture).GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers"]/*' />
|
||||
///<internalonly/>
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public class CodeIdentifiers {
|
||||
Hashtable identifiers;
|
||||
Hashtable reservedIdentifiers;
|
||||
ArrayList list;
|
||||
bool camelCase;
|
||||
|
||||
public CodeIdentifiers() : this(true) {
|
||||
}
|
||||
|
||||
public CodeIdentifiers(bool caseSensitive) {
|
||||
if (caseSensitive) {
|
||||
identifiers = new Hashtable();
|
||||
reservedIdentifiers = new Hashtable();
|
||||
}
|
||||
else {
|
||||
IEqualityComparer comparer = new CaseInsensitiveKeyComparer();
|
||||
identifiers = new Hashtable(comparer);
|
||||
reservedIdentifiers = new Hashtable(comparer);
|
||||
}
|
||||
|
||||
list = new ArrayList();
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.Clear"]/*' />
|
||||
public void Clear(){
|
||||
identifiers.Clear();
|
||||
list.Clear();
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.UseCamelCasing"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public bool UseCamelCasing {
|
||||
get { return camelCase; }
|
||||
set { camelCase = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.MakeRightCase"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public string MakeRightCase(string identifier) {
|
||||
if (camelCase)
|
||||
return CodeIdentifier.MakeCamel(identifier);
|
||||
else
|
||||
return CodeIdentifier.MakePascal(identifier);
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.MakeUnique"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public string MakeUnique(string identifier) {
|
||||
if (IsInUse(identifier)) {
|
||||
for (int i = 1; ; i++) {
|
||||
string newIdentifier = identifier + i.ToString(CultureInfo.InvariantCulture);
|
||||
if (!IsInUse(newIdentifier)) {
|
||||
identifier = newIdentifier;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check that we did not violate the identifier length after appending the suffix.
|
||||
if (identifier.Length > CodeIdentifier.MaxIdentifierLength) {
|
||||
return MakeUnique("Item");
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.AddReserved"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public void AddReserved(string identifier) {
|
||||
reservedIdentifiers.Add(identifier, identifier);
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.RemoveReserved"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public void RemoveReserved(string identifier) {
|
||||
reservedIdentifiers.Remove(identifier);
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.AddUnique"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public string AddUnique(string identifier, object value) {
|
||||
identifier = MakeUnique(identifier);
|
||||
Add(identifier, value);
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.IsInUse"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public bool IsInUse(string identifier) {
|
||||
return identifiers.Contains(identifier) || reservedIdentifiers.Contains(identifier);
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.Add"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public void Add(string identifier, object value) {
|
||||
identifiers.Add(identifier, value);
|
||||
list.Add(value);
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.Remove"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public void Remove(string identifier) {
|
||||
list.Remove(identifiers[identifier]);
|
||||
identifiers.Remove(identifier);
|
||||
}
|
||||
|
||||
/// <include file='doc\CodeIdentifiers.uex' path='docs/doc[@for="CodeIdentifiers.ToArray"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public object ToArray(Type type) {
|
||||
//Array array = Array.CreateInstance(type, identifiers.Values.Count);
|
||||
//identifiers.Values.CopyTo(array, 0);
|
||||
Array array = Array.CreateInstance(type, list.Count);
|
||||
list.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
|
||||
internal CodeIdentifiers Clone() {
|
||||
CodeIdentifiers newIdentifiers = new CodeIdentifiers();
|
||||
newIdentifiers.identifiers = (Hashtable)this.identifiers.Clone();
|
||||
newIdentifiers.reservedIdentifiers = (Hashtable)this.reservedIdentifiers.Clone();
|
||||
newIdentifiers.list = (ArrayList)this.list.Clone();
|
||||
newIdentifiers.camelCase = this.camelCase;
|
||||
|
||||
return newIdentifiers;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,279 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="Compiler.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization {
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Principal;
|
||||
using System.Security.Policy;
|
||||
using System.Threading;
|
||||
using System.Xml.Serialization.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
internal class Compiler {
|
||||
bool debugEnabled = DiagnosticsSwitches.KeepTempFiles.Enabled;
|
||||
Hashtable imports = new Hashtable();
|
||||
StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);
|
||||
|
||||
[ResourceExposure(ResourceScope.Machine)]
|
||||
protected string[] Imports {
|
||||
get {
|
||||
string[] array = new string[imports.Values.Count];
|
||||
imports.Values.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
// SxS: This method does not take any resource name and does not expose any resources to the caller.
|
||||
// It's OK to suppress the SxS warning.
|
||||
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
internal void AddImport(Type type, Hashtable types) {
|
||||
if (type == null)
|
||||
return;
|
||||
if (TypeScope.IsKnownType(type))
|
||||
return;
|
||||
if (types[type] != null)
|
||||
return;
|
||||
types[type] = type;
|
||||
Type baseType = type.BaseType;
|
||||
if (baseType != null)
|
||||
AddImport(baseType, types);
|
||||
|
||||
Type declaringType = type.DeclaringType;
|
||||
if (declaringType != null)
|
||||
AddImport(declaringType, types);
|
||||
|
||||
foreach (Type intf in type.GetInterfaces())
|
||||
AddImport(intf, types);
|
||||
|
||||
ConstructorInfo[] ctors = type.GetConstructors();
|
||||
for (int i = 0; i < ctors.Length; i++) {
|
||||
ParameterInfo[] parms = ctors[i].GetParameters();
|
||||
for (int j = 0; j < parms.Length; j++) {
|
||||
AddImport(parms[j].ParameterType, types);
|
||||
}
|
||||
}
|
||||
|
||||
if (type.IsGenericType) {
|
||||
Type[] arguments = type.GetGenericArguments();
|
||||
for (int i = 0; i < arguments.Length; i++) {
|
||||
AddImport(arguments[i], types);
|
||||
}
|
||||
}
|
||||
|
||||
TempAssembly.FileIOPermission.Assert();
|
||||
Module module = type.Module;
|
||||
Assembly assembly = module.Assembly;
|
||||
if (DynamicAssemblies.IsTypeDynamic(type)) {
|
||||
DynamicAssemblies.Add(assembly);
|
||||
return;
|
||||
}
|
||||
|
||||
object[] typeForwardedFromAttribute = type.GetCustomAttributes(typeof(TypeForwardedFromAttribute), false);
|
||||
if (typeForwardedFromAttribute.Length > 0)
|
||||
{
|
||||
TypeForwardedFromAttribute originalAssemblyInfo = typeForwardedFromAttribute[0] as TypeForwardedFromAttribute;
|
||||
Assembly originalAssembly = Assembly.Load(originalAssemblyInfo.AssemblyFullName);
|
||||
imports[originalAssembly] = originalAssembly.Location;
|
||||
}
|
||||
|
||||
imports[assembly] = assembly.Location;
|
||||
}
|
||||
|
||||
// SxS: This method does not take any resource name and does not expose any resources to the caller.
|
||||
// It's OK to suppress the SxS warning.
|
||||
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
internal void AddImport(Assembly assembly) {
|
||||
TempAssembly.FileIOPermission.Assert();
|
||||
imports[assembly] = assembly.Location;
|
||||
}
|
||||
|
||||
internal TextWriter Source {
|
||||
get { return writer; }
|
||||
}
|
||||
|
||||
internal void Close() { }
|
||||
|
||||
[ResourceConsumption(ResourceScope.Machine)]
|
||||
[ResourceExposure(ResourceScope.Machine)]
|
||||
internal static string GetTempAssemblyPath(string baseDir, Assembly assembly, string defaultNamespace) {
|
||||
if (assembly.IsDynamic) {
|
||||
throw new InvalidOperationException(Res.GetString(Res.XmlPregenAssemblyDynamic));
|
||||
}
|
||||
|
||||
PermissionSet perms = new PermissionSet(PermissionState.None);
|
||||
perms.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
|
||||
perms.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
|
||||
perms.Assert();
|
||||
|
||||
try {
|
||||
if (baseDir != null && baseDir.Length > 0) {
|
||||
// check that the dirsctory exists
|
||||
if (!Directory.Exists(baseDir)) {
|
||||
throw new UnauthorizedAccessException(Res.GetString(Res.XmlPregenMissingDirectory, baseDir));
|
||||
}
|
||||
}
|
||||
else {
|
||||
baseDir = Path.GetTempPath();
|
||||
// check that the dirsctory exists
|
||||
if (!Directory.Exists(baseDir)) {
|
||||
throw new UnauthorizedAccessException(Res.GetString(Res.XmlPregenMissingTempDirectory));
|
||||
}
|
||||
}
|
||||
|
||||
#if MONO
|
||||
baseDir = Path.Combine (baseDir, GetTempAssemblyName(assembly.GetName(), defaultNamespace));
|
||||
#else
|
||||
if (baseDir.EndsWith("\\", StringComparison.Ordinal))
|
||||
baseDir += GetTempAssemblyName(assembly.GetName(), defaultNamespace);
|
||||
else
|
||||
baseDir += "\\" + GetTempAssemblyName(assembly.GetName(), defaultNamespace);
|
||||
#endif
|
||||
}
|
||||
finally {
|
||||
CodeAccessPermission.RevertAssert();
|
||||
}
|
||||
return baseDir + ".dll";
|
||||
}
|
||||
|
||||
internal static string GetTempAssemblyName(AssemblyName parent, string ns) {
|
||||
return parent.Name + ".XmlSerializers" + (ns == null || ns.Length == 0 ? "" : "." + ns.GetHashCode());
|
||||
}
|
||||
|
||||
// SxS: This method does not take any resource name and does not expose any resources to the caller.
|
||||
// It's OK to suppress the SxS warning.
|
||||
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
internal Assembly Compile(Assembly parent, string ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence) {
|
||||
CodeDomProvider codeProvider = new Microsoft.CSharp.CSharpCodeProvider();
|
||||
CompilerParameters parameters = xmlParameters.CodeDomParameters;
|
||||
parameters.ReferencedAssemblies.AddRange(Imports);
|
||||
|
||||
if (debugEnabled) {
|
||||
parameters.GenerateInMemory = false;
|
||||
parameters.IncludeDebugInformation = true;
|
||||
parameters.TempFiles.KeepFiles = true;
|
||||
}
|
||||
PermissionSet perms = new PermissionSet(PermissionState.None);
|
||||
if (xmlParameters.IsNeedTempDirAccess) {
|
||||
perms.AddPermission(TempAssembly.FileIOPermission);
|
||||
}
|
||||
perms.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
|
||||
perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
|
||||
perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence));
|
||||
perms.Assert();
|
||||
|
||||
if (parent != null && (parameters.OutputAssembly == null || parameters.OutputAssembly.Length ==0)) {
|
||||
string assemblyName = AssemblyNameFromOptions(parameters.CompilerOptions);
|
||||
if (assemblyName == null)
|
||||
assemblyName = GetTempAssemblyPath(parameters.TempFiles.TempDir, parent, ns);
|
||||
//
|
||||
parameters.OutputAssembly = assemblyName;
|
||||
}
|
||||
|
||||
if (parameters.CompilerOptions == null || parameters.CompilerOptions.Length == 0)
|
||||
parameters.CompilerOptions = "/nostdlib";
|
||||
else
|
||||
parameters.CompilerOptions += " /nostdlib";
|
||||
|
||||
parameters.CompilerOptions += " /D:_DYNAMIC_XMLSERIALIZER_COMPILATION";
|
||||
#pragma warning disable 618
|
||||
parameters.Evidence = evidence;
|
||||
#pragma warning restore 618
|
||||
CompilerResults results = null;
|
||||
Assembly assembly = null;
|
||||
try {
|
||||
results = codeProvider.CompileAssemblyFromSource(parameters, writer.ToString());
|
||||
// check the output for errors or a certain level-1 warning (1595)
|
||||
if (results.Errors.Count > 0) {
|
||||
StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
||||
stringWriter.WriteLine(Res.GetString(Res.XmlCompilerError, results.NativeCompilerReturnValue.ToString(CultureInfo.InvariantCulture)));
|
||||
bool foundOne = false;
|
||||
foreach (CompilerError e in results.Errors) {
|
||||
// clear filename. This makes ToString() print just error number and message.
|
||||
e.FileName = "";
|
||||
if (!e.IsWarning || e.ErrorNumber == "CS1595") {
|
||||
foundOne = true;
|
||||
stringWriter.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
if (foundOne) {
|
||||
throw new InvalidOperationException(stringWriter.ToString());
|
||||
}
|
||||
}
|
||||
assembly = results.CompiledAssembly;
|
||||
}
|
||||
catch (UnauthorizedAccessException) {
|
||||
// try to get the user token
|
||||
string user = GetCurrentUser();
|
||||
if (user == null || user.Length == 0) {
|
||||
throw new UnauthorizedAccessException(Res.GetString(Res.XmlSerializerAccessDenied));
|
||||
}
|
||||
else {
|
||||
throw new UnauthorizedAccessException(Res.GetString(Res.XmlIdentityAccessDenied, user));
|
||||
}
|
||||
}
|
||||
catch (FileLoadException fle) {
|
||||
throw new InvalidOperationException(Res.GetString(Res.XmlSerializerCompileFailed), fle);
|
||||
}
|
||||
finally {
|
||||
CodeAccessPermission.RevertAssert();
|
||||
}
|
||||
// somehow we got here without generating an assembly
|
||||
if (assembly == null) throw new InvalidOperationException(Res.GetString(Res.XmlInternalError));
|
||||
|
||||
return assembly;
|
||||
}
|
||||
|
||||
static string AssemblyNameFromOptions(string options) {
|
||||
if (options == null || options.Length == 0)
|
||||
return null;
|
||||
|
||||
string outName = null;
|
||||
string[] flags = options.ToLower(CultureInfo.InvariantCulture).Split(null);
|
||||
for (int i = 0; i < flags.Length; i++) {
|
||||
string val = flags[i].Trim();
|
||||
if (val.StartsWith("/out:", StringComparison.Ordinal)) {
|
||||
outName = val.Substring(5);
|
||||
}
|
||||
}
|
||||
return outName;
|
||||
}
|
||||
|
||||
internal static string GetCurrentUser()
|
||||
{
|
||||
#if !FEATURE_PAL
|
||||
try {
|
||||
WindowsIdentity id = WindowsIdentity.GetCurrent();
|
||||
if (id != null && id.Name != null)
|
||||
return id.Name;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endif // !FEATURE_PAL
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConfigurationStrings.cs" company="Microsoft Corporation">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Xml.Serialization.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
|
||||
internal static class ConfigurationStrings
|
||||
{
|
||||
static string GetSectionPath(string sectionName)
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, @"{0}/{1}", ConfigurationStrings.SectionGroupName, sectionName);
|
||||
}
|
||||
|
||||
static internal string SchemaImporterExtensionsSectionPath
|
||||
{
|
||||
get { return ConfigurationStrings.GetSectionPath(ConfigurationStrings.SchemaImporterExtensionsSectionName); }
|
||||
}
|
||||
|
||||
static internal string DateTimeSerializationSectionPath
|
||||
{
|
||||
get { return ConfigurationStrings.GetSectionPath(ConfigurationStrings.DateTimeSerializationSectionName); }
|
||||
}
|
||||
|
||||
static internal string XmlSerializerSectionPath
|
||||
{
|
||||
get { return ConfigurationStrings.GetSectionPath(ConfigurationStrings.XmlSerializerSectionName); }
|
||||
}
|
||||
|
||||
internal const string Name = "name";
|
||||
internal const string SchemaImporterExtensionsSectionName = "schemaImporterExtensions";
|
||||
internal const string DateTimeSerializationSectionName = "dateTimeSerialization";
|
||||
internal const string XmlSerializerSectionName = "xmlSerializer";
|
||||
internal const string SectionGroupName = "system.xml.serialization";
|
||||
internal const string SqlTypesSchemaImporterChar = "SqlTypesSchemaImporterChar";
|
||||
internal const string SqlTypesSchemaImporterNChar = "SqlTypesSchemaImporterNChar";
|
||||
internal const string SqlTypesSchemaImporterVarChar = "SqlTypesSchemaImporterVarChar";
|
||||
internal const string SqlTypesSchemaImporterNVarChar = "SqlTypesSchemaImporterNVarChar";
|
||||
internal const string SqlTypesSchemaImporterText = "SqlTypesSchemaImporterText";
|
||||
internal const string SqlTypesSchemaImporterNText = "SqlTypesSchemaImporterNText";
|
||||
internal const string SqlTypesSchemaImporterVarBinary = "SqlTypesSchemaImporterVarBinary";
|
||||
internal const string SqlTypesSchemaImporterBinary = "SqlTypesSchemaImporterBinary";
|
||||
internal const string SqlTypesSchemaImporterImage = "SqlTypesSchemaImporterImage";
|
||||
internal const string SqlTypesSchemaImporterDecimal = "SqlTypesSchemaImporterDecimal";
|
||||
internal const string SqlTypesSchemaImporterNumeric = "SqlTypesSchemaImporterNumeric";
|
||||
internal const string SqlTypesSchemaImporterBigInt = "SqlTypesSchemaImporterBigInt";
|
||||
internal const string SqlTypesSchemaImporterInt = "SqlTypesSchemaImporterInt";
|
||||
internal const string SqlTypesSchemaImporterSmallInt = "SqlTypesSchemaImporterSmallInt";
|
||||
internal const string SqlTypesSchemaImporterTinyInt = "SqlTypesSchemaImporterTinyInt";
|
||||
internal const string SqlTypesSchemaImporterBit = "SqlTypesSchemaImporterBit";
|
||||
internal const string SqlTypesSchemaImporterFloat = "SqlTypesSchemaImporterFloat";
|
||||
internal const string SqlTypesSchemaImporterReal = "SqlTypesSchemaImporterReal";
|
||||
internal const string SqlTypesSchemaImporterDateTime = "SqlTypesSchemaImporterDateTime";
|
||||
internal const string SqlTypesSchemaImporterSmallDateTime = "SqlTypesSchemaImporterSmallDateTime";
|
||||
internal const string SqlTypesSchemaImporterMoney = "SqlTypesSchemaImporterMoney";
|
||||
internal const string SqlTypesSchemaImporterSmallMoney = "SqlTypesSchemaImporterSmallMoney";
|
||||
internal const string SqlTypesSchemaImporterUniqueIdentifier = "SqlTypesSchemaImporterUniqueIdentifier";
|
||||
internal const string Type = "type";
|
||||
internal const string Mode = "mode";
|
||||
internal const string CheckDeserializeAdvances = "checkDeserializeAdvances";
|
||||
internal const string TempFilesLocation = "tempFilesLocation";
|
||||
internal const string UseLegacySerializerGeneration = "useLegacySerializerGeneration";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DateTimeSerializationSection.cs" company="Microsoft Corporation">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
#if CONFIGURATION_DEP
|
||||
namespace System.Xml.Serialization.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
public sealed class DateTimeSerializationSection : ConfigurationSection
|
||||
{
|
||||
public enum DateTimeSerializationMode
|
||||
{
|
||||
Default = 0,
|
||||
Roundtrip = 1,
|
||||
Local = 2,
|
||||
}
|
||||
|
||||
public DateTimeSerializationSection()
|
||||
{
|
||||
this.properties.Add(this.mode);
|
||||
}
|
||||
|
||||
protected override ConfigurationPropertyCollection Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ConfigurationStrings.Mode, DefaultValue=DateTimeSerializationMode.Roundtrip)]
|
||||
public DateTimeSerializationMode Mode
|
||||
{
|
||||
get { return (DateTimeSerializationMode) this[this.mode]; }
|
||||
set { this[this.mode] = value; }
|
||||
}
|
||||
|
||||
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
|
||||
|
||||
// Supply a type converter, even though it's a plain type converter, to get around ConfigurationProperty's internal
|
||||
// Enum conversion routine. The internal one is case-sensitive, we want this to be case-insensitive.
|
||||
readonly ConfigurationProperty mode =
|
||||
new ConfigurationProperty(ConfigurationStrings.Mode, typeof(DateTimeSerializationMode), DateTimeSerializationMode.Roundtrip,
|
||||
new EnumConverter(typeof(DateTimeSerializationMode)), null, ConfigurationPropertyOptions.None);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,129 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="SchemaImporterExtensionElement.cs" company="Microsoft Corporation">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
#if CONFIGURATION_DEP
|
||||
namespace System.Xml.Serialization.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Security.Permissions;
|
||||
|
||||
public sealed class SchemaImporterExtensionElement : ConfigurationElement
|
||||
{
|
||||
public SchemaImporterExtensionElement()
|
||||
{
|
||||
this.properties.Add(this.name);
|
||||
this.properties.Add(this.type);
|
||||
}
|
||||
|
||||
public SchemaImporterExtensionElement(string name, string type) : this()
|
||||
{
|
||||
this.Name = name;
|
||||
this[this.type] = new TypeAndName(type);
|
||||
}
|
||||
|
||||
public SchemaImporterExtensionElement(string name, Type type) : this()
|
||||
{
|
||||
this.Name = name;
|
||||
this.Type = type;
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ConfigurationStrings.Name, IsRequired=true, IsKey = true)]
|
||||
public string Name
|
||||
{
|
||||
get { return (string)this[this.name]; }
|
||||
set { this[this.name] = value; }
|
||||
}
|
||||
|
||||
protected override ConfigurationPropertyCollection Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ConfigurationStrings.Type, IsRequired=true, IsKey = false)]
|
||||
[TypeConverter(typeof(TypeTypeConverter))]
|
||||
public Type Type
|
||||
{
|
||||
get { return ((TypeAndName) this[this.type]).type; }
|
||||
set { this[this.type] = new TypeAndName(value); }
|
||||
}
|
||||
|
||||
internal string Key
|
||||
{
|
||||
get { return this.Name; }
|
||||
}
|
||||
|
||||
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
|
||||
|
||||
readonly ConfigurationProperty name =
|
||||
new ConfigurationProperty(ConfigurationStrings.Name, typeof(string), null,
|
||||
ConfigurationPropertyOptions.IsKey);
|
||||
|
||||
readonly ConfigurationProperty type =
|
||||
new ConfigurationProperty(ConfigurationStrings.Type, typeof(Type), null,
|
||||
new TypeTypeConverter(), null, ConfigurationPropertyOptions.IsRequired);
|
||||
|
||||
class TypeAndName
|
||||
{
|
||||
public TypeAndName(string name)
|
||||
{
|
||||
this.type = Type.GetType(name, true, true);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public TypeAndName(Type type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return type.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object comparand)
|
||||
{
|
||||
return type.Equals(((TypeAndName) comparand).type);
|
||||
}
|
||||
|
||||
public readonly Type type;
|
||||
public readonly string name;
|
||||
}
|
||||
|
||||
class TypeTypeConverter : TypeConverter {
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
|
||||
if (sourceType == typeof(string)) {
|
||||
return true;
|
||||
}
|
||||
return base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
|
||||
if (value is string) {
|
||||
return new TypeAndName((string) value);
|
||||
}
|
||||
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
|
||||
if (destinationType == typeof(string)) {
|
||||
TypeAndName castedValue = (TypeAndName) value;
|
||||
return castedValue.name == null ? castedValue.type.AssemblyQualifiedName : castedValue.name;
|
||||
}
|
||||
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="SchemaImporterExtensionElementCollection.cs" company="Microsoft Corporation">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
#if CONFIGURATION_DEP
|
||||
namespace System.Xml.Serialization.Configuration
|
||||
{
|
||||
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Security.Permissions;
|
||||
|
||||
[ConfigurationCollection(typeof(SchemaImporterExtensionElement))]
|
||||
public sealed class SchemaImporterExtensionElementCollection : ConfigurationElementCollection
|
||||
{
|
||||
public SchemaImporterExtensionElementCollection()
|
||||
{
|
||||
}
|
||||
|
||||
public SchemaImporterExtensionElement this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (SchemaImporterExtensionElement)BaseGet(index);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (BaseGet(index) != null)
|
||||
{
|
||||
BaseRemoveAt(index);
|
||||
}
|
||||
BaseAdd(index,value);
|
||||
}
|
||||
}
|
||||
|
||||
public new SchemaImporterExtensionElement this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (SchemaImporterExtensionElement)BaseGet(name);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (BaseGet(name) != null)
|
||||
{
|
||||
BaseRemove(name);
|
||||
}
|
||||
BaseAdd(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(SchemaImporterExtensionElement element)
|
||||
{
|
||||
BaseAdd(element);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
BaseClear();
|
||||
}
|
||||
|
||||
protected override ConfigurationElement CreateNewElement()
|
||||
{
|
||||
return new SchemaImporterExtensionElement();
|
||||
}
|
||||
|
||||
protected override Object GetElementKey(ConfigurationElement element)
|
||||
{
|
||||
return ((SchemaImporterExtensionElement)element).Key;
|
||||
}
|
||||
|
||||
public int IndexOf(SchemaImporterExtensionElement element)
|
||||
{
|
||||
return BaseIndexOf(element);
|
||||
}
|
||||
|
||||
public void Remove(SchemaImporterExtensionElement element)
|
||||
{
|
||||
BaseRemove(element.Key);
|
||||
}
|
||||
|
||||
public void Remove(string name)
|
||||
{
|
||||
BaseRemove(name);
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
BaseRemoveAt(index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,108 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="SchemaImporterExtensionsSection.cs" company="Microsoft Corporation">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
#if CONFIGURATION_DEP
|
||||
namespace System.Xml.Serialization.Configuration
|
||||
{
|
||||
using System.Configuration;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Xml.Serialization.Advanced;
|
||||
|
||||
public sealed class SchemaImporterExtensionsSection : ConfigurationSection
|
||||
{
|
||||
public SchemaImporterExtensionsSection()
|
||||
{
|
||||
this.properties.Add(this.schemaImporterExtensions);
|
||||
}
|
||||
|
||||
private static string GetSqlTypeSchemaImporter(string typeName) {
|
||||
return "System.Data.SqlTypes." + typeName + ", " + AssemblyRef.SystemData;
|
||||
}
|
||||
|
||||
protected override void InitializeDefault()
|
||||
{
|
||||
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterChar, GetSqlTypeSchemaImporter("TypeCharSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterNChar, GetSqlTypeSchemaImporter("TypeNCharSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterVarChar, GetSqlTypeSchemaImporter("TypeVarCharSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterNVarChar, GetSqlTypeSchemaImporter("TypeNVarCharSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterText, GetSqlTypeSchemaImporter("TypeTextSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterNText, GetSqlTypeSchemaImporter("TypeNTextSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterVarBinary, GetSqlTypeSchemaImporter("TypeVarBinarySchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterBinary, GetSqlTypeSchemaImporter("TypeBinarySchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterImage, GetSqlTypeSchemaImporter("TypeVarImageSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterDecimal, GetSqlTypeSchemaImporter("TypeDecimalSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterNumeric, GetSqlTypeSchemaImporter("TypeNumericSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterBigInt, GetSqlTypeSchemaImporter("TypeBigIntSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterInt, GetSqlTypeSchemaImporter("TypeIntSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterSmallInt, GetSqlTypeSchemaImporter("TypeSmallIntSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterTinyInt, GetSqlTypeSchemaImporter("TypeTinyIntSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterBit, GetSqlTypeSchemaImporter("TypeBitSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterFloat, GetSqlTypeSchemaImporter("TypeFloatSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterReal, GetSqlTypeSchemaImporter("TypeRealSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterDateTime, GetSqlTypeSchemaImporter("TypeDateTimeSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterSmallDateTime, GetSqlTypeSchemaImporter("TypeSmallDateTimeSchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterMoney, GetSqlTypeSchemaImporter("TypeMoneySchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterSmallMoney, GetSqlTypeSchemaImporter("TypeSmallMoneySchemaImporterExtension")));
|
||||
this.SchemaImporterExtensions.Add(
|
||||
new SchemaImporterExtensionElement(ConfigurationStrings.SqlTypesSchemaImporterUniqueIdentifier, GetSqlTypeSchemaImporter("TypeUniqueIdentifierSchemaImporterExtension")));
|
||||
}
|
||||
|
||||
protected override ConfigurationPropertyCollection Properties
|
||||
{
|
||||
get { return this.properties; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty("", IsDefaultCollection = true)]
|
||||
public SchemaImporterExtensionElementCollection SchemaImporterExtensions
|
||||
{
|
||||
get { return (SchemaImporterExtensionElementCollection)this[this.schemaImporterExtensions]; }
|
||||
}
|
||||
|
||||
internal SchemaImporterExtensionCollection SchemaImporterExtensionsInternal {
|
||||
get {
|
||||
SchemaImporterExtensionCollection extensions = new SchemaImporterExtensionCollection();
|
||||
foreach(SchemaImporterExtensionElement elem in this.SchemaImporterExtensions) {
|
||||
extensions.Add(elem.Name, elem.Type);
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
|
||||
|
||||
readonly ConfigurationProperty schemaImporterExtensions =
|
||||
new ConfigurationProperty(null, typeof(SchemaImporterExtensionElementCollection), null,
|
||||
ConfigurationPropertyOptions.IsDefaultCollection);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="SerializationSectionGroup.cs" company="Microsoft Corporation">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
#if CONFIGURATION_DEP
|
||||
namespace System.Xml.Serialization.Configuration
|
||||
{
|
||||
using System.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for SerializationSectionGroup.
|
||||
/// </summary>
|
||||
public sealed class SerializationSectionGroup : ConfigurationSectionGroup
|
||||
{
|
||||
public SerializationSectionGroup() {}
|
||||
|
||||
// public properties
|
||||
[ConfigurationProperty(ConfigurationStrings.SchemaImporterExtensionsSectionName)]
|
||||
public SchemaImporterExtensionsSection SchemaImporterExtensions
|
||||
{
|
||||
get { return (SchemaImporterExtensionsSection)Sections[ConfigurationStrings.SchemaImporterExtensionsSectionName]; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ConfigurationStrings.DateTimeSerializationSectionName)]
|
||||
public DateTimeSerializationSection DateTimeSerialization
|
||||
{
|
||||
get { return (DateTimeSerializationSection)Sections[ConfigurationStrings.DateTimeSerializationSectionName]; }
|
||||
}
|
||||
|
||||
public XmlSerializerSection XmlSerializer
|
||||
{
|
||||
get { return (XmlSerializerSection)Sections[ConfigurationStrings.XmlSerializerSectionName]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
#if CONFIGURATION_DEP
|
||||
namespace System.Xml.Serialization.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Configuration;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
|
||||
public sealed class XmlSerializerSection : ConfigurationSection
|
||||
{
|
||||
public XmlSerializerSection()
|
||||
{
|
||||
this.properties.Add(this.checkDeserializeAdvances);
|
||||
this.properties.Add(this.tempFilesLocation);
|
||||
this.properties.Add(this.useLegacySerializerGeneration);
|
||||
}
|
||||
|
||||
protected override ConfigurationPropertyCollection Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ConfigurationStrings.CheckDeserializeAdvances, DefaultValue = false)]
|
||||
public bool CheckDeserializeAdvances
|
||||
{
|
||||
get { return (bool)this[this.checkDeserializeAdvances]; }
|
||||
set { this[this.checkDeserializeAdvances] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ConfigurationStrings.TempFilesLocation, DefaultValue = null)]
|
||||
public string TempFilesLocation
|
||||
{
|
||||
get { return (string)this[this.tempFilesLocation]; }
|
||||
set { this[this.tempFilesLocation] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ConfigurationStrings.UseLegacySerializerGeneration, DefaultValue = false)]
|
||||
public bool UseLegacySerializerGeneration
|
||||
{
|
||||
get { return (bool)this[this.useLegacySerializerGeneration]; }
|
||||
set { this[this.useLegacySerializerGeneration] = value; }
|
||||
}
|
||||
|
||||
ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
|
||||
|
||||
// Supply a type converter, even though it's a plain type converter, to get around ConfigurationProperty's internal
|
||||
// Enum conversion routine. The internal one is case-sensitive, we want this to be case-insensitive.
|
||||
readonly ConfigurationProperty checkDeserializeAdvances =
|
||||
new ConfigurationProperty(ConfigurationStrings.CheckDeserializeAdvances, typeof(bool), false,
|
||||
ConfigurationPropertyOptions.None);
|
||||
|
||||
readonly ConfigurationProperty tempFilesLocation =
|
||||
new ConfigurationProperty(ConfigurationStrings.TempFilesLocation, typeof(string), null, null,
|
||||
new RootedPathValidator(),
|
||||
ConfigurationPropertyOptions.None);
|
||||
|
||||
readonly ConfigurationProperty useLegacySerializerGeneration =
|
||||
new ConfigurationProperty(ConfigurationStrings.UseLegacySerializerGeneration, typeof(bool), false,
|
||||
ConfigurationPropertyOptions.None);
|
||||
}
|
||||
|
||||
|
||||
public class RootedPathValidator : ConfigurationValidatorBase
|
||||
{
|
||||
public override bool CanValidate(Type type)
|
||||
{
|
||||
return (type == typeof(string));
|
||||
}
|
||||
|
||||
public override void Validate(object value)
|
||||
{
|
||||
string tempDirectory = value as string;
|
||||
if (string.IsNullOrEmpty(tempDirectory))
|
||||
return;
|
||||
tempDirectory = tempDirectory.Trim();
|
||||
if (string.IsNullOrEmpty(tempDirectory))
|
||||
return;
|
||||
if (!Path.IsPathRooted(tempDirectory))
|
||||
{
|
||||
// Make sure the path is not relative (VSWhidbey 260075)
|
||||
throw new ConfigurationErrorsException();
|
||||
}
|
||||
char firstChar = tempDirectory[0];
|
||||
if (firstChar == Path.DirectorySeparatorChar || firstChar == Path.AltDirectorySeparatorChar)
|
||||
{
|
||||
// Make sure the path is explicitly rooted
|
||||
throw new ConfigurationErrorsException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="IXmlSerializable.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">ElenaK</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization {
|
||||
|
||||
using System.Xml.Schema;
|
||||
|
||||
/// <include file='doc\IXmlSerializable.uex' path='docs/doc[@for="IXmlSerializable"]/*' />
|
||||
///<internalonly/>
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public interface IXmlSerializable {
|
||||
/// <include file='doc\IXmlSerializable.uex' path='docs/doc[@for="IXmlSerializable.GetSchema"]/*' />
|
||||
XmlSchema GetSchema();
|
||||
/// <include file='doc\IXmlSerializable.uex' path='docs/doc[@for="IXmlSerializable.ReadXml"]/*' />
|
||||
void ReadXml(XmlReader reader);
|
||||
/// <include file='doc\IXmlSerializable.uex' path='docs/doc[@for="IXmlSerializable.WriteXml"]/*' />
|
||||
void WriteXml(XmlWriter writer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="SafeWriter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">ElenaK</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization {
|
||||
using System.Xml;
|
||||
|
||||
/// <include file='doc\IXmlTextParser.uex' path='docs/doc[@for="IXmlTextParser"]/*' />
|
||||
///<internalonly/>
|
||||
/// <devdoc>
|
||||
/// <para>This class is <see langword='interface'/> .</para>
|
||||
/// </devdoc>
|
||||
public interface IXmlTextParser {
|
||||
/// <include file='doc\IXmlTextParser.uex' path='docs/doc[@for="IXmlTextParser.Normalized"]/*' />
|
||||
/// <internalonly/>
|
||||
bool Normalized { get; set; }
|
||||
|
||||
/// <include file='doc\IXmlTextParser.uex' path='docs/doc[@for="IXmlTextParser.WhitespaceHandling"]/*' />
|
||||
/// <internalonly/>
|
||||
WhitespaceHandling WhitespaceHandling { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ImportContext.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Serialization {
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
#if !MONO_HYBRID_SYSTEM_XML
|
||||
public class ImportContext {
|
||||
bool shareTypes;
|
||||
SchemaObjectCache cache; // cached schema top-level items
|
||||
Hashtable mappings; // XmlSchema -> SerializableMapping, XmlSchemaSimpleType -> EnumMapping, XmlSchemaComplexType -> StructMapping
|
||||
Hashtable elements; // XmlSchemaElement -> ElementAccessor
|
||||
CodeIdentifiers typeIdentifiers;
|
||||
|
||||
/// <include file='doc\ImportContext.uex' path='docs/doc[@for="ImportContext.ImportContext"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public ImportContext(CodeIdentifiers identifiers, bool shareTypes) {
|
||||
this.typeIdentifiers = identifiers;
|
||||
this.shareTypes = shareTypes;
|
||||
}
|
||||
internal ImportContext() : this(null, false) {}
|
||||
|
||||
internal SchemaObjectCache Cache {
|
||||
get {
|
||||
if (cache == null)
|
||||
cache = new SchemaObjectCache();
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
|
||||
internal Hashtable Elements {
|
||||
get {
|
||||
if (elements == null)
|
||||
elements = new Hashtable();
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
|
||||
internal Hashtable Mappings {
|
||||
get {
|
||||
if (mappings == null)
|
||||
mappings = new Hashtable();
|
||||
return mappings;
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\ImportContext.uex' path='docs/doc[@for="ImportContext.TypeIdentifiers"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public CodeIdentifiers TypeIdentifiers {
|
||||
get {
|
||||
if (typeIdentifiers == null)
|
||||
typeIdentifiers = new CodeIdentifiers();
|
||||
return typeIdentifiers;
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\ImportContext.uex' path='docs/doc[@for="ImportContext.ShareTypes"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public bool ShareTypes {
|
||||
get { return shareTypes; }
|
||||
}
|
||||
|
||||
/// <include file='doc\ImportContext.uex' path='docs/doc[@for="ImportContext.Warnings"]/*' />
|
||||
/// <devdoc>
|
||||
/// <para>[To be supplied.]</para>
|
||||
/// </devdoc>
|
||||
public StringCollection Warnings {
|
||||
get { return Cache.Warnings; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
internal class SchemaObjectCache {
|
||||
Hashtable graph;
|
||||
Hashtable hash;
|
||||
Hashtable objectCache;
|
||||
StringCollection warnings;
|
||||
//
|
||||
internal Hashtable looks = new Hashtable();
|
||||
Hashtable Graph {
|
||||
get {
|
||||
if (graph == null)
|
||||
graph = new Hashtable();
|
||||
return graph;
|
||||
}
|
||||
}
|
||||
|
||||
Hashtable Hash {
|
||||
get {
|
||||
if (hash == null)
|
||||
hash = new Hashtable();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
Hashtable ObjectCache {
|
||||
get {
|
||||
if (objectCache == null)
|
||||
objectCache = new Hashtable();
|
||||
return objectCache;
|
||||
}
|
||||
}
|
||||
|
||||
internal StringCollection Warnings {
|
||||
get {
|
||||
if (warnings == null)
|
||||
warnings = new StringCollection();
|
||||
return warnings;
|
||||
}
|
||||
}
|
||||
|
||||
internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas) {
|
||||
if (item == null)
|
||||
return null;
|
||||
if (qname == null || qname.IsEmpty)
|
||||
return null;
|
||||
|
||||
string key = item.GetType().Name + ":" + qname.ToString();
|
||||
ArrayList list = (ArrayList)ObjectCache[key];
|
||||
if (list == null) {
|
||||
list = new ArrayList();
|
||||
ObjectCache[key] = list;
|
||||
}
|
||||
|
||||
for (int i = 0; i < list.Count; i++) {
|
||||
XmlSchemaObject cachedItem = (XmlSchemaObject)list[i];
|
||||
if (cachedItem == item)
|
||||
return cachedItem;
|
||||
|
||||
if (Match(cachedItem, item, true)) {
|
||||
return cachedItem;
|
||||
}
|
||||
else {
|
||||
Warnings.Add(Res.GetString(Res.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace));
|
||||
Warnings.Add("DEBUG:Cached item key:\r\n" + (string)looks[cachedItem] + "\r\nnew item key:\r\n" + (string)looks[item]);
|
||||
}
|
||||
}
|
||||
// no match found we need to insert the new type in the cache
|
||||
list.Add(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
internal bool Match(XmlSchemaObject o1, XmlSchemaObject o2, bool shareTypes) {
|
||||
if (o1 == o2)
|
||||
return true;
|
||||
if (o1.GetType() != o2.GetType())
|
||||
return false;
|
||||
if (Hash[o1] == null)
|
||||
Hash[o1] = GetHash(o1);
|
||||
int hash1 = (int)Hash[o1];
|
||||
int hash2 = GetHash(o2);
|
||||
if (hash1 != hash2)
|
||||
return false;
|
||||
|
||||
if (shareTypes)
|
||||
return CompositeHash(o1, hash1) == CompositeHash(o2, hash2);
|
||||
return true;
|
||||
}
|
||||
|
||||
private ArrayList GetDependencies(XmlSchemaObject o, ArrayList deps, Hashtable refs) {
|
||||
if (refs[o] == null) {
|
||||
refs[o] = o;
|
||||
deps.Add(o);
|
||||
ArrayList list = Graph[o] as ArrayList;
|
||||
if (list != null) {
|
||||
for (int i = 0; i < list.Count; i++) {
|
||||
GetDependencies((XmlSchemaObject)list[i], deps, refs);
|
||||
}
|
||||
}
|
||||
}
|
||||
return deps;
|
||||
}
|
||||
|
||||
private int CompositeHash(XmlSchemaObject o, int hash) {
|
||||
ArrayList list = GetDependencies(o, new ArrayList(), new Hashtable());
|
||||
double tmp = 0;
|
||||
for (int i = 0; i < list.Count; i++) {
|
||||
object cachedHash = Hash[list[i]];
|
||||
if (cachedHash is int) {
|
||||
tmp += (int)cachedHash/list.Count;
|
||||
}
|
||||
}
|
||||
return (int)tmp;
|
||||
}
|
||||
|
||||
internal void GenerateSchemaGraph(XmlSchemas schemas) {
|
||||
SchemaGraph graph = new SchemaGraph(Graph, schemas);
|
||||
ArrayList items = graph.GetItems();
|
||||
|
||||
for (int i = 0; i < items.Count; i++) {
|
||||
GetHash((XmlSchemaObject)items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private int GetHash(XmlSchemaObject o) {
|
||||
object hash = Hash[o];
|
||||
if (hash != null) {
|
||||
if (hash is XmlSchemaObject) {
|
||||
}
|
||||
else {
|
||||
return (int)hash;
|
||||
}
|
||||
}
|
||||
// new object, generate the hash
|
||||
string hashString = ToString(o, new SchemaObjectWriter());
|
||||
looks[o] = hashString;
|
||||
int code = hashString.GetHashCode();
|
||||
Hash[o] = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
string ToString(XmlSchemaObject o, SchemaObjectWriter writer) {
|
||||
return writer.WriteXmlSchemaObject(o);
|
||||
}
|
||||
}
|
||||
|
||||
internal class SchemaGraph {
|
||||
ArrayList empty = new ArrayList();
|
||||
XmlSchemas schemas;
|
||||
Hashtable scope;
|
||||
int items;
|
||||
|
||||
internal SchemaGraph(Hashtable scope, XmlSchemas schemas) {
|
||||
this.scope = scope;
|
||||
schemas.Compile(null, false);
|
||||
this.schemas = schemas;
|
||||
items = 0;
|
||||
foreach(XmlSchema s in schemas) {
|
||||
items += s.Items.Count;
|
||||
foreach (XmlSchemaObject item in s.Items) {
|
||||
Depends(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal ArrayList GetItems() {
|
||||
return new ArrayList(scope.Keys);
|
||||
}
|
||||
|
||||
internal void AddRef(ArrayList list, XmlSchemaObject o) {
|
||||
if (o == null)
|
||||
return;
|
||||
if (schemas.IsReference(o))
|
||||
return;
|
||||
if (o.Parent is XmlSchema) {
|
||||
string ns = ((XmlSchema)o.Parent).TargetNamespace;
|
||||
if (ns == XmlSchema.Namespace)
|
||||
return;
|
||||
if (list.Contains(o))
|
||||
return;
|
||||
list.Add(o);
|
||||
}
|
||||
}
|
||||
|
||||
internal ArrayList Depends(XmlSchemaObject item) {
|
||||
|
||||
if (item.Parent is XmlSchema) {
|
||||
if (scope[item] != null)
|
||||
return (ArrayList)scope[item];
|
||||
|
||||
ArrayList refs = new ArrayList();
|
||||
Depends(item, refs);
|
||||
scope.Add(item, refs);
|
||||
return refs;
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
internal void Depends(XmlSchemaObject item, ArrayList refs) {
|
||||
if (item == null || scope[item] != null)
|
||||
return;
|
||||
|
||||
Type t = item.GetType();
|
||||
if (typeof(XmlSchemaType).IsAssignableFrom(t)) {
|
||||
XmlQualifiedName baseName = XmlQualifiedName.Empty;
|
||||
XmlSchemaType baseType = null;
|
||||
XmlSchemaParticle particle = null;
|
||||
XmlSchemaObjectCollection attributes = null;
|
||||
|
||||
if (item is XmlSchemaComplexType) {
|
||||
XmlSchemaComplexType ct = (XmlSchemaComplexType)item;
|
||||
if (ct.ContentModel != null) {
|
||||
XmlSchemaContent content = ct.ContentModel.Content;
|
||||
if (content is XmlSchemaComplexContentRestriction) {
|
||||
baseName = ((XmlSchemaComplexContentRestriction)content).BaseTypeName;
|
||||
attributes = ((XmlSchemaComplexContentRestriction)content).Attributes;
|
||||
}
|
||||
else if (content is XmlSchemaSimpleContentRestriction) {
|
||||
XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content;
|
||||
if (restriction.BaseType != null)
|
||||
baseType = restriction.BaseType;
|
||||
else
|
||||
baseName = restriction.BaseTypeName;
|
||||
attributes = restriction.Attributes;
|
||||
}
|
||||
else if (content is XmlSchemaComplexContentExtension) {
|
||||
XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
|
||||
attributes = extension.Attributes;
|
||||
particle = extension.Particle;
|
||||
baseName = extension.BaseTypeName;
|
||||
}
|
||||
else if (content is XmlSchemaSimpleContentExtension) {
|
||||
XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content;
|
||||
attributes = extension.Attributes;
|
||||
baseName = extension.BaseTypeName;
|
||||
}
|
||||
}
|
||||
else {
|
||||
attributes = ct.Attributes;
|
||||
particle = ct.Particle;
|
||||
}
|
||||
if (particle is XmlSchemaGroupRef) {
|
||||
XmlSchemaGroupRef refGroup = (XmlSchemaGroupRef)particle;
|
||||
particle = ((XmlSchemaGroup)schemas.Find(refGroup.RefName, typeof(XmlSchemaGroup), false)).Particle;
|
||||
}
|
||||
else if (particle is XmlSchemaGroupBase) {
|
||||
particle = (XmlSchemaGroupBase)particle;
|
||||
}
|
||||
}
|
||||
else if (item is XmlSchemaSimpleType) {
|
||||
XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)item;
|
||||
XmlSchemaSimpleTypeContent content = simpleType.Content;
|
||||
if (content is XmlSchemaSimpleTypeRestriction) {
|
||||
baseType = ((XmlSchemaSimpleTypeRestriction)content).BaseType;
|
||||
baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName;
|
||||
}
|
||||
else if (content is XmlSchemaSimpleTypeList) {
|
||||
XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)content;
|
||||
if (list.ItemTypeName != null && !list.ItemTypeName.IsEmpty)
|
||||
baseName = list.ItemTypeName;
|
||||
if (list.ItemType != null) {
|
||||
baseType = list.ItemType;
|
||||
}
|
||||
}
|
||||
else if (content is XmlSchemaSimpleTypeRestriction) {
|
||||
baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName;
|
||||
}
|
||||
else if (t == typeof(XmlSchemaSimpleTypeUnion)) {
|
||||
XmlQualifiedName[] memberTypes = ((XmlSchemaSimpleTypeUnion)item).MemberTypes;
|
||||
|
||||
if (memberTypes != null) {
|
||||
for (int i = 0; i < memberTypes.Length; i++) {
|
||||
XmlSchemaType type = (XmlSchemaType)schemas.Find(memberTypes[i], typeof(XmlSchemaType), false);
|
||||
AddRef(refs, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (baseType == null && !baseName.IsEmpty && baseName.Namespace != XmlSchema.Namespace)
|
||||
baseType = (XmlSchemaType)schemas.Find(baseName, typeof(XmlSchemaType), false);
|
||||
|
||||
if (baseType != null) {
|
||||
AddRef(refs, baseType);
|
||||
}
|
||||
if (particle != null) {
|
||||
Depends(particle, refs);
|
||||
}
|
||||
if (attributes != null) {
|
||||
for (int i = 0; i < attributes.Count; i++) {
|
||||
Depends(attributes[i], refs);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (t == typeof(XmlSchemaElement)) {
|
||||
XmlSchemaElement el = (XmlSchemaElement)item;
|
||||
if (!el.SubstitutionGroup.IsEmpty) {
|
||||
if (el.SubstitutionGroup.Namespace != XmlSchema.Namespace) {
|
||||
XmlSchemaElement head = (XmlSchemaElement)schemas.Find(el.SubstitutionGroup, typeof(XmlSchemaElement), false);
|
||||
AddRef(refs, head);
|
||||
}
|
||||
}
|
||||
if (!el.RefName.IsEmpty) {
|
||||
el = (XmlSchemaElement)schemas.Find(el.RefName, typeof(XmlSchemaElement), false);
|
||||
AddRef(refs, el);
|
||||
}
|
||||
else if (!el.SchemaTypeName.IsEmpty) {
|
||||
XmlSchemaType type = (XmlSchemaType)schemas.Find(el.SchemaTypeName, typeof(XmlSchemaType), false);
|
||||
AddRef(refs, type);
|
||||
}
|
||||
else {
|
||||
Depends(el.SchemaType, refs);
|
||||
}
|
||||
}
|
||||
else if (t == typeof(XmlSchemaGroup)) {
|
||||
Depends(((XmlSchemaGroup)item).Particle);
|
||||
}
|
||||
else if (t == typeof(XmlSchemaGroupRef)) {
|
||||
XmlSchemaGroup group = (XmlSchemaGroup)schemas.Find(((XmlSchemaGroupRef)item).RefName, typeof(XmlSchemaGroup), false);
|
||||
AddRef(refs, group);
|
||||
}
|
||||
else if (typeof(XmlSchemaGroupBase).IsAssignableFrom(t)) {
|
||||
foreach (XmlSchemaObject o in ((XmlSchemaGroupBase)item).Items) {
|
||||
Depends(o, refs);
|
||||
}
|
||||
}
|
||||
else if (t == typeof(XmlSchemaAttributeGroupRef)) {
|
||||
XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup)schemas.Find(((XmlSchemaAttributeGroupRef)item).RefName, typeof(XmlSchemaAttributeGroup), false);
|
||||
AddRef(refs, group);
|
||||
}
|
||||
else if (t == typeof(XmlSchemaAttributeGroup)) {
|
||||
foreach (XmlSchemaObject o in ((XmlSchemaAttributeGroup)item).Attributes) {
|
||||
Depends(o, refs);
|
||||
}
|
||||
}
|
||||
else if (t == typeof(XmlSchemaAttribute)) {
|
||||
XmlSchemaAttribute at = (XmlSchemaAttribute)item;
|
||||
if (!at.RefName.IsEmpty) {
|
||||
at = (XmlSchemaAttribute)schemas.Find(at.RefName, typeof(XmlSchemaAttribute), false);
|
||||
AddRef(refs, at);
|
||||
}
|
||||
else if (!at.SchemaTypeName.IsEmpty) {
|
||||
XmlSchemaType type = (XmlSchemaType)schemas.Find(at.SchemaTypeName, typeof(XmlSchemaType), false);
|
||||
AddRef(refs, type);
|
||||
}
|
||||
else {
|
||||
Depends(at.SchemaType, refs);
|
||||
}
|
||||
}
|
||||
if (typeof(XmlSchemaAnnotated).IsAssignableFrom(t)) {
|
||||
XmlAttribute[] attrs = (XmlAttribute[])((XmlSchemaAnnotated)item).UnhandledAttributes;
|
||||
|
||||
if (attrs != null) {
|
||||
for (int i = 0; i < attrs.Length; i++) {
|
||||
XmlAttribute attribute = attrs[i];
|
||||
if (attribute.LocalName == Wsdl.ArrayType && attribute.NamespaceURI == Wsdl.Namespace) {
|
||||
string dims;
|
||||
XmlQualifiedName qname = TypeScope.ParseWsdlArrayType(attribute.Value, out dims, item);
|
||||
XmlSchemaType type = (XmlSchemaType)schemas.Find(qname, typeof(XmlSchemaType), false);
|
||||
AddRef(refs, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user