public bool Equals (FormatItem other) { if (other == null) return false; return FieldsEquals (other); }
bool FieldsEquals (FormatItem other) { return Index == other.Index && Alignment == other.Alignment && FormatString == other.FormatString && StartLocation == other.StartLocation && EndLocation == other.EndLocation; }
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed sealed class {0} from unsealed to sealed which will cause derived classes to not compile.", FormatItem.MemberName(NewType, StyleFlags.Bold));
private void Parse ( ) { const int GO_BACK_ONE_CHARACTER = 1; _intHighestFormatItemIndex = FormatItem.INVALID_INDEX; State enmState = State.NotStarted; int intCharPos = FormatItem.INVALID_OFFSET; FormatItem fiCurrent = null; _ficoll = null; StringBuilder sbFormatComponent = null; if ( _lstFormatStringErrors != null ) { // Object is being recycled, and a previous use foud at least one error. _lstFormatStringErrors.Clear ( ); } // if ( _lstFormatStringErrors != null ) foreach ( char chr in _strFormatString ) { intCharPos++; switch ( enmState ) { case State.NotStarted: if ( chr == ITEM_BEGIN ) { // The first character is a left French brace. enmState = State.ItemBegin; } // TRUE block, if ( chr == ITEM_BEGIN ) else { // The first character is something else. enmState = State.ProcessingLiterals; } // FALSE block, if ( chr == ITEM_BEGIN ) break; // case State.NotStarted case State.ProcessingLiterals: if ( chr == ITEM_BEGIN ) { // Found a left French brace. enmState = State.ItemBegin; } // if ( chr == ITEM_BEGIN ) break; // case State.ProcessingLiterals case State.ItemBegin: // ---------------------------------------------------- // If the current character is a left French brace and // the last was an escape. Disregard both, and resume // sccanning for left braces. // // The item cannot officially begin until the first // character immediately following the left brace is // evaluated, because it is unknown until then whether // the left brace is escaped, and is to be treated as a // literal. As a consequence, the reported starting // position must allow for the fact that the carat is // already on the next character. // ---------------------------------------------------- if ( chr == ITEM_BEGIN ) { // Left brace is escaped. Revert to scanning. enmState = State.ProcessingLiterals; } // if ( chr == ITEM_BEGIN ) else if ( char.IsDigit ( chr ) ) { // Found a digit. This is expected. enmState = State.IndexComponet; fiCurrent = new FormatItem ( ( intCharPos - GO_BACK_ONE_CHARACTER ) , ( int ) Char.GetNumericValue ( chr ) ); } // else if ( char.IsDigit ( chr ) ) else { // Character is not a digit. Report the error and stop procesing this format item. ReportNewError ( intCharPos , chr , enmState , Properties.Resources.ERRMSG_NONDIGIT_AFTER_LEFTBRACE ); enmState = State.ProcessingLiterals; } // FALSE block, if ( chr == ITEM_BEGIN ) AND else if ( char.IsDigit ( chr ) ) break; // case State.ItemBegin case State.IndexComponet: if ( chr == ITEM_END ) { // The unmodified single-digit format item is the simplest case. SaveFormatItem ( ref enmState , // On return, this is always State.ProcessingLiterals. intCharPos , // On return, this is always unchanged. ref fiCurrent ); // On return, this is always null. } // TRUE block, if ( chr == ITEM_END ) else if ( char.IsDigit ( chr ) ) { // Item index has more digits. fiCurrent.UpdateIndex ( chr ); } // else if ( char.IsDigit ( chr ) ) else if ( chr == ITEM_HAS_ALIGNMENT_ATTRIBUTE ) { // This is a flag, whose only effect is to cause a state change. enmState = State.AlignmentBegin; } // else if ( chr == ITEM_HAS_ALIGNMENT_ATTRIBUTE ) else if ( chr == ITEM_HAS_FORMAT_STRING_ATTRIBUTE ) { // This is a flag, whose only effect is to cause a state change. enmState = State.FormatBegin; } // else if ( chr == ITEM_HAS_FORMAT_STRING_ATTRIBUTE ) else { // Format item is invalid. Report the error and stop procesing this format item. ReportNewError ( intCharPos , chr , enmState , Properties.Resources.ERRMSG_NONDIGIT_AFTER_LEFTBRACE ); enmState = State.ProcessingLiterals; } // ELSE block for all of the above. break; // case State.IndexComponet case State.AlignmentBegin: if ( char.IsDigit ( chr ) ) { // The Alignment component delimiter is most likely to be followed by one or more digits. fiCurrent.UpdateMinimumWidth ( chr ); fiCurrent.TextAlignment = FormatItem.Alignment.Right; enmState = State.AlignmentComponent; } // if ( char.IsDigit ( chr ) ) else if ( chr == ITEM_IS_LEFT_ALIGNED ) { // Item is left aligned. fiCurrent.TextAlignment = FormatItem.Alignment.Left; enmState = State.AlignmentFlag; } // else if ( chr == ITEM_IS_LEFT_ALIGNED ) else if ( chr == ITEM_IS_RIGHT_ALIGNED ) { // Item is right aligned. fiCurrent.TextAlignment = FormatItem.Alignment.Right; enmState = State.AlignmentFlag; } // else if ( chr == ITEM_IS_RIGHT_ALIGNED ) else { // Format item is invalid. Report the error and stop procesing this format item. ReportNewError ( intCharPos , chr , enmState , Properties.Resources.ERRMSG_NONDIGIT_AFTER_LEFTBRACE ); enmState = State.ProcessingLiterals; } // ELSE block for all of the above. break; // case State.AlignmentBegin case State.AlignmentFlag: if ( char.IsDigit ( chr ) ) { // The alignment flag (+/-) must be followed by at least one digit. fiCurrent.MinimumWidth = ( int ) char.GetNumericValue ( chr ); enmState = State.AlignmentComponent; } // TRUE (normal outcome) block, if ( char.IsDigit ( chr ) ) else { // Format item is invalid. Report the error and stop procesing this format item. ReportNewError ( intCharPos , chr , enmState , Properties.Resources.ERRMSG_NONDIGIT_AFTER_LEFTBRACE ); enmState = State.ProcessingLiterals; } // FALSE (exception outcome) block, if ( char.IsDigit ( chr ) ) break; // case State.AlignmentFlag case State.AlignmentComponent: if ( char.IsDigit ( chr ) ) { // Update the MinimumWidth property. fiCurrent.UpdateMinimumWidth ( chr ); } // if ( char.IsDigit ( chr ) ) else if ( chr == ITEM_HAS_FORMAT_STRING_ATTRIBUTE ) { // This is a flag, whose only effect is to cause a state change. enmState = State.FormatBegin; } // else if ( chr == ITEM_HAS_FORMAT_STRING_ATTRIBUTE ) else if ( chr == ITEM_END ) { // Add the fully populated item to the collection, change the State flag, and discard the FormatItem. SaveFormatItem ( ref enmState , // On return, this is always State.ProcessingLiterals. intCharPos , // On return, this is always unchanged. ref fiCurrent ); // On return, this is always null. } // else if ( chr == ITEM_END ) else { // Format item is invalid. Report the error and stop procesing this format item. ReportNewError ( intCharPos , chr , enmState , Properties.Resources.ERRMSG_NONDIGIT_AFTER_LEFTBRACE ); enmState = State.ProcessingLiterals; } // FALSE (exception outcome) block, if ( char.IsDigit ( chr ) ) break; // case State.AlignmentComponent case State.FormatBegin: if ( chr != ITEM_END ) { // Unless it's a closing French brace, use the current character to start a new StringBuilder. sbFormatComponent = new StringBuilder ( chr.ToString ( ) ); enmState = State.FormatString; } // TRUE (expected outcome) block, if ( chr != ITEM_END ) else { // Format item is invalid. Report the error and stop procesing this format item. ReportNewError ( intCharPos , chr , enmState , Properties.Resources.ERRMSG_FORMAT_COMPONENT_IS_EMPTY ); enmState = State.ProcessingLiterals; } // FALSE (UNexpected outcome) block, if ( chr != ITEM_END ) break; // case State.FormatBegin case State.FormatString: if ( chr == ITEM_END ) { // The format component is complete. Save it, discard the StringBuilder, and save the completed FormatItem. fiCurrent.ItemFormat = sbFormatComponent.ToString ( ); sbFormatComponent = null; SaveFormatItem ( ref enmState , // On return, this is always State.ProcessingLiterals. intCharPos , // On return, this is always unchanged. ref fiCurrent ); // On return, this is always null. } // TRUE block, if ( chr == ITEM_END ) else { // Append to string. sbFormatComponent.Append ( chr ); } // FALSE block, if ( chr == ITEM_END ) break; // case State.FormatString } // switch ( enmState ) } // foreach ( char chr in _strFormatString ) if ( enmState != State.ProcessingLiterals ) { ReportNewError ( intCharPos , _strFormatString [ _strFormatString.Length ] , enmState , Properties.Resources.ERRMSG_LAST_ITEM_INCOMPLETE ); enmState = State.ProcessingLiterals; } // if ( enmState != State.ProcessingLiterals ) } // private void Parse
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Removed override of abstract {0} {1} in {2} which may derived classes to not compile.", FormatItem.MemberKind(OldMemberOverride), FormatItem.MemberName(OldMemberOverride, StyleFlags.Italics), FormatItem.MemberName(NewType, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Removed implementation of interface {0} from {1} which may cause code using the {2} to not compile.", FormatItem.MemberName(OldInterfaceType, StyleFlags.Italics), FormatItem.MemberName(NewType, StyleFlags.Bold), FormatItem.MemberKind(NewType));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Removed the equivalent to assembly {0} in the new version, which will cause projects referencing the assembly to not compile.", FormatItem.AssemblyName(OldAssembly, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Added or removed the static modifier of {0} {1} which may cause code using the {0} to not compile.", FormatItem.MemberKind(NewMember), FormatItem.MemberName(NewMember, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed non-static sealed class {0} to static which will cause instantiations of the sealed class to not compile.", FormatItem.MemberName(NewType, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed read-write field {0} to read-only which will cause writes to the field to not compile.", FormatItem.MemberName(NewField, StyleFlags.Bold));
public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed accessibility of {0} from public to protected which may cause code to not compile.", FormatItem.MemberName(NewMember, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Added a new interface {0} {1} which will cause implementing types to not compile.", FormatItem.MemberKind(NewMember), FormatItem.MemberName(NewMember, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Added a new base interface {1} to {0} which will cause implementing types to not compile.", FormatItem.MemberName(NewType, StyleFlags.Bold), FormatItem.MemberName(NewInterfaceType, StyleFlags.Italics));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Added a new abstract {0} {1} which will cause derived classes to not compile.", FormatItem.MemberKind(NewMember), FormatItem.MemberName(NewMember, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed the name of a parameter from '{0}' to '{1}' in {2} which will cause named arguments in invocations to not compile.", FormatItem.ParameterName(OldParameter, StyleFlags.Italics), FormatItem.ParameterName(NewParameter, StyleFlags.Italics), FormatItem.ParameterizedItemName(NewParameterizedItem, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed the type of parameter '{0}' in {1} in a way which may cause invocations to not compile. Type was changed from {2} to {3}.", FormatItem.ParameterName(NewParameter, StyleFlags.Italics), FormatItem.ParameterizedItemName(NewParameterizedItem, StyleFlags.Bold), FormatItem.TypedItemTypeName(OldParameter, StyleFlags.Italics), FormatItem.TypedItemTypeName(NewParameter, StyleFlags.Italics));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed constraints for the generic type parameter {0} in {1} {2} which may cause constructions of the entity to not compile.", FormatItem.MemberName(NewGenericParameter, StyleFlags.Italics), FormatItem.MemberKind(NewGenericParameter.GenericDeclaringMember), FormatItem.MemberName(NewGenericParameter.GenericDeclaringMember, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed the base sealed class of {0} to something not derived from the previous base sealed class which may cause code using the sealed class to not compile. The base sealed class was changed from {1} to {2}.", FormatItem.MemberName(NewType, StyleFlags.Bold), FormatItem.MemberName(OldType.BaseType, StyleFlags.Italics), FormatItem.MemberName(NewType.BaseType, StyleFlags.Italics));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed variance (in or out modifier) for the generic type parameter {0} in {1} {2} which may cause implicit conversions of the {1} to not compile.", FormatItem.MemberName(NewGenericParameter, StyleFlags.Italics), FormatItem.MemberKind(NewGenericParameter.GenericDeclaringMember), FormatItem.MemberName(NewGenericParameter.GenericDeclaringMember, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Removed the 'this' modifier from the first parameter of {0} which will cause code using the method as an extension method to not compile.", FormatItem.MemberName(NewMethod, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed virtual {0} {1} to non-virtual which will cause derived classes overriding the {0} to not compile.", FormatItem.MemberKind(NewMember), FormatItem.MemberName(NewMember, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Removed {0} {1} which will cause code using the {0} to not compile.", FormatItem.MemberKind(OldMember), FormatItem.MemberName(OldMember, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed the type of {0} {1} in a way which may cause code using the {0} to not compile. Type was changed from {2} to {3}.", FormatItem.TypedItemKind(NewTypedItem), FormatItem.TypedItemName(NewTypedItem, StyleFlags.Bold), FormatItem.TypedItemTypeName(OldTypedItem, StyleFlags.Italics), FormatItem.TypedItemTypeName(NewTypedItem, StyleFlags.Italics));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Removed or changed the visibility of the get or set accessor of {0} {1} which may code using the {0} to not compile.", FormatItem.MemberKind(NewProperty), FormatItem.MemberName(NewProperty, StyleFlags.Bold));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed the parameter count of {0} in a way which may cause invocations to not compile. Previous declaration was {1}.", FormatItem.ParameterizedItemName(NewParameterizedItem, StyleFlags.Bold), FormatItem.ParameterizedItemName(OldParameterizedItem, StyleFlags.Italics));
protected FormatItem(FormatItem parent, int startIndex) : this(parent.baseString, startIndex, parent.baseString.Length) { }
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed default value of parameter '{0}' in {1} which may cause an unintentional behavioral change in code. The value was changed from '{2}' to '{3}'.", FormatItem.ParameterName(NewParameter, StyleFlags.Italics), FormatItem.ParameterizedItemName(NewParameterizedItem, StyleFlags.Bold), FormatItem.DefaultParameterValue(OldParameter, StyleFlags.Italics), FormatItem.DefaultParameterValue(NewParameter, StyleFlags.Italics));
/// <inheritdoc/> public override void FormatMessage(IBreakingChangeFormatter formatter) => formatter.AppendFormat("Changed the ref or out modifier of parameter '{0}' in {1} which will cause invocations to not compile.", FormatItem.ParameterName(NewParameter, StyleFlags.Italics), FormatItem.ParameterizedItemName(NewParameterizedItem, StyleFlags.Bold));
private object ParseFormatItems(string attribValue, bool throwOnError) { return(FormatItem.ParseFormatString(attribValue)); }