protected virtual new AutoGeneratedField CreateAutoGeneratedColumn(AutoGeneratedFieldProperties fieldProperties)
        {
            Contract.Requires(fieldProperties != null);
            Contract.Ensures(Contract.Result <AutoGeneratedField>() != null);

            return(default(AutoGeneratedField));
        }
		internal AutoGeneratedField (AutoGeneratedFieldProperties fieldProperties)
		{
			DataField = fieldProperties.DataField;
			DataType = fieldProperties.Type;
			SortExpression = fieldProperties.Name;
			HeaderText = fieldProperties.Name;
			ReadOnly = fieldProperties.IsReadOnly;
		}
 internal AutoGeneratedField(AutoGeneratedFieldProperties fieldProperties)
 {
     DataField      = fieldProperties.DataField;
     DataType       = fieldProperties.Type;
     SortExpression = fieldProperties.Name;
     HeaderText     = fieldProperties.Name;
     ReadOnly       = fieldProperties.IsReadOnly;
 }
        /// <devdoc>
        /// Create a single autogenerated field.  This function can be overridden to create a different AutoGeneratedField.
        /// </devdoc>
        protected virtual AutoGeneratedField CreateAutoGeneratedFieldFromFieldProperties(AutoGeneratedFieldProperties fieldProperties) {
            AutoGeneratedField field = new AutoGeneratedField(fieldProperties.DataField);
            string name = fieldProperties.Name;
            ((IStateManager)field).TrackViewState();

            field.HeaderText = name;
            field.SortExpression = name;
            field.ReadOnly = fieldProperties.IsReadOnly;
            field.DataType = fieldProperties.Type;

            return field;
        }
        protected virtual void LoadViewState(object savedState) {
            if (savedState != null) {
                object[] autoGenFieldStateArray = (object[])savedState;
                int fieldCount = autoGenFieldStateArray.Length;
                AutoGeneratedFieldProperties.Clear();

                for (int i = 0; i < fieldCount; i++) {
                    AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                    ((IStateManager)fieldProps).TrackViewState();
                    ((IStateManager)fieldProps).LoadViewState(autoGenFieldStateArray[i]);
                    AutoGeneratedFieldProperties.Add(fieldProps);
                }
            }
        }
        protected virtual void LoadViewState(object savedState)
        {
            if (savedState != null)
            {
                object[] autoGenFieldStateArray = (object[])savedState;
                int      fieldCount             = autoGenFieldStateArray.Length;
                AutoGeneratedFieldProperties.Clear();

                for (int i = 0; i < fieldCount; i++)
                {
                    AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                    ((IStateManager)fieldProps).TrackViewState();
                    ((IStateManager)fieldProps).LoadViewState(autoGenFieldStateArray[i]);
                    AutoGeneratedFieldProperties.Add(fieldProps);
                }
            }
        }
 protected virtual new AutoGeneratedField CreateAutoGeneratedColumn(AutoGeneratedFieldProperties fieldProperties)
 {
     return(default(AutoGeneratedField));
 }
        public override List <AutoGeneratedField> CreateAutoGeneratedFields(object dataItem, Control control)
        {
            if (!(control is DetailsView))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidDefaultAutoFieldGenerator, GetType().FullName, typeof(DetailsView).FullName));
            }

            DetailsView detailsView = control as DetailsView;

            if (dataItem == null)
            {
                // note that we're not throwing an exception in this case, and the calling
                // code should be able to handle a null arraylist being returned
                return(null);
            }

            List <AutoGeneratedField>    generatedFields = new List <AutoGeneratedField>();
            PropertyDescriptorCollection propDescs       = null;
            bool throwException = true;
            Type dataItemType   = null;

            //The base class ensures that the AutoGeneratedFieldProperties collection is reset before this method is called.
            //However we are doing this again in here because we have another caller DetailsView.CreateAutoGeneratedRows which is
            //not being used anywhere today but kept for backward compatibility.
            if (AutoGeneratedFieldProperties.Count > 0)
            {
                AutoGeneratedFieldProperties.Clear();
            }

            if (dataItem != null)
            {
                dataItemType = dataItem.GetType();
            }

            if ((dataItem != null) && (dataItem is ICustomTypeDescriptor))
            {
                // Get the custom properties of the object
                propDescs = TypeDescriptor.GetProperties(dataItem);
            }
            else if (dataItemType != null)
            {
                // directly bindable types: strings, ints etc. get treated specially, since we
                // don't care about their properties, but rather we care about them directly
                if (ShouldGenerateField(dataItemType, detailsView))
                {
                    AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                    ((IStateManager)fieldProps).TrackViewState();

                    fieldProps.Name      = "Item";
                    fieldProps.DataField = AutoGeneratedField.ThisExpression;
                    fieldProps.Type      = dataItemType;

                    AutoGeneratedField field = CreateAutoGeneratedFieldFromFieldProperties(fieldProps);
                    if (field != null)
                    {
                        generatedFields.Add(field);
                        AutoGeneratedFieldProperties.Add(fieldProps);
                    }
                }
                else
                {
                    // complex type... we get its properties
                    propDescs = TypeDescriptor.GetProperties(dataItemType);
                }
            }

            if ((propDescs != null) && (propDescs.Count != 0))
            {
                string[] dataKeyNames   = detailsView.DataKeyNames;
                int      keyNamesLength = dataKeyNames.Length;
                string[] dataKeyNamesCaseInsensitive = new string[keyNamesLength];
                for (int i = 0; i < keyNamesLength; i++)
                {
                    dataKeyNamesCaseInsensitive[i] = dataKeyNames[i].ToLowerInvariant();
                }
                foreach (PropertyDescriptor pd in propDescs)
                {
                    Type propertyType = pd.PropertyType;
                    if (ShouldGenerateField(propertyType, detailsView))
                    {
                        string name  = pd.Name;
                        bool   isKey = ((IList)dataKeyNamesCaseInsensitive).Contains(name.ToLowerInvariant());
                        AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                        ((IStateManager)fieldProps).TrackViewState();

                        fieldProps.Name       = name;
                        fieldProps.IsReadOnly = isKey;
                        fieldProps.Type       = propertyType;
                        fieldProps.DataField  = name;

                        AutoGeneratedField field = CreateAutoGeneratedFieldFromFieldProperties(fieldProps);
                        if (field != null)
                        {
                            generatedFields.Add(field);
                            AutoGeneratedFieldProperties.Add(fieldProps);
                        }
                    }
                }
            }

            if ((generatedFields.Count == 0) && throwException)
            {
                // this handles the case where we got back something that either had no
                // properties, or all properties were not bindable.
                throw new InvalidOperationException(SR.GetString(SR.DetailsView_NoAutoGenFields, detailsView.ID));
            }

            return(generatedFields);
        }
        public override List<AutoGeneratedField> CreateAutoGeneratedFields(object dataObject, Control control) {
            if (!(control is GridView)) {
                throw new ArgumentException(SR.GetString(SR.InvalidDefaultAutoFieldGenerator, GetType().FullName, typeof(GridView).FullName));
            }

            Debug.Assert(dataObject == null || dataObject is PagedDataSource);

            PagedDataSource dataSource = dataObject as PagedDataSource;
            GridView gridView = control as GridView;

            if (dataSource == null) {
                // note that we're not throwing an exception in this case, and the calling
                // code should be able to handle a null arraylist being returned
                return null;
            }

            List<AutoGeneratedField> generatedFields = new List<AutoGeneratedField>();
            PropertyDescriptorCollection propDescs = null;
            bool throwException = true;

            // try ITypedList first
            // A PagedDataSource implements this, but returns null, if the underlying data source
            // does not implement it.
            propDescs = ((ITypedList)dataSource).GetItemProperties(new PropertyDescriptor[0]);

            if (propDescs == null) {
                Type sampleItemType = null;
                object sampleItem = null;

                IEnumerable realDataSource = dataSource.DataSource;
                Debug.Assert(realDataSource != null, "Must have a real data source when calling CreateAutoGeneratedColumns");

                Type dataSourceType = realDataSource.GetType();

                // try for a typed Row property, which should be present on strongly typed collections
                PropertyInfo itemProp = dataSourceType.GetProperty("Item", BindingFlags.Public | BindingFlags.Instance, null, null, new Type[] { typeof(int) }, null);
                if (itemProp != null) {
                    sampleItemType = itemProp.PropertyType;
                }

                if ((sampleItemType == null) || (sampleItemType == typeof(object))) {
                    // last resort... try to get ahold of the first item by beginning the
                    // enumeration

                    IEnumerator e = dataSource.GetEnumerator();

                    if (e.MoveNext()) {
                        sampleItem = e.Current;
                    }
                    else {
                        // we don't want to throw an exception if we're bound to an IEnumerable
                        // data source with no records... we'll simply bail and not show any data
                        throwException = false;
                    }
                    if (sampleItem != null) {
                        sampleItemType = sampleItem.GetType();
                    }

                    // We must store the enumerator regardless of whether we got back an item from it
                    // because we cannot start the enumeration again, in the case of a DataReader.
                    // Code in CreateChildControls must deal appropriately for the case where
                    // there is a stored enumerator, but a null object as the first item.
                    gridView.StoreEnumerator(e, sampleItem);
                }

                if ((sampleItem != null) && (sampleItem is ICustomTypeDescriptor)) {
                    // Get the custom properties of the object
                    propDescs = TypeDescriptor.GetProperties(sampleItem);
                }
                else if (sampleItemType != null) {
                    // directly bindable types: strings, ints etc. get treated specially, since we
                    // don't care about their properties, but rather we care about them directly
                    if (ShouldGenerateField(sampleItemType, gridView)) {
                        AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                        ((IStateManager)fieldProps).TrackViewState();

                        fieldProps.Type = sampleItemType;
                        fieldProps.Name = "Item";
                        fieldProps.DataField = AutoGeneratedField.ThisExpression;

                        AutoGeneratedField field = CreateAutoGeneratedFieldFromFieldProperties(fieldProps);
                        if (field != null) {
                            generatedFields.Add(field);

                            AutoGeneratedFieldProperties.Add(fieldProps);
                        }
                    }
                    else {
                        // complex type... we get its properties
                        propDescs = TypeDescriptor.GetProperties(sampleItemType);
                    }
                }
            }
            else {
                if (propDescs.Count == 0) {
                    // we don't want to throw an exception if we're bound to an ITypedList
                    // data source with no records... we'll simply bail and not show any data
                    throwException = false;
                }
            }

            if ((propDescs != null) && (propDescs.Count != 0)) {
                string[] dataKeyNames = gridView.DataKeyNames;
                int keyNamesLength = dataKeyNames.Length;
                string[] dataKeyNamesCaseInsensitive = new string[keyNamesLength];
                for (int i = 0; i < keyNamesLength; i++) {
                    dataKeyNamesCaseInsensitive[i] = dataKeyNames[i].ToLowerInvariant();
                }
                foreach (PropertyDescriptor pd in propDescs) {
                    Type propertyType = pd.PropertyType;
                    if (ShouldGenerateField(propertyType, gridView)) {
                        string name = pd.Name;
                        bool isKey = ((IList)dataKeyNamesCaseInsensitive).Contains(name.ToLowerInvariant());
                        AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                        ((IStateManager)fieldProps).TrackViewState();
                        fieldProps.Name = name;
                        fieldProps.IsReadOnly = isKey;
                        fieldProps.Type = propertyType;
                        fieldProps.DataField = name;

                        AutoGeneratedField field = CreateAutoGeneratedFieldFromFieldProperties(fieldProps);
                        if (field != null) {
                            generatedFields.Add(field);
                            AutoGeneratedFieldProperties.Add(fieldProps);
                        }
                    }
                }
            }

            if ((generatedFields.Count == 0) && throwException) {
                // this handles the case where we got back something that either had no
                // properties, or all properties were not bindable.
                throw new InvalidOperationException(SR.GetString(SR.GridView_NoAutoGenFields, gridView.ID));
            }

            return generatedFields;
        }
		AutoGeneratedFieldProperties[] CreateAutoFieldProperties (object dataItem)
		{
			PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
			
			ArrayList retVal = new ArrayList();
			if (props != null && props.Count > 0)
			{
				foreach (PropertyDescriptor current in props) {
					if (IsBindableType (current.PropertyType)) {
						AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
						((IStateManager)field).TrackViewState();
						field.Name = current.Name;
						field.DataField = current.Name;
						field.IsReadOnly = current.IsReadOnly;
						field.Type = current.PropertyType;
						retVal.Add (field);
					}
				}
			}

			if (retVal.Count > 0)
				return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
			else
				return new AutoGeneratedFieldProperties [0];
		}
		AutoGeneratedFieldProperties[] CreateAutoFieldProperties (object dataItem)
		{
			if (IsBindableType (dataItem.GetType ()))
			{
				AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
				((IStateManager) field).TrackViewState ();
				field.Name = "Item";
				field.DataField = BoundField.ThisExpression;
				field.Type = dataItem.GetType ();
				return new AutoGeneratedFieldProperties [] { field };
			}

			PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem, false);

			if (props != null && props.Count > 0) {
				ArrayList retVal = new ArrayList ();
				foreach (PropertyDescriptor current in props) {
					if (IsBindableType (current.PropertyType)) {
						AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
						((IStateManager) field).TrackViewState ();
						field.Name = current.Name;
						field.DataField = current.Name;
						for (int i = 0; i < DataKeyNames.Length; i++) {
							if (string.Compare (DataKeyNames [i], current.Name, StringComparison.InvariantCultureIgnoreCase) == 0) {
								field.IsReadOnly = true;
								break;
							}
						}
						field.Type = current.PropertyType;
						retVal.Add (field);
					}
				}
				if (retVal.Count > 0)
					return (AutoGeneratedFieldProperties []) retVal.ToArray (typeof (AutoGeneratedFieldProperties));
			}
			throw new HttpException (String.Format ("DetailsView with id '{0}' did not have any properties or attributes from which to generate fields.  Ensure that your data source has content.", ID));
		}
		protected virtual AutoGeneratedField CreateAutoGeneratedColumn (AutoGeneratedFieldProperties fieldProperties)
		{
			return new AutoGeneratedField (fieldProperties);
		}
Exemple #13
0
		public AutoGeneratedField DoCreateAutoGeneratedColumn (AutoGeneratedFieldProperties fieldProperties)
		{
			return base.CreateAutoGeneratedColumn (fieldProperties);
		}
		protected override void LoadViewState (object savedState)
		{
			if (savedState == null) {
				base.LoadViewState (null);
				return;
			}

			object [] states = (object []) savedState;
			
			if (states[11] != null) {
				object[] data = (object[]) states [11];
				autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
				for (int n=0; n<data.Length; n++) {
					IStateManager p = new AutoGeneratedFieldProperties ();
					p.TrackViewState ();
					p.LoadViewState (data [n]);
					autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
				}
			}

			base.LoadViewState (states[0]);
			
			if (states[1] != null) ((IStateManager)Columns).LoadViewState (states[1]);
			if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
			if (states[3] != null) ((IStateManager)AlternatingRowStyle).LoadViewState (states[3]);
			if (states[4] != null) ((IStateManager)FooterStyle).LoadViewState (states[4]);
			if (states[5] != null) ((IStateManager)HeaderStyle).LoadViewState (states[5]);
			if (states[6] != null) ((IStateManager)PagerStyle).LoadViewState (states[6]);
			if (states[7] != null) ((IStateManager)RowStyle).LoadViewState (states[7]);
			if (states[8] != null) ((IStateManager)SelectedRowStyle).LoadViewState (states[8]);
			if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
			if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
		}
Exemple #15
0
        AutoGeneratedFieldProperties[] CreateAutoFieldProperties(IEnumerable source, IEnumerator en)
        {
            Data = null;
            JsonData = "";

            if (this.SerializationMode == SerializationMode.Complex)
            {
                Data = source;
                return null;
            }
            
            if (source == null) return null;

            if (source is string && source.ToString().StartsWith("http"))
            {
                this.JsonData = "'{0}'".FormatWith(source);
                this.IsUrl = true;
                return null;
            }

            ITypedList typed = source as ITypedList;
            PropertyDescriptorCollection props = typed == null ? null : typed.GetItemProperties(new PropertyDescriptor[0]);

            Type prop_type;

            ArrayList retVal = new ArrayList();


            if (props == null)
            {
                object fitem = null;
                prop_type = null;
                PropertyInfo prop_item = source.GetType().GetProperty("Item",
                                                  BindingFlags.Instance | BindingFlags.Static |
                                                  BindingFlags.Public, null, null,
                                                  new Type[] { typeof(int) }, null);

                if (prop_item != null)
                {
                    prop_type = prop_item.PropertyType;

                    if (prop_type.IsInterface)
                    {
                        prop_type = null;
                    }
                }

                if (prop_type == null || prop_type == typeof(object))
                {
                    if (en.MoveNext())
                    {
                        fitem = en.Current;
                        this.firstRecord = fitem;
                    }

                    if (fitem != null)
                    {
                        prop_type = fitem.GetType();
                    }
                }

                if (fitem != null && fitem is ICustomTypeDescriptor)
                {
                    props = TypeDescriptor.GetProperties(fitem);
                }
                else if (prop_type != null)
                {
                    if (IsBindableType(prop_type))
                    {
                        AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties();
                        ((IStateManager)field).TrackViewState();
                        field.Name = "Item";
                        field.DataField = BoundField.ThisExpression;
                        field.Type = prop_type;
                        retVal.Add(field);
                    }
                    else
                    {
                        if (prop_type.IsArray)
                        {
                            Data = source;
                            return null;
                        }
                        else
                        {
                            props = TypeDescriptor.GetProperties(prop_type); 
                        }
                    }
                }
            }

            if (props != null && props.Count > 0)
            {
                foreach (PropertyDescriptor current in props)
                {
                    if (this.IsBindableType(current.PropertyType) || this.IsComplexField(current.Name))
                    {
                        AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties();
                        field.Name = current.Name;
                        field.DataField = current.Name;
                        retVal.Add(field);
                    }
                }
            }

            if (retVal.Count > 0)
            {
                return (AutoGeneratedFieldProperties[])retVal.ToArray(typeof(AutoGeneratedFieldProperties));
            }
            
            return null;
        }
        /// <devdoc>
        /// Create a single autogenerated field.  This function can be overridden to create a different AutoGeneratedField.
        /// </devdoc>
        protected virtual AutoGeneratedField CreateAutoGeneratedFieldFromFieldProperties(AutoGeneratedFieldProperties fieldProperties)
        {
            AutoGeneratedField field = new AutoGeneratedField(fieldProperties.DataField);
            string             name  = fieldProperties.Name;

            ((IStateManager)field).TrackViewState();

            field.HeaderText     = name;
            field.SortExpression = name;
            field.ReadOnly       = fieldProperties.IsReadOnly;
            field.DataType       = fieldProperties.Type;

            return(field);
        }
Exemple #17
0
        private object GetFieldValue(AutoGeneratedFieldProperties property, object obj, RecordField field, System.Data.DataRow dataRow)
        {
            if (field != null && field.ServerMapping.IsNotEmpty())
            {
                string[] mapping = field.ServerMapping.Split('.');

                if (mapping.Length > 1)
                {
                    for (int i = 0; i < mapping.Length; i++)
                    {
                        if (dataRow != null && dataRow.IsNull(mapping[i]))
                        {
                            return null;
                        }
                        
                        PropertyInfo p = obj.GetType().GetProperty(mapping[i]);
                        try
                        {
                            obj = p.GetValue(obj, null);
                        }
                        catch (NullReferenceException e)
                        {
                            throw new NullReferenceException(String.Format("Mapped property '{0}' doesn't exist", mapping[i]));
                        }
                        
                        if (obj == null)
                        {
                            return null;
                        }
                    }

                    return obj;
                }
            }

            return (dataRow != null && dataRow.IsNull(property.DataField)) ? null : DataBinder.GetPropertyValue(obj, property.DataField);
        }
Exemple #18
0
        private void BindRecord(AutoGeneratedFieldProperties[] autoFieldProperties, StringBuilder sb, object obj)
        {
            sb.Append("{");
            System.Data.DataRow dataRow = obj as System.Data.DataRow;

            foreach (AutoGeneratedFieldProperties property in autoFieldProperties)
            {
                FieldInReader field = this.IsInReader(property.DataField);

                if (this.IgnoreExtraFields && !field.InReader)
                {
                    continue;
                }
                
                if (field.Fields != null && field.Fields.Count > 0)
                {
                    foreach (RecordField recordField in field.Fields)
                    {
                        object value = this.GetFieldValue(property, obj, recordField, dataRow);
                        if (value != null && value.GetType().IsEnum && recordField.Type == RecordFieldType.Int)
                        {
                            value = (int)value;
                        }
                        sb.AppendFormat("{0}:{1},", JSON.Serialize(string.IsNullOrEmpty(recordField.Mapping) ? recordField.Name : recordField.Mapping), JSON.Serialize(value));
                    }
                }
                else
                {                    
                    if (dataRow == null || !dataRow.IsNull(property.DataField))
                    {
                        sb.AppendFormat("{0}:{1},", JSON.Serialize(property.DataField), JSON.Serialize(DataBinder.GetPropertyValue(obj, property.DataField)));
                    }
                }
            }
            
            RemoveLastComma(sb);
            sb.Append("},");
        }
        public override List<AutoGeneratedField> CreateAutoGeneratedFields(object dataItem, Control control) {
            if (!(control is DetailsView)) {
                throw new ArgumentException(SR.GetString(SR.InvalidDefaultAutoFieldGenerator, GetType().FullName, typeof(DetailsView).FullName));
            }

            DetailsView detailsView = control as DetailsView;

            if (dataItem == null) {
                // note that we're not throwing an exception in this case, and the calling
                // code should be able to handle a null arraylist being returned
                return null;
            }

            List<AutoGeneratedField> generatedFields = new List<AutoGeneratedField>();
            PropertyDescriptorCollection propDescs = null;
            bool throwException = true;
            Type dataItemType = null;

            //The base class ensures that the AutoGeneratedFieldProperties collection is reset before this method is called.
            //However we are doing this again in here because we have another caller DetailsView.CreateAutoGeneratedRows which is
            //not being used anywhere today but kept for backward compatibility.
            if (AutoGeneratedFieldProperties.Count > 0) {
                AutoGeneratedFieldProperties.Clear();
            }

            if (dataItem != null)
                dataItemType = dataItem.GetType();

            if ((dataItem != null) && (dataItem is ICustomTypeDescriptor)) {
                // Get the custom properties of the object
                propDescs = TypeDescriptor.GetProperties(dataItem);
            }
            else if (dataItemType != null) {
                // directly bindable types: strings, ints etc. get treated specially, since we
                // don't care about their properties, but rather we care about them directly
                if (ShouldGenerateField(dataItemType, detailsView)) {
                    AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                    ((IStateManager)fieldProps).TrackViewState();

                    fieldProps.Name = "Item";
                    fieldProps.DataField = AutoGeneratedField.ThisExpression;
                    fieldProps.Type = dataItemType;

                    AutoGeneratedField field = CreateAutoGeneratedFieldFromFieldProperties(fieldProps);
                    if (field != null) {
                        generatedFields.Add(field);
                        AutoGeneratedFieldProperties.Add(fieldProps);
                    }

                }
                else {
                    // complex type... we get its properties
                    propDescs = TypeDescriptor.GetProperties(dataItemType);
                }
            }

            if ((propDescs != null) && (propDescs.Count != 0)) {
                string[] dataKeyNames = detailsView.DataKeyNames;
                int keyNamesLength = dataKeyNames.Length;
                string[] dataKeyNamesCaseInsensitive = new string[keyNamesLength];
                for (int i = 0; i < keyNamesLength; i++) {
                    dataKeyNamesCaseInsensitive[i] = dataKeyNames[i].ToLowerInvariant();
                }
                foreach (PropertyDescriptor pd in propDescs) {
                    Type propertyType = pd.PropertyType;
                    if (ShouldGenerateField(propertyType, detailsView)) {
                        string name = pd.Name;
                        bool isKey = ((IList)dataKeyNamesCaseInsensitive).Contains(name.ToLowerInvariant());
                        AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                        ((IStateManager)fieldProps).TrackViewState();

                        fieldProps.Name = name;
                        fieldProps.IsReadOnly = isKey;
                        fieldProps.Type = propertyType;
                        fieldProps.DataField = name;

                        AutoGeneratedField field = CreateAutoGeneratedFieldFromFieldProperties(fieldProps);
                        if (field != null) {
                            generatedFields.Add(field);
                            AutoGeneratedFieldProperties.Add(fieldProps);
                        }
                    }
                }
            }

            if ((generatedFields.Count == 0) && throwException) {
                // this handles the case where we got back something that either had no
                // properties, or all properties were not bindable.
                throw new InvalidOperationException(SR.GetString(SR.DetailsView_NoAutoGenFields, detailsView.ID));
            }

            return generatedFields;
        }
 protected virtual ICollection CreateAutoGeneratedRows(object dataItem)
 {
     if (dataItem == null)
     {
         return null;
     }
     ArrayList list = new ArrayList();
     PropertyDescriptorCollection properties = null;
     bool flag = true;
     Type type = null;
     this._autoGenFieldProps = new ArrayList();
     if (dataItem != null)
     {
         type = dataItem.GetType();
     }
     if ((dataItem != null) && (dataItem is ICustomTypeDescriptor))
     {
         properties = TypeDescriptor.GetProperties(dataItem);
     }
     else if (type != null)
     {
         if (this.IsBindableType(type))
         {
             AutoGeneratedFieldProperties fieldProperties = new AutoGeneratedFieldProperties();
             ((IStateManager) fieldProperties).TrackViewState();
             fieldProperties.Name = "Item";
             fieldProperties.DataField = BoundField.ThisExpression;
             fieldProperties.Type = type;
             AutoGeneratedField field = this.CreateAutoGeneratedRow(fieldProperties);
             if (field != null)
             {
                 list.Add(field);
                 this._autoGenFieldProps.Add(fieldProperties);
             }
         }
         else
         {
             properties = TypeDescriptor.GetProperties(type);
         }
     }
     if ((properties != null) && (properties.Count != 0))
     {
         string[] dataKeyNamesInternal = this.DataKeyNamesInternal;
         int length = dataKeyNamesInternal.Length;
         string[] strArray2 = new string[length];
         for (int i = 0; i < length; i++)
         {
             strArray2[i] = dataKeyNamesInternal[i].ToLowerInvariant();
         }
         foreach (PropertyDescriptor descriptor in properties)
         {
             Type propertyType = descriptor.PropertyType;
             if (this.IsBindableType(propertyType))
             {
                 string name = descriptor.Name;
                 bool flag2 = strArray2.Contains(name.ToLowerInvariant());
                 AutoGeneratedFieldProperties properties2 = new AutoGeneratedFieldProperties();
                 ((IStateManager) properties2).TrackViewState();
                 properties2.Name = name;
                 properties2.IsReadOnly = flag2;
                 properties2.Type = propertyType;
                 properties2.DataField = name;
                 AutoGeneratedField field2 = this.CreateAutoGeneratedRow(properties2);
                 if (field2 != null)
                 {
                     list.Add(field2);
                     this._autoGenFieldProps.Add(properties2);
                 }
             }
         }
     }
     if ((list.Count == 0) && flag)
     {
         throw new HttpException(System.Web.SR.GetString("DetailsView_NoAutoGenFields", new object[] { this.ID }));
     }
     return list;
 }
        private object GetFieldValue(AutoGeneratedFieldProperties property, object obj, ModelField field, System.Data.DataRow dataRow, out bool notFound)
        {
            notFound = false;
            if (field != null && field.ServerMapping.IsNotEmpty())
            {
                string[] mapping = field.ServerMapping.Split('.');

                if (mapping.Length > 1)
                {
                    for (int i = 0; i < mapping.Length; i++)
                    {
                        if (dataRow != null && dataRow.IsNull(mapping[i]))
                        {
                            return null;
                        }

                        PropertyInfo p = obj.GetType().GetProperty(mapping[i]);
                        if (p == null)
                        {
                            notFound = true;
                            return null;
                        }

                        obj = p.GetValue(obj, null);

                        if (obj == null)
                        {
                            return null;
                        }
                    }

                    return obj;
                }
            }

            if (dataRow == null)
            {
                var prop = TypeDescriptor.GetProperties(obj).Find(property.DataField, true);
                if (prop != null)
                {
                    return prop.GetValue(obj);
                }
            }
            else if(!dataRow.IsNull(property.DataField))
            {
                return dataRow[property.DataField];
            }
            
            notFound = true;
            return null;
        }        
Exemple #22
0
        protected virtual new AutoGeneratedField CreateAutoGeneratedRow(AutoGeneratedFieldProperties fieldProperties)
        {
            Contract.Requires(fieldProperties != null);

            return(default(AutoGeneratedField));
        }
			public AutoGeneratedField DoCreateAutoGeneratedRow (AutoGeneratedFieldProperties filedProperties)
			{
				return CreateAutoGeneratedRow (filedProperties);
			}
Exemple #24
0
		public void GridView_CreateAutoGeneratedColumn ()
		{
			PokerGridView g = new PokerGridView ();
			AutoGeneratedFieldProperties fp = new AutoGeneratedFieldProperties();
			fp.Name = "testfield";
			fp.Type = typeof (string);
			AutoGeneratedField gf = g.DoCreateAutoGeneratedColumn (fp);
			Assert.AreEqual (typeof (string), gf.DataType , "AutoGeneratedColumn#1");
			Assert.AreEqual ("testfield", gf.HeaderText, "AutoGeneratedColumn#2");
			Assert.AreEqual ("System.Web.UI.WebControls.AutoGeneratedField", gf.GetType ().ToString (), "AutoGeneratedColumn#3");
		}
 protected override void LoadViewState(object savedState)
 {
     if (savedState != null)
     {
         object[] objArray = (object[]) savedState;
         base.LoadViewState(objArray[0]);
         if (objArray[1] != null)
         {
             ((IStateManager) this.PagerStyle).LoadViewState(objArray[1]);
         }
         if (objArray[2] != null)
         {
             ((IStateManager) this.HeaderStyle).LoadViewState(objArray[2]);
         }
         if (objArray[3] != null)
         {
             ((IStateManager) this.FooterStyle).LoadViewState(objArray[3]);
         }
         if (objArray[4] != null)
         {
             ((IStateManager) this.RowStyle).LoadViewState(objArray[4]);
         }
         if (objArray[5] != null)
         {
             ((IStateManager) this.AlternatingRowStyle).LoadViewState(objArray[5]);
         }
         if (objArray[6] != null)
         {
             ((IStateManager) this.CommandRowStyle).LoadViewState(objArray[6]);
         }
         if (objArray[7] != null)
         {
             ((IStateManager) this.EditRowStyle).LoadViewState(objArray[7]);
         }
         if (objArray[8] != null)
         {
             ((IStateManager) this.InsertRowStyle).LoadViewState(objArray[8]);
         }
         if (objArray[9] != null)
         {
             ((IStateManager) this.FieldHeaderStyle).LoadViewState(objArray[9]);
         }
         if (objArray[10] != null)
         {
             ((IStateManager) this.Fields).LoadViewState(objArray[10]);
         }
         if (objArray[11] != null)
         {
             OrderedDictionaryStateHelper.LoadViewState((OrderedDictionary) this.BoundFieldValues, (ArrayList) objArray[11]);
         }
         if (objArray[12] != null)
         {
             ((IStateManager) this.PagerSettings).LoadViewState(objArray[12]);
         }
         if (objArray[13] != null)
         {
             ((IStateManager) base.ControlStyle).LoadViewState(objArray[13]);
         }
         if (objArray[14] != null)
         {
             object[] objArray2 = (object[]) objArray[14];
             int length = objArray2.Length;
             this._autoGenFieldProps = new ArrayList();
             for (int i = 0; i < length; i++)
             {
                 AutoGeneratedFieldProperties properties = new AutoGeneratedFieldProperties();
                 ((IStateManager) properties).TrackViewState();
                 ((IStateManager) properties).LoadViewState(objArray2[i]);
                 this._autoGenFieldProps.Add(properties);
             }
         }
     }
     else
     {
         base.LoadViewState(null);
     }
 }
		AutoGeneratedFieldProperties[] CreateAutoFieldProperties (PagedDataSource source)
		{
			if(source == null) return null;
			
			PropertyDescriptorCollection props = source.GetItemProperties (new PropertyDescriptor[0]);
			Type prop_type;
			
			ArrayList retVal = new ArrayList();
			
			if (props == null)
			{
				object fitem = null;
				prop_type = null;
				PropertyInfo prop_item =  source.DataSource.GetType().GetProperty("Item",
												  BindingFlags.Instance | BindingFlags.Static |
												  BindingFlags.Public, null, null,
												  new Type[] { typeof(int) }, null);
				
				if (prop_item != null) {
					prop_type = prop_item.PropertyType;
				}
				
				if (prop_type == null || prop_type == typeof(object)) {
					IEnumerator en = source.GetEnumerator();
					if (en != null && en.MoveNext ()) {
						fitem = en.Current;
						_dataEnumerator = en;
					}
					if (fitem != null)
						prop_type = fitem.GetType();
				}
				
				if (fitem != null && fitem is ICustomTypeDescriptor) {
					props = TypeDescriptor.GetProperties(fitem);
				} else if (prop_type != null) {
					if (IsBindableType (prop_type)) {
						AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
						((IStateManager)field).TrackViewState();
						field.Name = "Item";
						field.DataField = BoundField.ThisExpression;
						field.Type = prop_type;
						retVal.Add (field);
					} else {
						props = TypeDescriptor.GetProperties (prop_type);
					}
				}
			}
			
			if (props != null && props.Count > 0)
			{
				foreach (PropertyDescriptor current in props) {
					if (IsBindableType (current.PropertyType)) {
						AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
						((IStateManager)field).TrackViewState();
						field.Name = current.Name;
						field.DataField = current.Name;
						for (int i = 0; i < DataKeyNames.Length; i++) {
							if (string.Compare (DataKeyNames [i], current.Name, StringComparison.InvariantCultureIgnoreCase) == 0) {
								field.IsReadOnly = true;
								break;
							}
						}
						field.Type = current.PropertyType;
						retVal.Add (field);
					}
				}
			}

			if (retVal.Count > 0)
				return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
			else
				return new AutoGeneratedFieldProperties [0];
		}
        public override List <AutoGeneratedField> CreateAutoGeneratedFields(object dataObject, Control control)
        {
            if (!(control is GridView))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidDefaultAutoFieldGenerator, GetType().FullName, typeof(GridView).FullName));
            }

            Debug.Assert(dataObject == null || dataObject is PagedDataSource);

            PagedDataSource dataSource = dataObject as PagedDataSource;
            GridView        gridView   = control as GridView;

            if (dataSource == null)
            {
                // note that we're not throwing an exception in this case, and the calling
                // code should be able to handle a null arraylist being returned
                return(null);
            }

            List <AutoGeneratedField>    generatedFields = new List <AutoGeneratedField>();
            PropertyDescriptorCollection propDescs       = null;
            bool throwException = true;

            // try ITypedList first
            // A PagedDataSource implements this, but returns null, if the underlying data source
            // does not implement it.
            propDescs = ((ITypedList)dataSource).GetItemProperties(new PropertyDescriptor[0]);

            if (propDescs == null)
            {
                Type   sampleItemType = null;
                object sampleItem     = null;

                IEnumerable realDataSource = dataSource.DataSource;
                Debug.Assert(realDataSource != null, "Must have a real data source when calling CreateAutoGeneratedColumns");

                Type dataSourceType = realDataSource.GetType();

                // try for a typed Row property, which should be present on strongly typed collections
                PropertyInfo itemProp = dataSourceType.GetProperty("Item", BindingFlags.Public | BindingFlags.Instance, null, null, new Type[] { typeof(int) }, null);
                if (itemProp != null)
                {
                    sampleItemType = itemProp.PropertyType;
                }

                if ((sampleItemType == null) || (sampleItemType == typeof(object)))
                {
                    // last resort... try to get ahold of the first item by beginning the
                    // enumeration

                    IEnumerator e = dataSource.GetEnumerator();

                    if (e.MoveNext())
                    {
                        sampleItem = e.Current;
                    }
                    else
                    {
                        // we don't want to throw an exception if we're bound to an IEnumerable
                        // data source with no records... we'll simply bail and not show any data
                        throwException = false;
                    }
                    if (sampleItem != null)
                    {
                        sampleItemType = sampleItem.GetType();
                    }

                    // We must store the enumerator regardless of whether we got back an item from it
                    // because we cannot start the enumeration again, in the case of a DataReader.
                    // Code in CreateChildControls must deal appropriately for the case where
                    // there is a stored enumerator, but a null object as the first item.
                    gridView.StoreEnumerator(e, sampleItem);
                }

                if ((sampleItem != null) && (sampleItem is ICustomTypeDescriptor))
                {
                    // Get the custom properties of the object
                    propDescs = TypeDescriptor.GetProperties(sampleItem);
                }
                else if (sampleItemType != null)
                {
                    // directly bindable types: strings, ints etc. get treated specially, since we
                    // don't care about their properties, but rather we care about them directly
                    if (ShouldGenerateField(sampleItemType, gridView))
                    {
                        AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                        ((IStateManager)fieldProps).TrackViewState();

                        fieldProps.Type      = sampleItemType;
                        fieldProps.Name      = "Item";
                        fieldProps.DataField = AutoGeneratedField.ThisExpression;

                        AutoGeneratedField field = CreateAutoGeneratedFieldFromFieldProperties(fieldProps);
                        if (field != null)
                        {
                            generatedFields.Add(field);

                            AutoGeneratedFieldProperties.Add(fieldProps);
                        }
                    }
                    else
                    {
                        // complex type... we get its properties
                        propDescs = TypeDescriptor.GetProperties(sampleItemType);
                    }
                }
            }
            else
            {
                if (propDescs.Count == 0)
                {
                    // we don't want to throw an exception if we're bound to an ITypedList
                    // data source with no records... we'll simply bail and not show any data
                    throwException = false;
                }
            }

            if ((propDescs != null) && (propDescs.Count != 0))
            {
                string[] dataKeyNames   = gridView.DataKeyNames;
                int      keyNamesLength = dataKeyNames.Length;
                string[] dataKeyNamesCaseInsensitive = new string[keyNamesLength];
                for (int i = 0; i < keyNamesLength; i++)
                {
                    dataKeyNamesCaseInsensitive[i] = dataKeyNames[i].ToLowerInvariant();
                }
                foreach (PropertyDescriptor pd in propDescs)
                {
                    Type propertyType = pd.PropertyType;
                    if (ShouldGenerateField(propertyType, gridView))
                    {
                        string name  = pd.Name;
                        bool   isKey = ((IList)dataKeyNamesCaseInsensitive).Contains(name.ToLowerInvariant());
                        AutoGeneratedFieldProperties fieldProps = new AutoGeneratedFieldProperties();
                        ((IStateManager)fieldProps).TrackViewState();
                        fieldProps.Name       = name;
                        fieldProps.IsReadOnly = isKey;
                        fieldProps.Type       = propertyType;
                        fieldProps.DataField  = name;

                        AutoGeneratedField field = CreateAutoGeneratedFieldFromFieldProperties(fieldProps);
                        if (field != null)
                        {
                            generatedFields.Add(field);
                            AutoGeneratedFieldProperties.Add(fieldProps);
                        }
                    }
                }
            }

            if ((generatedFields.Count == 0) && throwException)
            {
                // this handles the case where we got back something that either had no
                // properties, or all properties were not bindable.
                throw new InvalidOperationException(SR.GetString(SR.GridView_NoAutoGenFields, gridView.ID));
            }

            return(generatedFields);
        }
        private void BindRecord(AutoGeneratedFieldProperties[] autoFieldProperties, StringBuilder sb, object obj)
        {
            sb.Append("{");
            System.Data.DataRow dataRow = obj as System.Data.DataRow;

            foreach (AutoGeneratedFieldProperties property in autoFieldProperties)
            {
                FieldInModel field = this.IsInModel(property.DataField);

                if (this.IgnoreExtraFields && !field.InModel)
                {
                    continue;
                }

                if (field.Fields != null && field.Fields.Count > 0)
                {
                    foreach (ModelField recordField in field.Fields)
                    {
                        bool notFound;
                        object value = this.GetFieldValue(property, obj, recordField, dataRow, out notFound);
                        if (notFound)
                        {
                            continue;
                        }

                        if (value != null && value.GetType().IsEnum && recordField.Type == ModelFieldType.Int)
                        {
                            value = Convert.ChangeType(value, ((Enum)value).GetTypeCode());
                        }
                        sb.AppendFormat("{0}:{1},", JSON.Serialize(string.IsNullOrEmpty(recordField.Mapping) ? recordField.Name : recordField.Mapping), JSON.Serialize(value, recordField.Type == ModelFieldType.Date && recordField.RenderMilliseconds ? JSON.DateMsConvertersInternal : JSON.ConvertersInternal));
                    }
                }
                else
                {
                    if (dataRow == null)
                    {
                        var prop = TypeDescriptor.GetProperties(obj).Find(property.DataField, true);
                        if (prop != null)
                        {
                            sb.AppendFormat("{0}:{1},", JSON.Serialize(property.DataField), JSON.Serialize(prop.GetValue(obj)));
                        }
                    }
                    else if(!dataRow.IsNull(property.DataField))
                    {
                        sb.AppendFormat("{0}:{1},", JSON.Serialize(property.DataField), JSON.Serialize(dataRow[property.DataField]));
                    }
                }
            }

            RemoveLastComma(sb);
            sb.Append("},");
        }
 protected virtual new AutoGeneratedField CreateAutoGeneratedColumn(AutoGeneratedFieldProperties fieldProperties)
 {
   return default(AutoGeneratedField);
 }
        AutoGeneratedFieldProperties[] CreateAutoFieldProperties(IEnumerable source, IEnumerator en)
        {
            this.DSData = null;
            this.SetJsonForBinding("");

            if (source == null)
            {
                return null;
            }

            List<AutoGeneratedFieldProperties> retVal = new List<AutoGeneratedFieldProperties>();

            if (source is DataTable)
            {
                var dt = (DataTable)source;
                foreach (DataColumn c in dt.Columns)
                {
                    if (this.IsBindableType(c.DataType) || this.IsComplexField(c.ColumnName))
                    {
                        AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties();
                        field.Name = c.ColumnName;
                        field.DataField = c.ColumnName;
                        retVal.Add(field);
                    }
                }

                return retVal.Count > 0 ? retVal.ToArray() : null;
            }

            ITypedList typed = source as ITypedList;
            PropertyDescriptorCollection props = typed == null ? null : typed.GetItemProperties(new PropertyDescriptor[0]);

            Type prop_type;

            if (props == null)
            {
                object fitem = null;
                prop_type = null;
                PropertyInfo prop_item = source.GetType().GetProperty("Item",
                                                  BindingFlags.Instance | BindingFlags.Static |
                                                  BindingFlags.Public, null, null,
                                                  new Type[] { typeof(int) }, null);

                if (prop_item != null)
                {
                    prop_type = prop_item.PropertyType;

                    if (prop_type.IsInterface)
                    {
                        prop_type = null;
                    }
                }

                if (prop_type == null || prop_type == typeof(object))
                {
                    if (en.MoveNext())
                    {
                        fitem = en.Current;
                        this.firstRecord = fitem;
                    }

                    if (fitem != null)
                    {
                        prop_type = fitem.GetType();
                    }
                }

                if (fitem != null && fitem is ICustomTypeDescriptor)
                {
                    props = TypeDescriptor.GetProperties(fitem);
                }
                else if (prop_type != null)
                {
                    if (IsBindableType(prop_type))
                    {
                        AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties();
                        ((IStateManager)field).TrackViewState();
                        field.Name = "Item";
                        field.DataField = BoundField.ThisExpression;
                        field.Type = prop_type;
                        retVal.Add(field);
                    }
                    else
                    {
                        if (typeof(IEnumerable).IsAssignableFrom(prop_type))
                        {
                            this.DSData = source;
                            if (this.Reader.Primary == null)
                            {
                                this.Reader.Add(new ArrayReader());
                            }
                            else if (!(this.Reader.Primary is ArrayReader)){
                                throw new Exception(ServiceMessages.DEFINE_ARRAY_READER);
                            }
                            return null;
                        }
                        else
                        {
                            props = TypeDescriptor.GetProperties(prop_type);
                        }
                    }
                }
            }

            if (props != null && props.Count > 0)
            {
                foreach (PropertyDescriptor current in props)
                {
                    if (this.IsBindableType(current.PropertyType) || this.IsComplexField(current.Name))
                    {
                        AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties();
                        field.Name = current.Name;
                        field.DataField = current.Name;
                        retVal.Add(field);
                    }
                }
            }

            return retVal.Count > 0 ? retVal.ToArray() : null;
        }
    protected virtual new AutoGeneratedField CreateAutoGeneratedColumn (AutoGeneratedFieldProperties fieldProperties)
    {
      Contract.Requires (fieldProperties != null);

      return default(AutoGeneratedField);
    }
		public void DetailsView_CreateAutoGenerateRow ()
		{
			PokerDetailsView dv = new PokerDetailsView ();			
			AutoGeneratedFieldProperties prop = new AutoGeneratedFieldProperties ();			
			prop.Name = "FieldItem";			
			prop.Type = typeof(String);
			AutoGeneratedField field = dv.DoCreateAutoGeneratedRow (prop);
			Assert.AreEqual (typeof (string), field.DataType, "FieldDataType");
			Assert.AreEqual ("FieldItem", field.HeaderText, "FieldHeaderText");
			Assert.AreEqual ("FieldItem",field.SortExpression ,"FieldSortExpretion");
			Assert.AreEqual (typeof(AutoGeneratedField), field.GetType (), "AutoGeneratedFieldType"); 

		}
 private ICollection CreateAutoGeneratedColumns(PagedDataSource dataSource)
 {
     if (dataSource == null)
     {
         return null;
     }
     ArrayList list = new ArrayList();
     this._autoGenFieldProps = new ArrayList();
     PropertyDescriptorCollection itemProperties = null;
     bool flag = true;
     itemProperties = dataSource.GetItemProperties(new PropertyDescriptor[0]);
     if (itemProperties == null)
     {
         Type propertyType = null;
         object firstDataRow = null;
         PropertyInfo info = dataSource.DataSource.GetType().GetProperty("Item", BindingFlags.Public | BindingFlags.Instance, null, null, new Type[] { typeof(int) }, null);
         if (info != null)
         {
             propertyType = info.PropertyType;
         }
         if ((propertyType == null) || (propertyType == typeof(object)))
         {
             IEnumerator enumerator = dataSource.GetEnumerator();
             if (enumerator.MoveNext())
             {
                 firstDataRow = enumerator.Current;
             }
             else
             {
                 flag = false;
             }
             if (firstDataRow != null)
             {
                 propertyType = firstDataRow.GetType();
             }
             this.StoreEnumerator(enumerator, firstDataRow);
         }
         if ((firstDataRow != null) && (firstDataRow is ICustomTypeDescriptor))
         {
             itemProperties = TypeDescriptor.GetProperties(firstDataRow);
         }
         else if (propertyType != null)
         {
             if (this.IsBindableType(propertyType))
             {
                 AutoGeneratedFieldProperties fieldProperties = new AutoGeneratedFieldProperties();
                 ((IStateManager) fieldProperties).TrackViewState();
                 fieldProperties.Type = propertyType;
                 fieldProperties.Name = "Item";
                 fieldProperties.DataField = BoundField.ThisExpression;
                 AutoGeneratedField field = this.CreateAutoGeneratedColumn(fieldProperties);
                 if (field != null)
                 {
                     list.Add(field);
                     this._autoGenFieldProps.Add(fieldProperties);
                 }
             }
             else
             {
                 itemProperties = TypeDescriptor.GetProperties(propertyType);
             }
         }
     }
     else if (itemProperties.Count == 0)
     {
         flag = false;
     }
     if ((itemProperties != null) && (itemProperties.Count != 0))
     {
         string[] dataKeyNames = this.DataKeyNames;
         int length = dataKeyNames.Length;
         string[] strArray2 = new string[length];
         for (int i = 0; i < length; i++)
         {
             strArray2[i] = dataKeyNames[i].ToLowerInvariant();
         }
         foreach (PropertyDescriptor descriptor in itemProperties)
         {
             Type type = descriptor.PropertyType;
             if (this.IsBindableType(type))
             {
                 string name = descriptor.Name;
                 bool flag2 = strArray2.Contains(name.ToLowerInvariant());
                 AutoGeneratedFieldProperties properties2 = new AutoGeneratedFieldProperties();
                 ((IStateManager) properties2).TrackViewState();
                 properties2.Name = name;
                 properties2.IsReadOnly = flag2;
                 properties2.Type = type;
                 properties2.DataField = name;
                 AutoGeneratedField field2 = this.CreateAutoGeneratedColumn(properties2);
                 if (field2 != null)
                 {
                     list.Add(field2);
                     this._autoGenFieldProps.Add(properties2);
                 }
             }
         }
     }
     if ((list.Count == 0) && flag)
     {
         throw new HttpException(System.Web.SR.GetString("GridView_NoAutoGenFields", new object[] { this.ID }));
     }
     return list;
 }