private void ReadChild(ExcelRangeBase cell, ref int row, int level) { do { bool isValueTag = !string.IsNullOrEmpty(cell.Offset(row, 6).Text); int depth; int.TryParse(cell.Offset(row, 1).Text, out depth); if (level != 0 && depth <= level) { break; } string tagName = cell.Offset(row, 2 + depth).Text; row += 1; if (isValueTag) { Console.WriteLine("{2}<{0}>{1}</{0}>", tagName, "ValueTag", new string(' ', depth * 4)); } else { Console.WriteLine("{1}<{0}>", tagName, new string(' ', depth * 4)); ReadChild(cell, ref row, depth); Console.WriteLine("{1}</{0}>", tagName, new string(' ', depth * 4)); } } while (!string.IsNullOrEmpty(cell.Offset(row, 0).Text)); }
/// <summary> /// 指定したセルを基準としたプロパティ情報を生成する。 /// </summary> /// <param name="cell"></param> /// <returns></returns> private static PropertyInfo CreatePropertyInfo(ExcelRangeBase cell) { string typeName = cell.Offset(0, 2).ValueString(); string defaultValue = string.Empty; string elementCount = cell.Offset(0, 3).ValueString(); int count; // 配列やコレクションの場合、メンバで初期化する必要がある。 // それ以外の場合は、初期化は実施しない。 // ここでは、デフォルト値の設定有無の判定と、型名の変換を行う。 if (int.TryParse(elementCount, out count) == true) { if (count > 1) { // 配列で定義されている。 defaultValue = string.Format("new {0}[{1}]", typeName, count); typeName = string.Format("{0}[]", typeName); } } else if (elementCount == "*") { // コレクションで定義されている。 typeName = string.Format("ObservableCollection<{0}>", typeName); defaultValue = string.Format("new {0}()", typeName); } var result = new PropertyInfo(cell.Offset(0, 0).ValueString() , typeName , cell.Offset(0, 4).ValueString() , cell.Offset(0, 1).ValueString() , cell.Offset(0, 5).ValueString()) { DefaultValue = defaultValue, }; result.CheckAttributes.AddRange(CreateCheckAttributes(cell.Offset(0, 6))); return result; }
/// <summary> /// 入力チェック属性情報を生成する。 /// </summary> /// <param name="cell"></param> /// <returns></returns> private static IEnumerable<CheckAttributeBase> CreateCheckAttributes(ExcelRangeBase cell) { var results = new List<CheckAttributeBase>(); string isCheckRequired = cell.Offset(0, 0).ValueString(); if (string.IsNullOrEmpty(isCheckRequired) == false) { // 未入力チェック実施 results.Add(new CheckRequiredAttribute()); } string typeName = cell.Offset(0, -4).ValueString(); string minimum = cell.Offset(0, 1).ValueString(); string maximum = cell.Offset(0, 2).ValueString(); if (string.IsNullOrEmpty(minimum) == false && string.IsNullOrEmpty(maximum) == false) { // 範囲入力チェック実施 results.Add(new CheckRangeAttribute(typeName, minimum, maximum)); } string minLength = cell.Offset(0, 3).ValueString(); string maxLength = cell.Offset(0, 4).ValueString(); if (string.IsNullOrEmpty(minLength) == false && string.IsNullOrEmpty(maxLength) == false) { // 文字数制限チェック実施 results.Add(new CheckStringLengthAttribute(int.Parse(minLength), int.Parse(maxLength))); } return results; }
/// <summary> /// 指定したセルを基準とした定数情報を生成する。 /// </summary> /// <param name="cell"></param> /// <returns></returns> private static DefinedInfo CreateDefinedInfo(ExcelRangeBase cell) { var result = new DefinedInfo(cell.Offset(0, 0).ValueString() , cell.Offset(1, 0).ValueString() , cell.Offset(3, 0).ValueString() , cell.Offset(2, 0).ValueString()); return result; }