Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / System / data / design / TypedTableGenerator.cs / 4 / TypedTableGenerator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All Rights Reserved. // Information Contained Herein is Proprietary and Confidential. // //----------------------------------------------------------------------------- namespace System.Data.Design { using System; using System.Data; using System.Data.Common; using System.CodeDom; using System.Reflection; using System.Xml.Serialization; using System.CodeDom.Compiler; using GenerateOption = TypedDataSetGenerator.GenerateOption; internal sealed class TypedTableGenerator { private TypedDataSourceCodeGenerator codeGenerator = null; private static string LINQOverTDSTableBaseClass = "System.Data.TypedTableBase"; internal TypedTableGenerator(TypedDataSourceCodeGenerator codeGenerator) { this.codeGenerator = codeGenerator; } internal void GenerateTables(CodeTypeDeclaration dataSourceClass) { if(dataSourceClass == null) { throw new InternalException("DataSource CodeTypeDeclaration should not be null."); } foreach(DesignTable table in codeGenerator.TableHandler.Tables) { dataSourceClass.Members.Add(GenerateTable(table, dataSourceClass)); } } private CodeTypeDeclaration GenerateTable(DesignTable designTable, CodeTypeDeclaration dataSourceClass) { // get class name for table string tableClassName = designTable.GeneratorTableClassName; // get table-specific column handler TypedColumnHandler columnHandler = codeGenerator.TableHandler.GetColumnHandler(designTable.Name); // create CodeTypeDeclaration CodeTypeDeclaration dataTableClass = CodeGenHelper.Class(tableClassName, true, TypeAttributes.Public); // set BaseTypes if ((this.codeGenerator.GenerateOptions & GenerateOption.LinqOverTypedDatasets) == GenerateOption.LinqOverTypedDatasets) { dataTableClass.BaseTypes.Add( CodeGenHelper.GlobalGenericType( LINQOverTDSTableBaseClass, CodeGenHelper.Type(designTable.GeneratorRowClassName) ) ); } else { dataTableClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(System.Data.DataTable))); dataTableClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(System.Collections.IEnumerable))); } // set Attributes dataTableClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.Serializable")); dataTableClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlSchemaProviderAttribute).FullName, CodeGenHelper.Primitive("GetTypedTableSchema"))); dataTableClass.Comments.Add(CodeGenHelper.Comment("Represents the strongly named DataTable class.", true)); // add 1 private variable of type DataColumn for each column in the table columnHandler.AddPrivateVariables(dataTableClass); // add 1 property for each column in the table columnHandler.AddTableColumnProperties(dataTableClass); // add count property dataTableClass.Members.Add( CountProperty() ); if (this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareIndexerProperties)) { // add index property dataTableClass.Members.Add(IndexProperty(designTable)); } if (this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareEvents) && this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareDelegates)) { // add typed row changing/changed/deleting/deleted events codeGenerator.RowHandler.AddTypedRowEvents(dataTableClass, designTable.Name); } // create table-method generator TableMethodGenerator tableMethodGenerator = new TableMethodGenerator(codeGenerator, designTable); // generate typed table methods tableMethodGenerator.AddMethods(dataTableClass); return dataTableClass; } private CodeMemberProperty CountProperty() { //\\ public int Count { //\\ get { return this.Rows.Count; } //\\ } CodeMemberProperty countProp = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(System.Int32)), "Count", MemberAttributes.Public | MemberAttributes.Final); countProp.CustomAttributes.Add( CodeGenHelper.AttributeDecl("System.ComponentModel.Browsable", CodeGenHelper.Primitive(false)) ); countProp.GetStatements.Add( CodeGenHelper.Return( CodeGenHelper.Property( CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "Count" ) ) ); return countProp; } private CodeMemberProperty IndexProperty(DesignTable designTable) { string rowConcreteClassName = designTable.GeneratorRowClassName; //\\ publicthis[int index] { //\\ return ( ) this.Rows[index]; //\\ } CodeMemberProperty thisIndex = CodeGenHelper.PropertyDecl( CodeGenHelper.Type(rowConcreteClassName), "Item", MemberAttributes.Public | MemberAttributes.Final ); thisIndex.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(System.Int32)), "index")); thisIndex.GetStatements.Add( CodeGenHelper.Return( CodeGenHelper.Cast( CodeGenHelper.Type(rowConcreteClassName), CodeGenHelper.Indexer( CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), CodeGenHelper.Argument("index") ) ) ) ); return thisIndex; } } } // 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
- CodePropertyReferenceExpression.cs
- DataServiceBuildProvider.cs
- WindowsRegion.cs
- SiteMapDataSourceView.cs
- DataBoundControlAdapter.cs
- TypeBuilder.cs
- TextureBrush.cs
- NotFiniteNumberException.cs
- COM2IDispatchConverter.cs
- SiteMapNode.cs
- GlobalizationSection.cs
- CuspData.cs
- SqlConnectionFactory.cs
- ToolStripContextMenu.cs
- BindingCollection.cs
- ProfileGroupSettings.cs
- WebBrowserNavigatingEventHandler.cs
- ArgumentException.cs
- Pens.cs
- ContactManager.cs
- PrinterUnitConvert.cs
- RegisteredArrayDeclaration.cs
- EmptyQuery.cs
- ScrollBar.cs
- RenamedEventArgs.cs
- AuthorizationSection.cs
- LicenseProviderAttribute.cs
- XpsInterleavingPolicy.cs
- VsPropertyGrid.cs
- PeerDuplexChannelListener.cs
- CacheVirtualItemsEvent.cs
- TextDecorationLocationValidation.cs
- unsafeIndexingFilterStream.cs
- CheckPair.cs
- AsnEncodedData.cs
- XmlNamespaceDeclarationsAttribute.cs
- ContentValidator.cs
- ColumnCollectionEditor.cs
- CriticalFinalizerObject.cs
- FormsAuthentication.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- VectorKeyFrameCollection.cs
- IncrementalCompileAnalyzer.cs
- UniqueTransportManagerRegistration.cs
- PrimaryKeyTypeConverter.cs
- ChineseLunisolarCalendar.cs
- SqlLiftWhereClauses.cs
- AuthenticationSection.cs
- BooleanFunctions.cs
- AnimatedTypeHelpers.cs
- DecoderBestFitFallback.cs
- ObjectQuery.cs
- WebPartConnectionsDisconnectVerb.cs
- BooleanAnimationBase.cs
- ObjectSet.cs
- ApplicationManager.cs
- altserialization.cs
- NativeMethods.cs
- FormsAuthenticationConfiguration.cs
- ResourcePart.cs
- TextMarkerSource.cs
- WindowsListViewItem.cs
- ControlBuilder.cs
- PanelDesigner.cs
- WorkflowApplicationEventArgs.cs
- ToolStripItemEventArgs.cs
- FormClosingEvent.cs
- ColorAnimation.cs
- SapiRecognizer.cs
- VariableQuery.cs
- MulticastDelegate.cs
- RemotingClientProxy.cs
- Boolean.cs
- DataRelationPropertyDescriptor.cs
- WaitForChangedResult.cs
- ComplusTypeValidator.cs
- ProxyWebPartConnectionCollection.cs
- _ContextAwareResult.cs
- KeyedHashAlgorithm.cs
- ControlValuePropertyAttribute.cs
- XmlSchemaInferenceException.cs
- RoleManagerSection.cs
- DaylightTime.cs
- RNGCryptoServiceProvider.cs
- CompilerResults.cs
- ExecutionEngineException.cs
- UnmanagedBitmapWrapper.cs
- TextTreeInsertElementUndoUnit.cs
- GenericAuthenticationEventArgs.cs
- UnsafeNativeMethodsPenimc.cs
- BindingManagerDataErrorEventArgs.cs
- DragStartedEventArgs.cs
- HelpInfo.cs
- PropertyManager.cs
- EncoderNLS.cs
- StackSpiller.Bindings.cs
- TextEndOfLine.cs
- DotExpr.cs
- XmlName.cs
- OneToOneMappingSerializer.cs