Skip to content

Commit

Permalink
code format updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveWinward committed Nov 26, 2023
1 parent 979c9bd commit 8eac2dd
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The following Google Sheets API operations are supported:
* Deleting rows
* Updating specific cells

All operations above are encapsulated in the SheetHelper class.
All operations above are encapsulated in the ````SheetHelper```` class.

There are also base classes, ````BaseRecord```` and ````BaseRepository```` to simplify transforming raw Google Sheets rows into .NET objects.

Expand Down
2 changes: 1 addition & 1 deletion src/GoogleSheetsWrapper/BaseRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class BaseRecord
public int RowId { get; set; }

/// <summary>
/// Default constructor for BaseRecord
/// Default constructor for <see cref="BaseRecord"/>
/// </summary>
public BaseRecord() { }

Expand Down
2 changes: 1 addition & 1 deletion src/GoogleSheetsWrapper/BaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public BatchUpdateSpreadsheetResponse SaveFields(T record, IList<Expression<Func
{
var data = record.ConvertToCellData(SheetHelper.TabName);

var updates = BaseRepository<T>.FilterUpdates(data, properties);
var updates = FilterUpdates(data, properties);

return SheetHelper.BatchUpdate(updates);
}
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleSheetsWrapper/BatchUpdateRequestObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BatchUpdateRequestObject
public CellData Data { get; set; }

/// <summary>
/// The SheetFieldAttribute
/// The <see cref="SheetFieldAttribute"/> value
/// </summary>
public SheetFieldAttribute FieldAttribute { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleSheetsWrapper/SheetExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void ExportAsExcel(SheetRange range, Stream stream)

// Add Sheets to the Workbook.
var sheets = document.WorkbookPart.Workbook.
AppendChild<Sheets>(new Sheets());
AppendChild(new Sheets());

// Append a new worksheet and associate it with the workbook.
var sheet = new Sheet()
Expand Down
8 changes: 5 additions & 3 deletions src/GoogleSheetsWrapper/SheetFieldAttributeComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public class SheetFieldAttributeComparer : IComparer<SheetFieldAttribute>
/// <returns></returns>
public int Compare([AllowNull] SheetFieldAttribute x, [AllowNull] SheetFieldAttribute y)
{
if ((x != null) && (y != null))
// If either of the objects are null, return 0
if (x == null || y == null)
{
return x.ColumnID.CompareTo(y.ColumnID);
return 0;
}
// Otherwise, return the actual CompareTo value
else
{
return 0;
return x.ColumnID.CompareTo(y.ColumnID);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/GoogleSheetsWrapper/SheetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Google.Apis.Services;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
using static Google.Apis.Sheets.v4.SpreadsheetsResource.ValuesResource;
using static Google.Apis.Sheets.v4.SpreadsheetsResource.ValuesResource.GetRequest;

namespace GoogleSheetsWrapper
Expand Down Expand Up @@ -183,8 +182,8 @@ public List<string> GetAllTabNames()
var request =
Service.Spreadsheets.Values.Get(SpreadsheetID, rangeValue);

request.ValueRenderOption = GetRequest.ValueRenderOptionEnum.FORMATTEDVALUE;
request.DateTimeRenderOption = GetRequest.DateTimeRenderOptionEnum.FORMATTEDSTRING;
request.ValueRenderOption = ValueRenderOptionEnum.FORMATTEDVALUE;
request.DateTimeRenderOption = DateTimeRenderOptionEnum.FORMATTEDSTRING;

var response = request.Execute();
return response.Values;
Expand Down
107 changes: 59 additions & 48 deletions src/GoogleSheetsWrapper/SheetRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ public string TabName
set => UpdateFieldAndNotiationProperties(ref _tabName, value);
}

/// <summary>
/// Internal property to indicate the object has been initialized and the constructor method
/// has completed.
/// </summary>
private readonly bool IsInitialized;

/// <summary>
/// Helper list of all letters A through Z
/// </summary>
private static readonly List<string> aToZ
= Enumerable.Range('A', 26)
.Select(x => (char)x + "")
Expand Down Expand Up @@ -192,54 +199,6 @@ public static int GetColumnIDFromLetters(string letters)
return result;
}

/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static int GetHashCode(SheetRange obj)
{
return HashCode.Combine(obj.StartRow, obj.StartColumn, obj.EndColumn, obj.EndRow, obj.TabName);
}

/// <summary>
///
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(SheetRange other)
{
return
A1Notation == other.A1Notation &&
CanSupportA1Notation == other.CanSupportA1Notation &&
EndColumn == other.EndColumn &&
EndRow == other.EndRow &&
IsSingleCellRange == other.IsSingleCellRange &&
R1C1Notation == other.R1C1Notation &&
StartColumn == other.StartColumn &&
StartRow == other.StartRow &&
TabName == other.TabName;
}

/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
return Equals((SheetRange)obj);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return GetHashCode(this);
}

/// <summary>
/// Calculates the R1C1 Notation and A1 Notation values for this instance
/// </summary>
Expand Down Expand Up @@ -295,5 +254,57 @@ private void UpdateFieldAndNotiationProperties<T>(ref T currentValue, T newValue
}
}
}

#region IEquatable Interface Implementation

/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static int GetHashCode(SheetRange obj)
{
return HashCode.Combine(obj.StartRow, obj.StartColumn, obj.EndColumn, obj.EndRow, obj.TabName);
}

/// <summary>
///
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(SheetRange other)
{
return
A1Notation == other.A1Notation &&
CanSupportA1Notation == other.CanSupportA1Notation &&
EndColumn == other.EndColumn &&
EndRow == other.EndRow &&
IsSingleCellRange == other.IsSingleCellRange &&
R1C1Notation == other.R1C1Notation &&
StartColumn == other.StartColumn &&
StartRow == other.StartRow &&
TabName == other.TabName;
}

/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
return Equals((SheetRange)obj);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return GetHashCode(this);
}

#endregion
}
}

0 comments on commit 8eac2dd

Please sign in to comment.