/// <summary> /// This is ran when too many constructors were found when attempting to create an object. /// </summary> public void TooManyConstructorsWithDifferentCase(Type type, int location) { // Create EventArgs to pass around information about what happened. var args = new ErrorEncounteredEventArgs(ABSaveError.TooManyConstructorsWithDifferentCase, location, "When creating an instance of an object, there were too many constructors with matching names to the fields/properties (when ignoring case)... As a result, ABSave cannot determine which constructor to use. This is with the type '" + type.ToString() + "'."); // Now, handle the error. HandleError(args, ABSaveError.TooManyConstructorsWithDifferentCase, new TooManyConstructorsWithDifferentCase(args.ToString())); }
/// <summary> /// This is ran when an "Infer Type" is passed when serializing. /// </summary> public void InferTypeWhenSerializing() { // Create EventArgs to pass around information about what happened. var args = new ErrorEncounteredEventArgs(ABSaveError.InferTypeWhenSerializing, 0); // Now, handle the error. HandleError(args, ABSaveError.InferTypeWhenSerializing, new InferABSaveTypeWhenSerializing(args.ToString())); }
/// <summary> /// This is ran when an invalid header is found when parsing. /// </summary> public void InvalidHeaderWhenParsing(string message) { // Create EventArgs to pass around information about what happened. var args = new ErrorEncounteredEventArgs(ABSaveError.InvalidHeaderWhenParsing, 0, message); // Now, handle the error. HandleError(args, ABSaveError.InvalidHeaderWhenParsing, new InvalidHeaderWhenParsing(args.ToString())); }
/// <summary> /// This is ran when there is a missing name for a value. /// </summary> /// <param name="location"></param> public void MissingNameToValueWhenParsing(int location) { // Create EventArgs to pass around information about what happened. var args = new ErrorEncounteredEventArgs(ABSaveError.MissingNameToValueWhenParsing, location, "A value has been found without a matching name."); // Now, handle the error. HandleError(args, ABSaveError.MissingNameToValueWhenParsing, new MissingNameToValueWhenParsing(args.ToString())); }
/// <summary> /// This is ran when there are more "Next Item" tokens than actual items. /// </summary> public void MoreNextItemTokensThanItems(int location) { // Create EventArgs to pass around information about what happened. var args = new ErrorEncounteredEventArgs(ABSaveError.MoreNextItemTokensThanItems, location, "There were more 'next item' tokens than there were fields/properties on an object."); // Now, handle the error. HandleError(args, ABSaveError.MoreNextItemTokensThanItems, new MoreNextItemTokensThanActualItems(args.ToString())); }
/// <summary> /// This is ran when there is an unexpected token when parsing. /// </summary> public void UnexpectedTokenWhenParsing(int location, string message) { // Create EventArgs to pass around information about what happened. var args = new ErrorEncounteredEventArgs(ABSaveError.UnexpectedTokenWhenParsing, location, message); // Now, handle the error. HandleError(args, ABSaveError.UnexpectedTokenWhenParsing, new UnexpectedTokenWhenParsing(args.ToString())); }
/// <summary> /// This is ran when a valid constructor can not be found when creating an instance of an object. /// </summary> public void InvalidConstructorsForCreatingObject(Type type, int location) { // Create EventArgs to pass around information about what happened. var args = new ErrorEncounteredEventArgs(ABSaveError.InvalidConstructorsForCreatingObject, location, "A valid constructor cannot be found for the type: " + type.ToString()); // Now, handle the error. HandleError(args, ABSaveError.InvalidConstructorsForCreatingObject, new InvalidConstructorsWhenCreatingObject(args.ToString())); }
/// <summary> /// Handles all the basic functionality for an error (throw exception if needed and run "ErrorEncountered"). /// </summary> /// <param name="args">The information about the error.</param> /// <param name="err">The type the error was.</param> /// <param name="exception">The actual exception this error is contained in.</param> internal void HandleError(ErrorEncounteredEventArgs args, ABSaveError err, Exception exception) { // Call the event "ErrorEncountered" - if we aren't meant to IgnoreAllErrors. if (!IgnoreAllErrors) { ErrorEncountered?.Invoke(args); } // If it isn't suppressed, throw an exception. if (!SuppressedErrors.HasFlag(err)) { throw exception; } }