private static void GetSheetTabAttributes(Type instanceType, out SheetNameAttribute sheetNameAttribute, out TabNameAttribute tabNameAttribute) { sheetNameAttribute = instanceType.GetCustomAttribute <SheetNameAttribute>(); if (sheetNameAttribute == null) { throw new InvalidDataException($"{instanceType.Name} needs to specify the \"SheetName\" attribute."); } tabNameAttribute = instanceType.GetCustomAttribute <TabNameAttribute>(); if (tabNameAttribute == null) { throw new InvalidDataException($"{instanceType.Name} needs to specify the \"TabName\" attribute."); } }
public static List <T> Get <T>() where T : new() { SheetNameAttribute sheetAttribute = typeof(T).GetCustomAttribute <SheetNameAttribute>(); if (sheetAttribute == null) { throw new InvalidDataException($"SheetNameAttribute not found on (\"{typeof(T).Name}\")."); } TabNameAttribute tabAttribute = typeof(T).GetCustomAttribute <TabNameAttribute>(); if (tabAttribute == null) { throw new InvalidDataException($"TabNameAttribute not found on (\"{typeof(T).Name}\")."); } return(Get <T>(sheetAttribute.SheetName, tabAttribute.TabName)); }
public static void SaveChanges(object[] instances, string filterMembers = null) { if (instances == null || instances.Length == 0) { return; } Type instanceType = instances[0].GetType(); SheetNameAttribute sheetNameAttribute = instanceType.GetCustomAttribute <SheetNameAttribute>(); if (sheetNameAttribute == null) { throw new InvalidDataException($"{instanceType.Name} needs to specify the \"SheetName\" attribute."); } TabNameAttribute tabNameAttribute = instanceType.GetCustomAttribute <TabNameAttribute>(); if (tabNameAttribute == null) { throw new InvalidDataException($"{instanceType.Name} needs to specify the \"TabName\" attribute."); } SaveChanges(sheetNameAttribute.SheetName, tabNameAttribute.TabName, instances, instanceType, filterMembers); }