public string GetTableDefinitionCode( ITableMetaInfo tinfo, bool withNamespace = true) { string code = GetStronglyTypedTableDefinitionCode(tinfo); if (withNamespace) { code = WrapTableDefinitionsCodeInOuterNamespaceAndUsings(new string[] { code }); } return(code); }
public static string GetTableMetaInfoCodeStatic(ITableMetaInfo tmi) { string result = $@"new {nameof(TableMetaInfo)}() {{ {nameof(tmi.TableName)} = ""{tmi.TableName}"", {nameof(tmi.TableSchema)} = ""{tmi.TableSchema}"", {nameof(tmi.TableNameFull)} = ""{tmi.TableNameFull}"", {nameof(tmi.TypeName)} = ""{tmi.TypeName}"", {nameof(tmi.TypeNameFull)} = ""{tmi.TypeNameFull}"", {nameof(tmi.TableColumnNames)} = _TableColumnNames.ToArray(), {nameof(tmi.EntityPropertyNames)} = _EntityPropertyNames.ToArray() }};" ; return(result); }
public static string GetTableMetaInfoCode(ITableMetaInfo tmi) => GetTableMetaInfoCodeStatic(tmi);
public string GetStronglyTypedTableDefinitionCode(ITableMetaInfo tmi) { var info = tmi; string[] tblCols = tmi.TableColumnNames; string[] entCols = tmi.EntityPropertyNames; if (tmi.TableName.IsNulle() || tblCols.IsNulle() || tblCols.Length != entCols.Length) { throw new ArgumentException(); } string finalInterfaceExtraVal = null; if (ExtraInterfacesPerTD.NotNulle()) { if (ExtraInterfacesPerTD.TryGetValueAny(out finalInterfaceExtraVal, tmi.TypeName, tmi.TypeNameFull, tmi.TableName)) { finalInterfaceExtraVal += ", "; } } var sb = new StringBuilder(); // --- Class Definition --- sb.AppendFormat( @" #region {0}TD public class {0}TD : {1}ITableDefinition {{ ", tmi.TypeName, finalInterfaceExtraVal); // using EntityName instead of TableName // --- Static Column Values --- sb.Append(" #region --- CONST PROPERTY NAMES ---\r\n\r\n"); for (int i = 0; i < tblCols.Length; i++) { sb.AppendFormat(" public const string _{0} = \"{1}\";\r\n", entCols[i], tblCols[i]); } sb.Append("\r\n #endregion\r\n\r\n"); // --- Add _TableColumnNames --- string columnsJoined = entCols.JoinToString(", _"); // --- Column Properties --- sb.Append(" #region --- Strongly Typed Instance Table Column Names ---\r\n\r\n"); for (int i = 0; i < tblCols.Length; i++) { sb.AppendFormat(" public string {0} => _{0};\r\n", entCols[i]); } sb.Append("\r\n #endregion\r\n\r\n"); // =-=-= ITableDefinition Properties =-=-= sb.Append(" #region =-=-= STATIC FIELDS =-=-=\r\n\r\n") .AppendFormat(" public static readonly string[] _TableColumnNames = {{ _{0} }};\r\n", columnsJoined) .AppendLine() .AppendFormat(" public static readonly string[] _EntityPropertyNames = {{ \"{0}\" }};\r\n", entCols.JoinToString("\", \"")) .AppendLine(); string tableMetaInfoCode = tmi.GetTableMetaInfoCode(); sb.AppendMany( " public static TableMetaInfo _TableMeta = ", tableMetaInfoCode); sb.AppendLine() .AppendLine() .AppendLine($" public string[] {nameof(tmi.TableColumnNames)} => _TableColumnNames;") .AppendLine($" public string[] {nameof(tmi.EntityPropertyNames)} => _EntityPropertyNames;") .AppendLine(" public TableMetaInfo TableMeta { get => _TableMeta; set { _TableMeta = value; } }") .AppendLine(); sb.Append(" #endregion\r\n\r\n") .Append( @" } #endregion" ); string result = sb.ToString(); return(result); }
public static string GetTableDefinitionCode( this ITableMetaInfo tinfo, TDCodeGenerator codeGenOps = null, bool withNamespace = true) => codeGenOps.E().GetTableDefinitionCode(tinfo, withNamespace);
public static string GetTableMetaInfoCode( this ITableMetaInfo tmi) => TDCodeGenerator.GetTableMetaInfoCodeStatic(tmi);