Skip to content

Commit

Permalink
Fixes OData#3132 Replace using Resource files for error message (ODat…
Browse files Browse the repository at this point in the history
…a#3146)

* Fixes OData#3132 Replace using Resource files for error message
1) Remove the old tt files
2) Convert the error messages from txt files to resx files
3) Add the Error class for helpers
4) Change the codes to use the resource error message

* Remove the unused files

* Fix the failing test cases

* Fixes the failing tests
  • Loading branch information
xuzhg authored Dec 12, 2024
1 parent 1ab767c commit 70eef8a
Show file tree
Hide file tree
Showing 638 changed files with 22,469 additions and 21,557 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Client/ALinq/ALinqExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal virtual Expression Visit(Expression exp)
case ExpressionType.ListInit:
return this.VisitListInit((ListInitExpression)exp);
default:
throw new NotSupportedException(Strings.ALinq_UnsupportedExpression(exp.NodeType.ToString()));
throw new NotSupportedException(Error.Format(SRResources.ALinq_UnsupportedExpression, exp.NodeType.ToString()));
}
}

Expand All @@ -117,7 +117,7 @@ internal virtual MemberBinding VisitBinding(MemberBinding binding)
case MemberBindingType.ListBinding:
return this.VisitMemberListBinding((MemberListBinding)binding);
default:
throw new NotSupportedException(Strings.ALinq_UnsupportedExpression(binding.BindingType.ToString()));
throw new NotSupportedException(Error.Format(SRResources.ALinq_UnsupportedExpression, binding.BindingType.ToString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AddNewEndingTokenVisitor(PathSegmentToken newTokenToAdd)
/// <param name="tokenIn">The system token to traverse</param>
public void Visit(SystemToken tokenIn)
{
throw new NotSupportedException(Strings.ALinq_IllegalSystemQueryOption(tokenIn.Identifier));
throw new NotSupportedException(Error.Format(SRResources.ALinq_IllegalSystemQueryOption, tokenIn.Identifier));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private TElement ParseAggregateSingletonResult<TElement>(QueryResult queryResult
}

// Failed to retrieve the aggregate result for whatever reason
throw new DataServiceQueryException(Strings.DataServiceRequest_FailGetValue);
throw new DataServiceQueryException(SRResources.DataServiceRequest_FailGetValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class ExpandOnlyPathToStringVisitor : IPathSegmentTokenVisitor<string>
/// <returns>Always throws, since a system token is invalid in an expand path.</returns>
public string Visit(SystemToken tokenIn)
{
throw new NotSupportedException(Strings.ALinq_IllegalSystemQueryOption(tokenIn.Identifier));
throw new NotSupportedException(Error.Format(SRResources.ALinq_IllegalSystemQueryOption, tokenIn.Identifier));
}

/// <summary>
Expand All @@ -51,7 +51,7 @@ public string Visit(NonSystemToken tokenIn)
}
else
{
throw new NotSupportedException(Strings.ALinq_TypeTokenWithNoTrailingNavProp(tokenIn.Identifier));
throw new NotSupportedException(Error.Format(SRResources.ALinq_TypeTokenWithNoTrailingNavProp, tokenIn.Identifier));
}
}
else
Expand Down
16 changes: 8 additions & 8 deletions src/Microsoft.OData.Client/ALinq/ExpressionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal static string ExpressionToString(DataServiceContext context, Expression
WebUtil.RaiseVersion(ref uriVersion, ew.uriVersion);
if (ew.cantTranslateExpression)
{
throw new NotSupportedException(Strings.ALinq_CantTranslateExpression(e.ToString()));
throw new NotSupportedException(Error.Format(SRResources.ALinq_CantTranslateExpression, e.ToString()));
}

return serialized;
Expand Down Expand Up @@ -229,7 +229,7 @@ internal override Expression VisitInputReferenceExpression(InputReferenceExpress
// because we cannot reference 'this' as a standalone expression; however
// if the parent is null for any reason, we fall back to the expression itself.
string expressionText = (this.parent != null) ? this.parent.ToString() : ire.ToString();
throw new NotSupportedException(Strings.ALinq_CantTranslateExpression(expressionText));
throw new NotSupportedException(Error.Format(SRResources.ALinq_CantTranslateExpression, expressionText));
}

// Write "$it" for input parameter reference inside any/all methods
Expand Down Expand Up @@ -426,7 +426,7 @@ internal override Expression VisitMethodCall(MethodCallExpression m)
string declaringType = this.context.ResolveNameFromTypeInternal(m.Method.DeclaringType);
if (string.IsNullOrEmpty(declaringType))
{
throw new NotSupportedException(Strings.ALinq_CantTranslateExpression(m.ToString()));
throw new NotSupportedException(Error.Format(SRResources.ALinq_CantTranslateExpression, m.ToString()));
}

int index = declaringType.LastIndexOf('.');
Expand Down Expand Up @@ -472,7 +472,7 @@ internal override Expression VisitMemberAccess(MemberExpression m)
{
if (m.Member is FieldInfo)
{
throw new NotSupportedException(Strings.ALinq_CantReferToPublicField(m.Member.Name));
throw new NotSupportedException(Error.Format(SRResources.ALinq_CantReferToPublicField, m.Member.Name));
}

Expression e = this.Visit(m.Expression);
Expand Down Expand Up @@ -572,7 +572,7 @@ internal override Expression VisitConstant(ConstantExpression c)
return c;
}

throw new NotSupportedException(Strings.ALinq_CouldNotConvert(item));
throw new NotSupportedException(Error.Format(SRResources.ALinq_CouldNotConvert, item));
}

listExpr.Append(uriLiteral);
Expand All @@ -581,7 +581,7 @@ internal override Expression VisitConstant(ConstantExpression c)
// Contains cannot be used with an empty static collection
if (listExpr.Length == 0)
{
throw new InvalidOperationException(Strings.ALinq_ContainsNotValidOnEmptyCollection);
throw new InvalidOperationException(SRResources.ALinq_ContainsNotValidOnEmptyCollection);
}

listExpr.Insert(0, UriHelper.LEFTPAREN);
Expand All @@ -604,7 +604,7 @@ internal override Expression VisitConstant(ConstantExpression c)
return c;
}

throw new NotSupportedException(Strings.ALinq_CouldNotConvert(c.Value));
throw new NotSupportedException(Error.Format(SRResources.ALinq_CouldNotConvert, c.Value));
}
}

Expand Down Expand Up @@ -666,7 +666,7 @@ internal override Expression VisitUnary(UnaryExpression u)
case ExpressionType.TypeAs:
if (u.Operand.NodeType == ExpressionType.TypeAs)
{
throw new NotSupportedException(Strings.ALinq_CannotUseTypeFiltersMultipleTimes);
throw new NotSupportedException(SRResources.ALinq_CannotUseTypeFiltersMultipleTimes);
}

this.Visit(u.Operand);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OData.Client/ALinq/GroupByAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ internal override NewExpression VisitNew(NewExpression nex)
else if (nex.Arguments.Count > 0 && nex.Constructor.GetParameters().Length > 0)
{
// Constructor initialization in key selector not supported
throw new NotSupportedException(Strings.ALinq_InvalidGroupByKeySelector(nex));
throw new NotSupportedException(Error.Format(SRResources.ALinq_InvalidGroupByKeySelector, nex));
}

return base.VisitNew(nex);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OData.Client/ALinq/NewTreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class NewTreeBuilder : IPathSegmentTokenVisitor<PathSegmentToken>
/// <returns>Always throws, since a SystemToken is illegal in a select or expand path.</returns>
public PathSegmentToken Visit(SystemToken tokenIn)
{
throw new NotSupportedException(Strings.ALinq_IllegalSystemQueryOption(tokenIn.Identifier));
throw new NotSupportedException(Error.Format(SRResources.ALinq_IllegalSystemQueryOption, tokenIn.Identifier));
}

/// <summary>
Expand Down
Loading

0 comments on commit 70eef8a

Please sign in to comment.