Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / ModelProviders / ColumnProvider.cs / 1305376 / ColumnProvider.cs
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Web.DynamicData;
using System.Web.DynamicData.Util;
namespace System.Web.DynamicData.ModelProviders {
///
/// Base provider class for columns.
/// Each provider type (e.g. Linq To Sql, Entity Framework, 3rd party) extends this class.
///
public abstract class ColumnProvider {
private bool? _isReadOnly;
///
/// ctor
///
/// the table this column belongs to
protected ColumnProvider(TableProvider table) {
if (table == null) {
throw new ArgumentNullException("table");
}
Table = table;
}
///
/// readable representation
///
///
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
public override string ToString() {
// To help identifying objects in debugger
return Name ?? base.ToString();
}
internal virtual PropertyDescriptor PropertyDescriptor {
get {
return Table.GetTypeDescriptor().GetProperties().Find(Name, true/*ignoreCase*/);
}
}
public virtual AttributeCollection Attributes {
get {
var propertyDescriptor = PropertyDescriptor;
var attributes = propertyDescriptor != null ? propertyDescriptor.Attributes : AttributeCollection.Empty;
return AddDefaultAttributes(this, attributes);
}
}
protected static AttributeCollection AddDefaultAttributes(ColumnProvider columnProvider, AttributeCollection attributes) {
List extraAttributes = new List();
// If there is no required attribute and the Provider says required, add one
var requiredAttribute = attributes.FirstOrDefault();
if (requiredAttribute == null && !columnProvider.Nullable) {
extraAttributes.Add(new RequiredAttribute());
}
// If there is no StringLength attribute and it's a string, add one
var stringLengthAttribute = attributes.FirstOrDefault();
int maxLength = columnProvider.MaxLength;
if (stringLengthAttribute == null && columnProvider.ColumnType == typeof(String) && maxLength > 0) {
extraAttributes.Add(new StringLengthAttribute(maxLength));
}
// If we need any extra attributes, create a new collection
if (extraAttributes.Count > 0) {
attributes = AttributeCollection.FromExisting(attributes, extraAttributes.ToArray());
}
return attributes;
}
///
/// The name of the column
///
public virtual string Name { get; protected set; }
///
/// The CLR type of the column
///
public virtual Type ColumnType { get; protected set; }
///
/// Is this column a primary key in its table
///
public virtual bool IsPrimaryKey { get; protected set; }
///
/// Specifies if this column is read only
///
public virtual bool IsReadOnly {
get {
if (_isReadOnly == null) {
var propertyDescriptor = PropertyDescriptor;
_isReadOnly = propertyDescriptor != null ? propertyDescriptor.IsReadOnly : false;
}
return _isReadOnly.Value;
}
protected set {
_isReadOnly = value;
}
}
///
/// Is it a database generated column
///
public virtual bool IsGenerated { get; protected set; }
///
/// Returns whether the underlying model supports sorting of the table on this column
///
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sortable", Justification="It's a valid word")]
public virtual bool IsSortable { get; protected set; }
///
/// The maximun length allowed for this column (applies to string columns)
///
public virtual int MaxLength { get; protected set; }
///
/// Does it allow null values (meaning it is not required)
///
public virtual bool Nullable { get; protected set; }
///
/// meant to indicate that a member is an extra property that was declared in a partial class
///
public virtual bool IsCustomProperty { get; protected set; }
///
/// If the column represents and association with anther table, this returns the association information.
/// Otherwise, null is returned.
///
public virtual AssociationProvider Association { get; protected set; }
///
/// The table that this column belongs to
///
public TableProvider Table { get; private set; }
///
/// The PropertyInfo of the property that represents this column on the entity type
///
public virtual PropertyInfo EntityTypeProperty { get; protected set; }
///
/// This is set for columns that are part of a foreign key. Note that it is NOT set for
/// the strongly typed entity ref columns (though those columns 'use' one or more columns
/// where IsForeignKeyComponent is set).
///
public virtual bool IsForeignKeyComponent { get; protected set; }
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Web.DynamicData;
using System.Web.DynamicData.Util;
namespace System.Web.DynamicData.ModelProviders {
///
/// Base provider class for columns.
/// Each provider type (e.g. Linq To Sql, Entity Framework, 3rd party) extends this class.
///
public abstract class ColumnProvider {
private bool? _isReadOnly;
///
/// ctor
///
/// the table this column belongs to
protected ColumnProvider(TableProvider table) {
if (table == null) {
throw new ArgumentNullException("table");
}
Table = table;
}
///
/// readable representation
///
///
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
public override string ToString() {
// To help identifying objects in debugger
return Name ?? base.ToString();
}
internal virtual PropertyDescriptor PropertyDescriptor {
get {
return Table.GetTypeDescriptor().GetProperties().Find(Name, true/*ignoreCase*/);
}
}
public virtual AttributeCollection Attributes {
get {
var propertyDescriptor = PropertyDescriptor;
var attributes = propertyDescriptor != null ? propertyDescriptor.Attributes : AttributeCollection.Empty;
return AddDefaultAttributes(this, attributes);
}
}
protected static AttributeCollection AddDefaultAttributes(ColumnProvider columnProvider, AttributeCollection attributes) {
List extraAttributes = new List();
// If there is no required attribute and the Provider says required, add one
var requiredAttribute = attributes.FirstOrDefault();
if (requiredAttribute == null && !columnProvider.Nullable) {
extraAttributes.Add(new RequiredAttribute());
}
// If there is no StringLength attribute and it's a string, add one
var stringLengthAttribute = attributes.FirstOrDefault();
int maxLength = columnProvider.MaxLength;
if (stringLengthAttribute == null && columnProvider.ColumnType == typeof(String) && maxLength > 0) {
extraAttributes.Add(new StringLengthAttribute(maxLength));
}
// If we need any extra attributes, create a new collection
if (extraAttributes.Count > 0) {
attributes = AttributeCollection.FromExisting(attributes, extraAttributes.ToArray());
}
return attributes;
}
///
/// The name of the column
///
public virtual string Name { get; protected set; }
///
/// The CLR type of the column
///
public virtual Type ColumnType { get; protected set; }
///
/// Is this column a primary key in its table
///
public virtual bool IsPrimaryKey { get; protected set; }
///
/// Specifies if this column is read only
///
public virtual bool IsReadOnly {
get {
if (_isReadOnly == null) {
var propertyDescriptor = PropertyDescriptor;
_isReadOnly = propertyDescriptor != null ? propertyDescriptor.IsReadOnly : false;
}
return _isReadOnly.Value;
}
protected set {
_isReadOnly = value;
}
}
///
/// Is it a database generated column
///
public virtual bool IsGenerated { get; protected set; }
///
/// Returns whether the underlying model supports sorting of the table on this column
///
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sortable", Justification="It's a valid word")]
public virtual bool IsSortable { get; protected set; }
///
/// The maximun length allowed for this column (applies to string columns)
///
public virtual int MaxLength { get; protected set; }
///
/// Does it allow null values (meaning it is not required)
///
public virtual bool Nullable { get; protected set; }
///
/// meant to indicate that a member is an extra property that was declared in a partial class
///
public virtual bool IsCustomProperty { get; protected set; }
///
/// If the column represents and association with anther table, this returns the association information.
/// Otherwise, null is returned.
///
public virtual AssociationProvider Association { get; protected set; }
///
/// The table that this column belongs to
///
public TableProvider Table { get; private set; }
///
/// The PropertyInfo of the property that represents this column on the entity type
///
public virtual PropertyInfo EntityTypeProperty { get; protected set; }
///
/// This is set for columns that are part of a foreign key. Note that it is NOT set for
/// the strongly typed entity ref columns (though those columns 'use' one or more columns
/// where IsForeignKeyComponent is set).
///
public virtual bool IsForeignKeyComponent { get; protected set; }
}
}
// 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
- DataBinder.cs
- BrowserInteropHelper.cs
- EventLogger.cs
- XmlSerializerFactory.cs
- HwndSource.cs
- PenLineCapValidation.cs
- NodeFunctions.cs
- PowerStatus.cs
- StylusDownEventArgs.cs
- CodeComment.cs
- Comparer.cs
- ContentValidator.cs
- Wizard.cs
- StringAnimationUsingKeyFrames.cs
- Propagator.JoinPropagator.cs
- ViewEventArgs.cs
- ScalarConstant.cs
- StorageEntitySetMapping.cs
- PropertyChangedEventArgs.cs
- HostedElements.cs
- FunctionDefinition.cs
- COSERVERINFO.cs
- XmlChoiceIdentifierAttribute.cs
- RootProfilePropertySettingsCollection.cs
- TransformProviderWrapper.cs
- XmlLinkedNode.cs
- GridViewRowPresenterBase.cs
- SvcFileManager.cs
- IndexerNameAttribute.cs
- SynchronizedInputHelper.cs
- ObjectAnimationUsingKeyFrames.cs
- GroupBoxAutomationPeer.cs
- SystemException.cs
- GACIdentityPermission.cs
- PointHitTestResult.cs
- SerializableAttribute.cs
- ReflectionTypeLoadException.cs
- TextAutomationPeer.cs
- TypedRowHandler.cs
- Queue.cs
- TextEditorContextMenu.cs
- XmlSerializationReader.cs
- EventMappingSettingsCollection.cs
- IsolationInterop.cs
- NameHandler.cs
- OperationValidationEventArgs.cs
- XmlEnumAttribute.cs
- XmlComplianceUtil.cs
- PromptEventArgs.cs
- ScriptServiceAttribute.cs
- TextTreeTextBlock.cs
- ContainerControl.cs
- LogReservationCollection.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- XmlJsonReader.cs
- BeginGetFileNameFromUserRequest.cs
- RenderCapability.cs
- PropertyChange.cs
- OdbcErrorCollection.cs
- TableColumnCollectionInternal.cs
- NetTcpSection.cs
- EntityDataSourceState.cs
- Directory.cs
- KerberosRequestorSecurityToken.cs
- AnnotationHelper.cs
- CallContext.cs
- DataGridViewColumnCollectionEditor.cs
- Ops.cs
- HiddenField.cs
- ExtentJoinTreeNode.cs
- SectionVisual.cs
- Content.cs
- PropertyManager.cs
- ApplicationFileParser.cs
- OuterGlowBitmapEffect.cs
- Size3DConverter.cs
- RangeBaseAutomationPeer.cs
- RadioButton.cs
- CodeDelegateInvokeExpression.cs
- SafeLibraryHandle.cs
- ClientBuildManagerCallback.cs
- Relationship.cs
- LicenseProviderAttribute.cs
- VirtualizingStackPanel.cs
- FrameAutomationPeer.cs
- Int32CollectionConverter.cs
- ExpressionBuilderContext.cs
- CommentEmitter.cs
- SHA1CryptoServiceProvider.cs
- Vector3DAnimationBase.cs
- PartialToken.cs
- PeerNodeTraceRecord.cs
- SwitchAttribute.cs
- TableDesigner.cs
- AsymmetricAlgorithm.cs
- SemanticResolver.cs
- Stylus.cs
- XmlCharType.cs
- ServicePoint.cs
- CriticalFinalizerObject.cs