Skip to content

Commit

Permalink
Improve code style, add different overloads to TableSectionData methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyNefyodov committed Apr 30, 2024
1 parent 5b33826 commit 335e590
Showing 1 changed file with 109 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param
nameof(TableSectionData.CanInsertRow) => ResolveCanInsertRow(),
nameof(TableSectionData.CanRemoveColumn) => ResolveCanRemoveColumn(),
nameof(TableSectionData.CanRemoveRow) => ResolveCanRemoveRow(),
nameof(TableSectionData.GetCellCalculatedValue) => ResolveCellCalculatedValue(),
nameof(TableSectionData.GetCellCategoryId) => ResolveCellCategoryId(),
nameof(TableSectionData.GetCellCombinedParameters) => ResolveCellCombinedParameters(),
nameof(TableSectionData.GetCellFormatOptions) => ResolveCellFormatOptions(),
nameof(TableSectionData.GetCellParamId) => ResolveCellParamId(),
nameof(TableSectionData.GetCellCalculatedValue) when parameters.Length == 1 => ResolveCellCalculatedValueForColumns(),
nameof(TableSectionData.GetCellCalculatedValue) when parameters.Length == 2 => ResolveCellCalculatedValueForTable(),
nameof(TableSectionData.GetCellCategoryId) when parameters.Length == 1 => ResolveCellCategoryIdForColumns(),
nameof(TableSectionData.GetCellCategoryId) when parameters.Length == 2 => ResolveCellCategoryIdForTable(),
nameof(TableSectionData.GetCellCombinedParameters) when parameters.Length == 1 => ResolveCellCombinedParametersForColumns(),
nameof(TableSectionData.GetCellCombinedParameters) when parameters.Length == 2 => ResolveCellCombinedParametersForTable(),
nameof(TableSectionData.GetCellFormatOptions) when parameters.Length == 2 => ResolveCellFormatOptionsForColumns(),
nameof(TableSectionData.GetCellFormatOptions) when parameters.Length == 3 => ResolveCellFormatOptionsForTable(),
nameof(TableSectionData.GetCellParamId) when parameters.Length == 1 => ResolveCellParamIdForColumns(),
nameof(TableSectionData.GetCellParamId) when parameters.Length == 2 => ResolveCellParamIdForTable(),
nameof(TableSectionData.GetCellSpec) => ResolveCellSpec(),
nameof(TableSectionData.GetCellText) => ResolveCellText(),
nameof(TableSectionData.GetCellType) => ResolveCellType(),
nameof(TableSectionData.GetCellType) when parameters.Length == 1 => ResolveCellTypeForColumns(),
nameof(TableSectionData.GetCellType) when parameters.Length == 2 => ResolveCellTypeForTable(),
nameof(TableSectionData.GetRowHeight) => ResolveRowHeight(),
nameof(TableSectionData.RefreshData) => ResolveSet.Append(false, "Overridden"),
_ => null
Expand All @@ -69,8 +75,8 @@ ResolveSet ResolveOverrideCellStyle()
ResolveSet ResolveCanInsertColumn()
{
var count = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(count + 2);
for (var i = 0; i < count + 2; i++)
var resolveSummary = new ResolveSet(count);
for (var i = 0; i < count; i++)
{
var result = tableSectionData.CanInsertColumn(i);
resolveSummary.AppendVariant(result, $"{i}: {result}");
Expand All @@ -82,8 +88,8 @@ ResolveSet ResolveCanInsertColumn()
ResolveSet ResolveCanInsertRow()
{
var count = tableSectionData.NumberOfRows;
var resolveSummary = new ResolveSet(count + 2);
for (var i = 0; i < count + 2; i++)
var resolveSummary = new ResolveSet(count);
for (var i = 0; i < count; i++)
{
var result = tableSectionData.CanInsertRow(i);
resolveSummary.AppendVariant(result, $"{i}: {result}");
Expand Down Expand Up @@ -118,7 +124,20 @@ ResolveSet ResolveCanRemoveRow()
return resolveSummary;
}

ResolveSet ResolveCellCalculatedValue()
ResolveSet ResolveCellCalculatedValueForColumns()
{
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(columnsNumber);
for (var j = 0; j < columnsNumber; j++)
{
var result = tableSectionData.GetCellCalculatedValue(j);
resolveSummary.AppendVariant(result, $"Column {j}: {result}");
}

return resolveSummary;
}

ResolveSet ResolveCellCalculatedValueForTable()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
Expand All @@ -135,23 +154,33 @@ ResolveSet ResolveCellCalculatedValue()
return resolveSummary;
}

ResolveSet ResolveCellCategoryId()
ResolveSet ResolveCellCategoryIdForColumns()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(rowsNumber * columnsNumber);
var resolveSummary = new ResolveSet(columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
var columnResult = tableSectionData.GetCellCategoryId(i);
if (columnResult != ElementId.InvalidElementId)
var result = tableSectionData.GetCellCategoryId(i);
if (result != ElementId.InvalidElementId)
{
var category = Category.GetCategory(context, columnResult);
var category = Category.GetCategory(context, result);
if (category is not null)
{
resolveSummary.AppendVariant(columnResult, $"Column {i}: {category.Name}");
resolveSummary.AppendVariant(result, $"Column {i}: {category.Name}");
}
}

}

return resolveSummary;
}

ResolveSet ResolveCellCategoryIdForTable()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(rowsNumber * columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
for (var j = 0; j < rowsNumber; j++)
{
var result = tableSectionData.GetCellCategoryId(j, i);
Expand All @@ -169,15 +198,26 @@ ResolveSet ResolveCellCategoryId()
return resolveSummary;
}

ResolveSet ResolveCellCombinedParameters()
ResolveSet ResolveCellCombinedParametersForColumns()
{
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
var result = tableSectionData.GetCellCombinedParameters(i);
resolveSummary.AppendVariant(result, $"Column {i}");
}

return resolveSummary;
}

ResolveSet ResolveCellCombinedParametersForTable()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(rowsNumber * columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
var columnResult = tableSectionData.GetCellCombinedParameters(i);
resolveSummary.AppendVariant(columnResult, $"Column {i}");
for (var j = 0; j < rowsNumber; j++)
{
var result = tableSectionData.GetCellCombinedParameters(j, i);
Expand All @@ -188,15 +228,26 @@ ResolveSet ResolveCellCombinedParameters()
return resolveSummary;
}

ResolveSet ResolveCellFormatOptions()
ResolveSet ResolveCellFormatOptionsForColumns()
{
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
var result = tableSectionData.GetCellFormatOptions(i, context);
resolveSummary.AppendVariant(result, $"Column {i}");
}

return resolveSummary;
}

ResolveSet ResolveCellFormatOptionsForTable()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(rowsNumber * columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
var columnResult = tableSectionData.GetCellFormatOptions(i, context);
resolveSummary.AppendVariant(columnResult, $"Column {i}");
for (var j = 0; j < rowsNumber; j++)
{
var result = tableSectionData.GetCellFormatOptions(j, i, context);
Expand All @@ -207,20 +258,30 @@ ResolveSet ResolveCellFormatOptions()
return resolveSummary;
}

ResolveSet ResolveCellParamId()
ResolveSet ResolveCellParamIdForColumns()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(rowsNumber * columnsNumber);
var resolveSummary = new ResolveSet(columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
var columnResult = tableSectionData.GetCellParamId(i);
if (columnResult != ElementId.InvalidElementId)
var result = tableSectionData.GetCellParamId(i);
if (result != ElementId.InvalidElementId)
{
var parameter = columnResult.ToElement(context);
resolveSummary.AppendVariant(columnResult, $"Column {i}: {parameter!.Name}");
var parameter = result.ToElement(context);
resolveSummary.AppendVariant(result, $"Column {i}: {parameter!.Name}");
}

}

return resolveSummary;
}

ResolveSet ResolveCellParamIdForTable()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(rowsNumber * columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
for (var j = 0; j < rowsNumber; j++)
{
var result = tableSectionData.GetCellParamId(j, i);
Expand All @@ -246,7 +307,7 @@ ResolveSet ResolveCellSpec()
{
var result = tableSectionData.GetCellSpec(j, i);
if (!result.Empty())
resolveSummary.AppendVariant(result, $"Row {j}, Column {i}: {result.ToLabel()}");
resolveSummary.AppendVariant(result, $"Row {j}, Column {i}: {result.ToUnitLabel()}");
}
}

Expand All @@ -270,15 +331,26 @@ ResolveSet ResolveCellText()
return resolveSummary;
}

ResolveSet ResolveCellType()
ResolveSet ResolveCellTypeForColumns()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(rowsNumber * columnsNumber);
var resolveSummary = new ResolveSet(columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
var columnResult = tableSectionData.GetCellType(i);
resolveSummary.AppendVariant(columnResult, $"Column {i}: {columnResult}");
}

return resolveSummary;
}

ResolveSet ResolveCellTypeForTable()
{
var rowsNumber = tableSectionData.NumberOfRows;
var columnsNumber = tableSectionData.NumberOfColumns;
var resolveSummary = new ResolveSet(rowsNumber * columnsNumber);
for (var i = 0; i < columnsNumber; i++)
{
for (var j = 0; j < rowsNumber; j++)
{
var result = tableSectionData.GetCellType(j, i);
Expand Down

0 comments on commit 335e590

Please sign in to comment.