1 //------------------------------------------------------------------------------ 2 // <copyright file="DataObjectFieldAttribute.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 //------------------------------------------------------------------------------ 6 7 namespace System.ComponentModel { 8 9 using System; 10 using System.Security.Permissions; 11 12 /// <devdoc> 13 /// Represents a field of a DataObject. Use this attribute on a field to indicate 14 /// properties such as primary key, identity, nullability, and length. 15 /// </devdoc> 16 [AttributeUsage(AttributeTargets.Property)] 17 public sealed class DataObjectFieldAttribute : Attribute { 18 private bool _primaryKey; 19 private bool _isIdentity; 20 private bool _isNullable; 21 private int _length; 22 DataObjectFieldAttribute(bool primaryKey)23 public DataObjectFieldAttribute(bool primaryKey) : this(primaryKey, false, false, -1) { 24 } 25 DataObjectFieldAttribute(bool primaryKey, bool isIdentity)26 public DataObjectFieldAttribute(bool primaryKey, bool isIdentity) : this(primaryKey, isIdentity, false, -1) { 27 } 28 DataObjectFieldAttribute(bool primaryKey, bool isIdentity, bool isNullable)29 public DataObjectFieldAttribute(bool primaryKey, bool isIdentity, bool isNullable) : this(primaryKey, isIdentity, isNullable, -1){ 30 } 31 DataObjectFieldAttribute(bool primaryKey, bool isIdentity, bool isNullable, int length)32 public DataObjectFieldAttribute(bool primaryKey, bool isIdentity, bool isNullable, int length) { 33 _primaryKey = primaryKey; 34 _isIdentity = isIdentity; 35 _isNullable = isNullable; 36 _length = length; 37 } 38 39 public bool IsIdentity { 40 get { 41 return _isIdentity; 42 } 43 } 44 45 public bool IsNullable { 46 get { 47 return _isNullable; 48 } 49 } 50 51 public int Length { 52 get { 53 return _length; 54 } 55 } 56 57 public bool PrimaryKey { 58 get { 59 return _primaryKey; 60 } 61 } 62 Equals(object obj)63 public override bool Equals(object obj) { 64 if (obj == this) { 65 return true; 66 } 67 68 DataObjectFieldAttribute other = obj as DataObjectFieldAttribute; 69 return (other != null) && 70 (other.IsIdentity == IsIdentity) && 71 (other.IsNullable == IsNullable) && 72 (other.Length == Length) && 73 (other.PrimaryKey == PrimaryKey); 74 } 75 GetHashCode()76 public override int GetHashCode() { 77 return base.GetHashCode(); 78 } 79 } 80 } 81