Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / Compilation / XsdBuildProvider.cs / 3 / XsdBuildProvider.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Compilation { using System; using System.IO; using System.Data; using System.Data.Design; using System.Globalization; using System.Xml; using System.Xml.Schema; using System.Reflection; using System.CodeDom; using System.CodeDom.Compiler; using System.Web.Hosting; using System.Web.Configuration; using System.Collections; using Util=System.Web.UI.Util; #if !FEATURE_PAL // FEATURE_PAL does not support System.Data.Design using TypedDataSetGenerator=System.Data.Design.TypedDataSetGenerator; #endif // !FEATURE_PAL [BuildProviderAppliesTo(BuildProviderAppliesTo.Code)] internal class XsdBuildProvider: BuildProvider { public override void GenerateCode(AssemblyBuilder assemblyBuilder) { #if !FEATURE_PAL // FEATURE_PAL does not support System.Data.Design // Get the namespace that we will use string ns = Util.GetNamespaceFromVirtualPath(VirtualPathObject); // We need to use XmlDocument to parse the xsd file is order to open it with the // correct encoding ( XmlDocument doc = new XmlDocument(); using (Stream stream = OpenStream()) { doc.Load(stream); } String content = doc.OuterXml; // Generate a CodeCompileUnit from the dataset CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); CodeNamespace codeNamespace = new CodeNamespace(ns); codeCompileUnit.Namespaces.Add(codeNamespace); // Devdiv 18365 // Call a different Generate method if compiler version is v3.5 bool isVer35 = CompilationUtil.IsCompilerVersion35(assemblyBuilder.CodeDomProvider.GetType()); if (isVer35) { TypedDataSetGenerator.GenerateOption generateOptions = TypedDataSetGenerator.GenerateOption.None; generateOptions |= TypedDataSetGenerator.GenerateOption.HierarchicalUpdate; generateOptions |= TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets; Hashtable customDBProviders = null; TypedDataSetGenerator.Generate(content, codeCompileUnit, codeNamespace, assemblyBuilder.CodeDomProvider, customDBProviders, generateOptions); } else { TypedDataSetGenerator.Generate(content, codeCompileUnit, codeNamespace, assemblyBuilder.CodeDomProvider); } // Add all the assembly references needed by the generated code if (TypedDataSetGenerator.ReferencedAssemblies != null) { foreach (Assembly a in TypedDataSetGenerator.ReferencedAssemblies) { assemblyBuilder.AddAssemblyReference(a); } } // Add the CodeCompileUnit to the compilation assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit); #else // !FEATURE_PAL throw new NotImplementedException("System.Data.Design - ROTORTODO"); #endif // !FEATURE_PAL } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Compilation { using System; using System.IO; using System.Data; using System.Data.Design; using System.Globalization; using System.Xml; using System.Xml.Schema; using System.Reflection; using System.CodeDom; using System.CodeDom.Compiler; using System.Web.Hosting; using System.Web.Configuration; using System.Collections; using Util=System.Web.UI.Util; #if !FEATURE_PAL // FEATURE_PAL does not support System.Data.Design using TypedDataSetGenerator=System.Data.Design.TypedDataSetGenerator; #endif // !FEATURE_PAL [BuildProviderAppliesTo(BuildProviderAppliesTo.Code)] internal class XsdBuildProvider: BuildProvider { public override void GenerateCode(AssemblyBuilder assemblyBuilder) { #if !FEATURE_PAL // FEATURE_PAL does not support System.Data.Design // Get the namespace that we will use string ns = Util.GetNamespaceFromVirtualPath(VirtualPathObject); // We need to use XmlDocument to parse the xsd file is order to open it with the // correct encoding ( XmlDocument doc = new XmlDocument(); using (Stream stream = OpenStream()) { doc.Load(stream); } String content = doc.OuterXml; // Generate a CodeCompileUnit from the dataset CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); CodeNamespace codeNamespace = new CodeNamespace(ns); codeCompileUnit.Namespaces.Add(codeNamespace); // Devdiv 18365 // Call a different Generate method if compiler version is v3.5 bool isVer35 = CompilationUtil.IsCompilerVersion35(assemblyBuilder.CodeDomProvider.GetType()); if (isVer35) { TypedDataSetGenerator.GenerateOption generateOptions = TypedDataSetGenerator.GenerateOption.None; generateOptions |= TypedDataSetGenerator.GenerateOption.HierarchicalUpdate; generateOptions |= TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets; Hashtable customDBProviders = null; TypedDataSetGenerator.Generate(content, codeCompileUnit, codeNamespace, assemblyBuilder.CodeDomProvider, customDBProviders, generateOptions); } else { TypedDataSetGenerator.Generate(content, codeCompileUnit, codeNamespace, assemblyBuilder.CodeDomProvider); } // Add all the assembly references needed by the generated code if (TypedDataSetGenerator.ReferencedAssemblies != null) { foreach (Assembly a in TypedDataSetGenerator.ReferencedAssemblies) { assemblyBuilder.AddAssemblyReference(a); } } // Add the CodeCompileUnit to the compilation assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit); #else // !FEATURE_PAL throw new NotImplementedException("System.Data.Design - ROTORTODO"); #endif // !FEATURE_PAL } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Size.cs
- MILUtilities.cs
- XPathNodeList.cs
- BuildProvider.cs
- Int32Animation.cs
- SoapRpcServiceAttribute.cs
- BaseValidatorDesigner.cs
- SmiTypedGetterSetter.cs
- RuleRefElement.cs
- QuaternionRotation3D.cs
- XsltConvert.cs
- SmiEventSink_Default.cs
- XmlDataImplementation.cs
- SqlUserDefinedTypeAttribute.cs
- SmtpNegotiateAuthenticationModule.cs
- FixedHyperLink.cs
- ConnectionManager.cs
- WebControlAdapter.cs
- HyperLinkColumn.cs
- HitTestFilterBehavior.cs
- _ScatterGatherBuffers.cs
- CharacterString.cs
- ParseElementCollection.cs
- IResourceProvider.cs
- bindurihelper.cs
- BooleanStorage.cs
- DescendantOverDescendantQuery.cs
- CompatibleComparer.cs
- StringAttributeCollection.cs
- TreeNodeStyleCollection.cs
- HttpStreamMessage.cs
- TabItem.cs
- JsonWriterDelegator.cs
- KeyValuePair.cs
- Gdiplus.cs
- DbDataSourceEnumerator.cs
- ConfigurationStrings.cs
- SafeMarshalContext.cs
- PersonalizationDictionary.cs
- DisplayInformation.cs
- AnyAllSearchOperator.cs
- QilPatternVisitor.cs
- Authorization.cs
- SettingsBindableAttribute.cs
- StickyNoteHelper.cs
- CodeEventReferenceExpression.cs
- Attachment.cs
- ReturnType.cs
- NetworkCredential.cs
- ClonableStack.cs
- __Error.cs
- FontClient.cs
- TextParagraphProperties.cs
- LifetimeServices.cs
- FormViewCommandEventArgs.cs
- SqlMethodTransformer.cs
- TextContainerChangeEventArgs.cs
- EntityProviderServices.cs
- GeneralTransform.cs
- ToolboxItemLoader.cs
- LinqDataSourceUpdateEventArgs.cs
- Matrix3D.cs
- InfoCardBinaryReader.cs
- StreamWithDictionary.cs
- GridViewCancelEditEventArgs.cs
- Splitter.cs
- GeneralTransform3D.cs
- CustomAttribute.cs
- DataSet.cs
- LinqDataSourceHelper.cs
- SqlNotificationRequest.cs
- UnsupportedPolicyOptionsException.cs
- LinkButton.cs
- __Filters.cs
- ActiveXHelper.cs
- ListGeneralPage.cs
- PointF.cs
- ValidationError.cs
- TriggerCollection.cs
- CodeNamespaceCollection.cs
- ObjectPersistData.cs
- IgnorePropertiesAttribute.cs
- PreservationFileWriter.cs
- Int32RectValueSerializer.cs
- ResolveNameEventArgs.cs
- RtfToken.cs
- WpfXamlMember.cs
- IPCCacheManager.cs
- ActivityIdHeader.cs
- PreservationFileReader.cs
- LogLogRecordEnumerator.cs
- XmlComplianceUtil.cs
- StringToken.cs
- MarshalByRefObject.cs
- GatewayDefinition.cs
- ECDiffieHellmanPublicKey.cs
- SqlUtils.cs
- DrawListViewColumnHeaderEventArgs.cs
- DispatchChannelSink.cs
- DateTime.cs