Beispiel #1
0
        /// <summary>
        /// Generates the VO fields string.
        /// </summary>
        /// <param name="headInfos">The MetadataHeadInfo list.</param>
        /// <returns>The VO fields string.</returns>
        private static string GenerateVOFieldsString(List <MetadataHeadInfo> headInfos)
        {
            string fieldsString = string.Empty;

            if (headInfos != null && headInfos.Count > 0)
            {
                for (int i = 0, length = headInfos.Count; i < length; ++i)
                {
                    MetadataHeadInfo headInfo = headInfos[i];
                    fieldsString += string.Format("\t\t/// <summary>{0}\t\t/// {1}{2}\t\t/// </summary>{3}\t\tpublic {4} {5};",
                                                  Environment.newline,
                                                  headInfo.comment,
                                                  Environment.newline,
                                                  Environment.newline,
                                                  headInfo.parsedType,
                                                  headInfo.key);

                    if (i < length - 1)
                    {
                        fieldsString += Environment.newline + Environment.newline;
                    }
                }
            }

            return(fieldsString);
        }
Beispiel #2
0
        /// <summary>
        /// Generates the data list.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="headInfos">The MetadataHeadInfo list.</param>
        /// <returns></returns>
        private static List <ConfigMetadata> GenerateDataList(DataTable table, string className, List <MetadataHeadInfo> headInfos)
        {
            List <ConfigMetadata> dataList = new List <ConfigMetadata>();

            int rowCount = table.Rows.Count;

            for (int i = DefaultDataStartRowIndex; i < rowCount; ++i)
            {
                ConfigMetadata metadata = (ConfigMetadata)ReflectionUtility.CreateClassInstance(GetMetadataFullName(className));

                for (int j = 0, keysCount = headInfos.Count; j < keysCount; ++j)
                {
                    string           cellValue = table.Rows[i][j].ToString().Trim();
                    MetadataHeadInfo headInfo  = headInfos[j];

                    // The value of primary key can not be null or empty string.
                    if (headInfo.key == primaryKey && string.IsNullOrEmpty(cellValue))
                    {
                        continue;
                    }

                    ITypeParser parser = GetTypeParser(headInfo.type);

                    if (parser != null && !string.IsNullOrEmpty(cellValue))
                    {
                        object value = parser.ParseValue(cellValue);
                        ReflectionUtility.SetObjectFieldValue(metadata, headInfo.key, value);
                    }
                }

                dataList.Add(metadata);
            }

            return(dataList);
        }
Beispiel #3
0
        /// <summary>
        /// Generates the metadata head informations.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <returns></returns>
        private static List <MetadataHeadInfo> GenerateMetadataHeadInfos(DataTable table)
        {
            DataColumnCollection columns = table.Columns;
            DataRowCollection    rows    = table.Rows;
            int columnCount = columns.Count;
            List <MetadataHeadInfo> headInfos = new List <MetadataHeadInfo>();

            for (int i = 0; i < columnCount; i++)
            {
                string key        = rows[keyRowIndex][i].ToString().Trim();
                string typeString = rows[DefaultTypeRowIndex][i].ToString().Trim();
                string comment    = rows[DefaultCommentsRowIndex][i].ToString().Trim();

                // Format key.
                if (metadataKeyFormatter != null)
                {
                    key = metadataKeyFormatter(key);
                }

                // If key is not empty string, type is not empty string, and type is supported,  then add item to list.
                if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(typeString) && IsSupportedDataType(typeString))
                {
                    ITypeParser      typeParser = GetTypeParser(typeString);
                    MetadataHeadInfo headInfo   = new MetadataHeadInfo();
                    headInfo.key        = key;
                    headInfo.type       = typeString;
                    headInfo.parsedType = typeParser.ParseType(typeString);
                    headInfo.comment    = CommentFormatter(comment);
                    headInfos.Add(headInfo);
                }
            }

            return(headInfos);
        }