SqlTypesSchemaImporter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Data / System / Data / SQLTypes / SqlTypesSchemaImporter.cs / 1 / SqlTypesSchemaImporter.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// dondu 
// [....]
// [....] 
//----------------------------------------------------------------------------- 

 
namespace System.Data.SqlTypes {

    using System;
    using System.CodeDom; 
    using System.CodeDom.Compiler;
    using System.Collections; 
    using System.Collections.Specialized; 
    using System.Xml;
    using System.Xml.Schema; 
    using System.Xml.Serialization;
    using System.Xml.Serialization.Advanced;

    public class SqlTypesSchemaImporterExtensionHelper : SchemaImporterExtension { 
        private string m_name;
        private string m_targetNamespace; 
        private string[] m_references; 
        private CodeNamespaceImport[] m_namespaceImports;
        private string m_destinationType; 
        private bool m_direct;
       public SqlTypesSchemaImporterExtensionHelper(string name,
                                                     string targetNamespace,
                                                     string[] references, 
                                                     CodeNamespaceImport[] namespaceImports,
                                                     string destinationType, 
                                                     bool direct) { 
            Init(name, targetNamespace, references, namespaceImports, destinationType, direct);
        } 
        public SqlTypesSchemaImporterExtensionHelper(string name, string destinationType) {
            Init(name, SqlTypesNamespace, null, null, destinationType, true);
        }
        public SqlTypesSchemaImporterExtensionHelper(string name, string destinationType, bool direct) { 
            Init(name, SqlTypesNamespace, null, null, destinationType, direct);
        } 
        private void Init(string name, 
                          string targetNamespace,
                          string[] references, 
                          CodeNamespaceImport[] namespaceImports,
                          string destinationType,
                          bool direct) {
            m_name = name; 
            m_targetNamespace = targetNamespace;
            if (references == null) { 
                m_references = new string[1]; 
                m_references[0] = "System.Data.dll";
            } else { 
                m_references = references;
            }
            if (namespaceImports == null) {
                m_namespaceImports = new CodeNamespaceImport[2]; 
                m_namespaceImports[0] = new CodeNamespaceImport("System.Data");
                m_namespaceImports[1] = new CodeNamespaceImport("System.Data.SqlTypes"); 
            } else { 
                m_namespaceImports = namespaceImports;
            } 
            m_destinationType = destinationType;
            m_direct = direct;
        }
        public override string ImportSchemaType(string name, 
                                                string xmlNamespace,
                                                XmlSchemaObject context, 
                                                XmlSchemas schemas, 
                                                XmlSchemaImporter importer,
                                                CodeCompileUnit compileUnit, 
                                                CodeNamespace mainNamespace,
                                                CodeGenerationOptions options,
                                                CodeDomProvider codeProvider) {
            if (m_direct) { 
                if (context is XmlSchemaElement) {
                    if ((0 == string.CompareOrdinal(m_name, name)) && (0 == string.CompareOrdinal(m_targetNamespace, xmlNamespace))) { 
                        compileUnit.ReferencedAssemblies.AddRange(m_references); 
                        mainNamespace.Imports.AddRange(m_namespaceImports);
                        return m_destinationType; 
                    }
                }
            }
            return null; 
        }
        public override string ImportSchemaType(XmlSchemaType type, 
                                                XmlSchemaObject context, 
                                                XmlSchemas schemas,
                                                XmlSchemaImporter importer, 
                                                CodeCompileUnit compileUnit,
                                                CodeNamespace mainNamespace,
                                                CodeGenerationOptions options,
                                                CodeDomProvider codeProvider) { 
            if (!m_direct) {
                if ((type is XmlSchemaSimpleType) && (context is XmlSchemaElement)) { 
                    XmlSchemaType basetype = ((XmlSchemaSimpleType) type).BaseXmlSchemaType; 
                    XmlQualifiedName qname = basetype.QualifiedName;
                    if ((0 == string.CompareOrdinal(m_name, qname.Name)) && (0 == string.CompareOrdinal(m_targetNamespace, qname.Namespace))) { 
                        compileUnit.ReferencedAssemblies.AddRange(m_references);
                        mainNamespace.Imports.AddRange(m_namespaceImports);
                        return m_destinationType;
                    } 
                }
            } 
            return null; 
        }
 
        protected static readonly string SqlTypesNamespace = "http://schemas.microsoft.com/sqlserver/2004/sqltypes";
    };

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeCharSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeCharSchemaImporterExtension() : base("char", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeNCharSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeNCharSchemaImporterExtension() : base("nchar", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeVarCharSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeVarCharSchemaImporterExtension() : base("varchar", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeNVarCharSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeNVarCharSchemaImporterExtension() : base("nvarchar", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeTextSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeTextSchemaImporterExtension() : base("text", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeNTextSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeNTextSchemaImporterExtension() : base("ntext", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeVarBinarySchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeVarBinarySchemaImporterExtension() : base("varbinary", "System.Data.SqlTypes.SqlBinary", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeBinarySchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeBinarySchemaImporterExtension() : base("binary", "System.Data.SqlTypes.SqlBinary", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeVarImageSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeVarImageSchemaImporterExtension() : base("image", "System.Data.SqlTypes.SqlBinary", false) { }
    }

/* 
  
     
       
    
   
*/

/*
   
  
     
   
*/
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeDecimalSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeDecimalSchemaImporterExtension() : base("decimal", "System.Data.SqlTypes.SqlDecimal", false) { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeNumericSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeNumericSchemaImporterExtension() : base("numeric", "System.Data.SqlTypes.SqlDecimal", false) { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeBigIntSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeBigIntSchemaImporterExtension() : base("bigint", "System.Data.SqlTypes.SqlInt64") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeIntSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeIntSchemaImporterExtension() : base("int", "System.Data.SqlTypes.SqlInt32") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeSmallIntSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeSmallIntSchemaImporterExtension() : base("smallint", "System.Data.SqlTypes.SqlInt16") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeTinyIntSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeTinyIntSchemaImporterExtension() : base("tinyint", "System.Data.SqlTypes.SqlByte") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeBitSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeBitSchemaImporterExtension() : base("bit", "System.Data.SqlTypes.SqlBoolean") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeFloatSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeFloatSchemaImporterExtension() : base("float", "System.Data.SqlTypes.SqlDouble") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeRealSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeRealSchemaImporterExtension() : base("real", "System.Data.SqlTypes.SqlSingle") { } 
    }
 
/*
  
    
       
      
       
     
  
*/ 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeDateTimeSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeDateTimeSchemaImporterExtension() : base("datetime", "System.Data.SqlTypes.SqlDateTime") { }
    } 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeSmallDateTimeSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeSmallDateTimeSchemaImporterExtension() : base("smalldatetime", "System.Data.SqlTypes.SqlDateTime") { }
    } 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeMoneySchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeMoneySchemaImporterExtension() : base("money", "System.Data.SqlTypes.SqlMoney") { }
    } 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeSmallMoneySchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeSmallMoneySchemaImporterExtension() : base("smallmoney", "System.Data.SqlTypes.SqlMoney") { }
    } 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeUniqueIdentifierSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeUniqueIdentifierSchemaImporterExtension() : base("uniqueidentifier", "System.Data.SqlTypes.SqlGuid") { }
    } 

/*
  
*/ 

/* 
   
    
       
    
  
*/
 
/*
   
     
  
*/ 

}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// dondu 
// [....]
// [....] 
//----------------------------------------------------------------------------- 

 
namespace System.Data.SqlTypes {

    using System;
    using System.CodeDom; 
    using System.CodeDom.Compiler;
    using System.Collections; 
    using System.Collections.Specialized; 
    using System.Xml;
    using System.Xml.Schema; 
    using System.Xml.Serialization;
    using System.Xml.Serialization.Advanced;

    public class SqlTypesSchemaImporterExtensionHelper : SchemaImporterExtension { 
        private string m_name;
        private string m_targetNamespace; 
        private string[] m_references; 
        private CodeNamespaceImport[] m_namespaceImports;
        private string m_destinationType; 
        private bool m_direct;
       public SqlTypesSchemaImporterExtensionHelper(string name,
                                                     string targetNamespace,
                                                     string[] references, 
                                                     CodeNamespaceImport[] namespaceImports,
                                                     string destinationType, 
                                                     bool direct) { 
            Init(name, targetNamespace, references, namespaceImports, destinationType, direct);
        } 
        public SqlTypesSchemaImporterExtensionHelper(string name, string destinationType) {
            Init(name, SqlTypesNamespace, null, null, destinationType, true);
        }
        public SqlTypesSchemaImporterExtensionHelper(string name, string destinationType, bool direct) { 
            Init(name, SqlTypesNamespace, null, null, destinationType, direct);
        } 
        private void Init(string name, 
                          string targetNamespace,
                          string[] references, 
                          CodeNamespaceImport[] namespaceImports,
                          string destinationType,
                          bool direct) {
            m_name = name; 
            m_targetNamespace = targetNamespace;
            if (references == null) { 
                m_references = new string[1]; 
                m_references[0] = "System.Data.dll";
            } else { 
                m_references = references;
            }
            if (namespaceImports == null) {
                m_namespaceImports = new CodeNamespaceImport[2]; 
                m_namespaceImports[0] = new CodeNamespaceImport("System.Data");
                m_namespaceImports[1] = new CodeNamespaceImport("System.Data.SqlTypes"); 
            } else { 
                m_namespaceImports = namespaceImports;
            } 
            m_destinationType = destinationType;
            m_direct = direct;
        }
        public override string ImportSchemaType(string name, 
                                                string xmlNamespace,
                                                XmlSchemaObject context, 
                                                XmlSchemas schemas, 
                                                XmlSchemaImporter importer,
                                                CodeCompileUnit compileUnit, 
                                                CodeNamespace mainNamespace,
                                                CodeGenerationOptions options,
                                                CodeDomProvider codeProvider) {
            if (m_direct) { 
                if (context is XmlSchemaElement) {
                    if ((0 == string.CompareOrdinal(m_name, name)) && (0 == string.CompareOrdinal(m_targetNamespace, xmlNamespace))) { 
                        compileUnit.ReferencedAssemblies.AddRange(m_references); 
                        mainNamespace.Imports.AddRange(m_namespaceImports);
                        return m_destinationType; 
                    }
                }
            }
            return null; 
        }
        public override string ImportSchemaType(XmlSchemaType type, 
                                                XmlSchemaObject context, 
                                                XmlSchemas schemas,
                                                XmlSchemaImporter importer, 
                                                CodeCompileUnit compileUnit,
                                                CodeNamespace mainNamespace,
                                                CodeGenerationOptions options,
                                                CodeDomProvider codeProvider) { 
            if (!m_direct) {
                if ((type is XmlSchemaSimpleType) && (context is XmlSchemaElement)) { 
                    XmlSchemaType basetype = ((XmlSchemaSimpleType) type).BaseXmlSchemaType; 
                    XmlQualifiedName qname = basetype.QualifiedName;
                    if ((0 == string.CompareOrdinal(m_name, qname.Name)) && (0 == string.CompareOrdinal(m_targetNamespace, qname.Namespace))) { 
                        compileUnit.ReferencedAssemblies.AddRange(m_references);
                        mainNamespace.Imports.AddRange(m_namespaceImports);
                        return m_destinationType;
                    } 
                }
            } 
            return null; 
        }
 
        protected static readonly string SqlTypesNamespace = "http://schemas.microsoft.com/sqlserver/2004/sqltypes";
    };

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeCharSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeCharSchemaImporterExtension() : base("char", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeNCharSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeNCharSchemaImporterExtension() : base("nchar", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeVarCharSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeVarCharSchemaImporterExtension() : base("varchar", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeNVarCharSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeNVarCharSchemaImporterExtension() : base("nvarchar", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeTextSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeTextSchemaImporterExtension() : base("text", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeNTextSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeNTextSchemaImporterExtension() : base("ntext", "System.Data.SqlTypes.SqlString", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeVarBinarySchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeVarBinarySchemaImporterExtension() : base("varbinary", "System.Data.SqlTypes.SqlBinary", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeBinarySchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeBinarySchemaImporterExtension() : base("binary", "System.Data.SqlTypes.SqlBinary", false) { }
    }

#if WINFSInternalOnly 
    internal
#else 
    public 
#endif
    sealed class TypeVarImageSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeVarImageSchemaImporterExtension() : base("image", "System.Data.SqlTypes.SqlBinary", false) { }
    }

/* 
  
     
       
    
   
*/

/*
   
  
     
   
*/
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeDecimalSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeDecimalSchemaImporterExtension() : base("decimal", "System.Data.SqlTypes.SqlDecimal", false) { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeNumericSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeNumericSchemaImporterExtension() : base("numeric", "System.Data.SqlTypes.SqlDecimal", false) { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeBigIntSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeBigIntSchemaImporterExtension() : base("bigint", "System.Data.SqlTypes.SqlInt64") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeIntSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeIntSchemaImporterExtension() : base("int", "System.Data.SqlTypes.SqlInt32") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeSmallIntSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeSmallIntSchemaImporterExtension() : base("smallint", "System.Data.SqlTypes.SqlInt16") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeTinyIntSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeTinyIntSchemaImporterExtension() : base("tinyint", "System.Data.SqlTypes.SqlByte") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeBitSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeBitSchemaImporterExtension() : base("bit", "System.Data.SqlTypes.SqlBoolean") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeFloatSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeFloatSchemaImporterExtension() : base("float", "System.Data.SqlTypes.SqlDouble") { } 
    }
 
#if WINFSInternalOnly
    internal
#else
    public 
#endif
    sealed class TypeRealSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeRealSchemaImporterExtension() : base("real", "System.Data.SqlTypes.SqlSingle") { } 
    }
 
/*
  
    
       
      
       
     
  
*/ 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeDateTimeSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeDateTimeSchemaImporterExtension() : base("datetime", "System.Data.SqlTypes.SqlDateTime") { }
    } 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeSmallDateTimeSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeSmallDateTimeSchemaImporterExtension() : base("smalldatetime", "System.Data.SqlTypes.SqlDateTime") { }
    } 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeMoneySchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeMoneySchemaImporterExtension() : base("money", "System.Data.SqlTypes.SqlMoney") { }
    } 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeSmallMoneySchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeSmallMoneySchemaImporterExtension() : base("smallmoney", "System.Data.SqlTypes.SqlMoney") { }
    } 

#if WINFSInternalOnly
    internal
#else 
    public
#endif 
    sealed class TypeUniqueIdentifierSchemaImporterExtension : SqlTypesSchemaImporterExtensionHelper { 
        public TypeUniqueIdentifierSchemaImporterExtension() : base("uniqueidentifier", "System.Data.SqlTypes.SqlGuid") { }
    } 

/*
  
*/ 

/* 
   
    
       
    
  
*/
 
/*
   
     
  
*/ 

}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK