System.Web.UI.WebControls.GridView.CreateAutoFieldProperties C# (CSharp) Method

CreateAutoFieldProperties() private method

private CreateAutoFieldProperties ( PagedDataSource source ) : AutoGeneratedFieldProperties[]
source PagedDataSource
return AutoGeneratedFieldProperties[]
		AutoGeneratedFieldProperties[] CreateAutoFieldProperties (PagedDataSource source)
		{
			if(source == null) return null;
			
			PropertyDescriptorCollection props = source.GetItemProperties (new PropertyDescriptor[0]);
			Type prop_type = null;
			
			var retVal = new List <AutoGeneratedFieldProperties> ();
			
			if (props == null)
			{
				object fitem = 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) && (prop_type == null || current.ComponentType == prop_type)) {
						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 retVal.ToArray ();
			else
				return new AutoGeneratedFieldProperties [0];
		}