예제 #1
0
        /// <summary>
        /// Converts the block into an object.
        /// </summary>
        /// <param name="type">The type of object to convert to.</param>
        /// <returns>The new object.</returns>
        public object ConvertTo(Type type)
        {
            if (type == null)
            {
                return(null);
            }

            object theObject = Activator.CreateInstance(type);

            for (int i = 0; i < this.Size; i++)
            {
                string      label  = this.GetLabel(i);
                ValueSetter setter = ValueSetter.GetValueSetter(theObject, label);

                if (setter.CanSetValue())
                {
                    setter.SetFormattedValue(this.GetValue(i));
                }
                else
                {
                    throw new Exception(string.Format("Could not set {0} on type {1}.", label, type.FullName));
                }
            }

            return(theObject);
        }
예제 #2
0
파일: Grid.cs 프로젝트: gzlive/behaven
        private object CreateItem(Type itemType, int rowIndex)
        {
            object item = Activator.CreateInstance(itemType);

            for (int columnIndex = 0; columnIndex < this.ColumnCount; columnIndex++)
            {
                string      header = this.GetHeader(columnIndex);
                ValueSetter setter = ValueSetter.GetValueSetter(item, header);

                if (setter.CanSetValue())
                {
                    setter.SetFormattedValue(this.GetValue(rowIndex, columnIndex));
                }
                else
                {
                    throw new Exception(string.Format("Could not set {0} on type {1}.", header, itemType.FullName));
                }
            }

            return(item);
        }