Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce warnings across projects #1808

Merged
merged 27 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b26a12d
Fix CA1200: replace cref="\w with cref=".
bdebaere Jun 13, 2020
b4f3f46
Fix xUnit2017: replace Assert.IsTrue(Contains) with Assert.Contains.
bdebaere Jun 13, 2020
aaef400
Fix CA1063: implement Dispose correctly.
bdebaere Jun 13, 2020
2ba095c
Fix CA1309: use StringComparison.Ordinal.
bdebaere Jun 13, 2020
df6d5f9
Fix CA1507: use nameof instead of string literal.
bdebaere Jun 13, 2020
934a8c9
Fix CS1658: replace `1 with generic parameter in comments.
bdebaere Jun 13, 2020
5b22550
Fix SA1500: adjust StringsClassGenerator.ttinclude to span multiple l…
bdebaere Jun 13, 2020
efbe56c
Replace DataServiceQuerySingle`1 with DataServiceQuerySingle{T}.
bdebaere Jun 16, 2020
ca07cea
Replace QueryOperationResponse`1 with QueryOperationResponse{T}.
bdebaere Jun 16, 2020
9ddab3a
Replace DataServiceRequest`1 with DataServiceRequest{T}.
bdebaere Jun 16, 2020
adc73c1
Replace Dictionary`2 with Dictionary{TKey,TValue}.
bdebaere Jun 16, 2020
1a03bc8
Repalce ReadOnlyCollection`1 with ReadOnlyCollection{T}.
bdebaere Jun 16, 2020
f3a3523
Replace DataServiceRequest[]" with DataServiceRequest[].
bdebaere Jun 17, 2020
cec7c26
Replace DataServiceContext.BeginExecute``1 with DataServiceContext.Be…
bdebaere Jun 17, 2020
5fb8f8e
Fix CA1829: use Length property when available.
bdebaere Jun 17, 2020
5974f82
Regenerate file.
bdebaere Jun 17, 2020
50bd839
Add // <auto-generated/> at the top of generated files.
bdebaere Jun 17, 2020
cbf94b9
Fix CA1827: replace Count() == 0 with !Any and Count() > 0 with Any.
bdebaere Jun 17, 2020
9785057
Fix xUnit2013: use Assert.Single.
bdebaere Jun 17, 2020
5ea5666
Fix xUnit2013: add FactAttribute.
bdebaere Jun 17, 2020
78f6800
Replace DataServiceActionQuery.BeginExecute``1 with DataServiceAction…
bdebaere Jun 17, 2020
e626c6a
Replace DataServiceContext.EndExecute``1 with DataServiceContext.EndE…
bdebaere Jun 17, 2020
a69d2cc
Apply various stylecop fixes.
bdebaere Jun 17, 2020
10d0c3a
Fix xUnit2008: use Assert.Matches.
bdebaere Jun 17, 2020
5ba2f32
More various stylecop fixes.
bdebaere Jun 17, 2020
86f66f9
Fix CA1829: use property instead of method.
bdebaere Jun 17, 2020
ba8fbbf
Revert "Fix xUnit2013: add FactAttribute."
bdebaere Jun 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Microsoft.OData.Client/ALinq/ExpressionNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ internal override Expression VisitBinary(BinaryExpression b)
if (_patterns.TryGetValue(visited.Left, out pattern) && pattern.Kind == PatternKind.Compare && IsConstantZero(visited.Right))
{
ComparePattern comparePattern = (ComparePattern)pattern;

// handle relational operators
BinaryExpression relationalExpression;
if (TryCreateRelationalOperator(visited.NodeType, comparePattern.Left, comparePattern.Right, out relationalExpression))
Expand Down Expand Up @@ -174,7 +175,7 @@ internal override Expression VisitUnary(UnaryExpression u)
if (!PrimitiveType.IsKnownNullableType(visited.Operand.Type) && !PrimitiveType.IsKnownNullableType(visited.Type) || visited.Operand.Type == visited.Type)
{
// x is not a collection of entity types
if(!(ClientTypeUtil.TypeOrElementTypeIsEntity(visited.Operand.Type) && ProjectionAnalyzer.IsCollectionProducingExpression(visited.Operand)))
if (!(ClientTypeUtil.TypeOrElementTypeIsEntity(visited.Operand.Type) && ProjectionAnalyzer.IsCollectionProducingExpression(visited.Operand)))
{
// x is not an enum type
if (!visited.Operand.Type.IsEnum())
Expand Down Expand Up @@ -383,10 +384,13 @@ internal Expression VisitMethodCallNoRewrite(MethodCallExpression call)
}

MethodCallExpression normalizedResult;

// check for coalesce operators added by the VB compiler to predicate arguments
normalizedResult = NormalizePredicateArgument(visited);

// check for type conversions in a Select that can be converted to Cast
normalizedResult = NormalizeSelectWithTypeCast(normalizedResult);

// check for type conversion for Any/All/OfType source
normalizedResult = NormalizeEnumerableSource(normalizedResult);

Expand Down Expand Up @@ -475,7 +479,7 @@ private static bool HasPredicateArgument(MethodCallExpression callExpression, ou
// argument. As a result, we always set argumentOrdinal to 1 when there is a match and
// we can safely ignore all methods taking fewer than 2 arguments
SequenceMethod sequenceMethod;
if (2 <= callExpression.Arguments.Count &&
if (callExpression.Arguments.Count >= 2 &&
ReflectionUtil.TryIdentifySequenceMethod(callExpression.Method, out sequenceMethod))
{
switch (sequenceMethod)
Expand Down Expand Up @@ -623,6 +627,7 @@ private static bool TryMatchConvertSingleArgument(Expression expression, out Typ
if (lambda.Parameters.Count == 1 && lambda.Body.NodeType == ExpressionType.Convert)
{
UnaryExpression convertExpression = (UnaryExpression)lambda.Body;

// Make sure the parameter being converted is the single lambda parameter
if (convertExpression.Operand == lambda.Parameters[0])
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Client/ALinq/ExpressionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ internal override Expression VisitMethodCall(MethodCallExpression m)
{
// SequenceMethod.Any represents Enumerable.Any(), which has only source argument
// AnyPredicate and All has a second parameter which is the predicate lambda.
Debug.Assert(m.Arguments.Count() == 2, "m.Arguments.Count() == 2");
Debug.Assert(m.Arguments.Count == 2, "m.Arguments.Count() == 2");
LambdaExpression le = (LambdaExpression)m.Arguments[1];
string rangeVariable = le.Parameters[0].Name;
this.builder.Append(rangeVariable);
Expand Down Expand Up @@ -463,7 +463,7 @@ internal override Expression VisitMemberAccess(MemberExpression m)
var parentType = m.Member.DeclaringType;
Type collectionType = ClientTypeUtil.GetImplementationType(parentType, typeof(ICollection<>));
if (!PrimitiveType.IsKnownNullableType(parentType) && collectionType != null &&
m.Member.Name.Equals(ReflectionUtil.COUNTPROPNAME))
m.Member.Name.Equals(ReflectionUtil.COUNTPROPNAME, StringComparison.Ordinal))
{
this.builder.Append(UriHelper.DOLLARSIGN).Append(UriHelper.COUNT);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Client/ALinq/ProjectionAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static void Analyze(LambdaExpression e, SelectExpandPathBuilder pb, Data
bool knownEntityType = ClientTypeUtil.TypeOrElementTypeIsEntity(e.Body.Type);
ParameterExpression pe = e.Parameters.Last();
bool isEntityParameter = ClientTypeUtil.TypeOrElementTypeIsEntity(pe.Type);
if(isEntityParameter)
if (isEntityParameter)
{
pb.PushParamExpression(pe);
}
Expand Down Expand Up @@ -654,7 +654,7 @@ internal override Expression VisitBinary(BinaryExpression b)

internal override Expression VisitTypeIs(TypeBinaryExpression b)
{
if (ClientTypeUtil.TypeOrElementTypeIsEntity(b.Expression.Type ) || IsCollectionProducingExpression(b.Expression))
if (ClientTypeUtil.TypeOrElementTypeIsEntity(b.Expression.Type) || IsCollectionProducingExpression(b.Expression))
{
throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjection(this.type, b.ToString()));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Client/ALinq/ReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ internal static string GetCanonicalMethodDescription(MethodInfo method)
description.Append(")");

// include return type
if (null != method.ReturnType)
if (method.ReturnType != null)
{
description.Append("->");
AppendCanonicalTypeDescription(method.ReturnType, genericArgumentOrdinals, description);
Expand All @@ -513,7 +513,7 @@ private static void AppendCanonicalTypeDescription(Type type, Dictionary<Type, i
int ordinal;

// if this a type argument for the method, substitute
if (null != genericArgumentOrdinals && genericArgumentOrdinals.TryGetValue(type, out ordinal))
if (genericArgumentOrdinals != null && genericArgumentOrdinals.TryGetValue(type, out ordinal))
{
description.Append("T").Append(ordinal.ToString(CultureInfo.InvariantCulture));

Expand Down
17 changes: 12 additions & 5 deletions src/Microsoft.OData.Client/ALinq/ResourceBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ private static bool TryAnalyzeSelectManyCollector(ResourceExpression input, Expr
result = null;
}
}

return result != null;
}

Expand Down Expand Up @@ -827,6 +828,7 @@ private static Expression LimitCardinality(MethodCallExpression mce, int maxCard
AddSequenceQueryOption(rse, new TakeQueryOptionExpression(mce.Type, Expression.Constant(maxCardinality)));
}
}

return mce.Arguments[0];
}
else if (mce.Arguments[0] is NavigationPropertySingletonExpression || mce.Arguments[0] is SingletonResourceExpression)
Expand Down Expand Up @@ -1303,7 +1305,7 @@ private static Expression AnalyzeResourceSetConstantMethod(MethodCallExpression
{
ResourceExpression input = (ResourceExpression)mce.Arguments[0];
ConstantExpression constantArg = StripTo<ConstantExpression>(mce.Arguments[1]);
if (null == constantArg)
if (constantArg == null)
{
// UNSUPPORTED: A ConstantExpression is expected
return mce;
Expand Down Expand Up @@ -1506,14 +1508,17 @@ internal override Expression VisitMethodCall(MethodCallExpression mce)
{
return AnalyzeExpand(mce, this.context);
}

if (mce.Method.GetParameters().Any() && mce.Method.GetParameters()[0].ParameterType == t)
{
return AnalyzeFunc(mce, true);
}

if (mce.Method.Name == AddQueryOptionMethodName && mce.Method.DeclaringType == t)
{
return AnalyzeAddCustomQueryOption(mce);
}

if (mce.Method.Name == IncludeCountMethodName && mce.Method.DeclaringType == t)
{
return AnalyzeAddCountOption(mce);
Expand Down Expand Up @@ -1773,6 +1778,7 @@ internal static bool MatchNonPrivateReadableProperty(Expression e, out PropertyI

propInfo = null;
target = null;

// must be member expression
MemberExpression me = e as MemberExpression;
if (me == null)
Expand All @@ -1784,6 +1790,7 @@ internal static bool MatchNonPrivateReadableProperty(Expression e, out PropertyI
if (PlatformHelper.IsProperty(me.Member))
{
PropertyInfo pi = (PropertyInfo)me.Member;

// must be readable and non-private
if (pi.CanRead && !TypeSystem.IsPrivate(pi))
{
Expand Down Expand Up @@ -2772,7 +2779,7 @@ internal override Expression VisitMemberAccess(MemberExpression m)
PropertyInfo pi = (PropertyInfo)m.Member;

// For member like "c.Trips.Count", when Count is visited, no future visit if declare type is a Collection
if (pi.Name.Equals(ReflectionUtil.COUNTPROPNAME))
if (pi.Name.Equals(ReflectionUtil.COUNTPROPNAME, StringComparison.Ordinal))
{
MemberExpression me = StripTo<MemberExpression>(m.Expression);
if (me != null && !PrimitiveType.IsKnownNullableType(me.Type))
Expand Down Expand Up @@ -2947,11 +2954,11 @@ public bool Equals(PropertyInfo left, PropertyInfo right)

// If either side is null, return false order (both can't be null because of
// the previous check)
if (null == left || null == right) { return false; }
if (left == null || right == null) { return false; }

// If the declaring type and the name of the property are the same,
// both the property infos refer to the same property.
return object.ReferenceEquals(left.DeclaringType, right.DeclaringType) && left.Name.Equals(right.Name);
return object.ReferenceEquals(left.DeclaringType, right.DeclaringType) && left.Name.Equals(right.Name, StringComparison.Ordinal);
}

/// <summary>
Expand All @@ -2962,7 +2969,7 @@ public bool Equals(PropertyInfo left, PropertyInfo right)
public int GetHashCode(PropertyInfo obj)
{
Debug.Assert(obj != null, "obj != null");
return (null != obj) ? obj.GetHashCode() : 0;
return (obj != null) ? obj.GetHashCode() : 0;
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Client/Annotation/AnnotationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private static IEdmVocabularyAnnotation GetOrInsertCachedMetadataAnnotationForTy
var edmValueAnnotations = serviceModel.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(edmVocabularyAnnotatable, term, qualifier)
.Where(a => a.Qualifier == qualifier && a.Target == edmVocabularyAnnotatable);

if (edmValueAnnotations.Count() == 0)
if (!edmValueAnnotations.Any())
{
edmValueAnnotation = GetOrInsertCachedMetadataAnnotationForType(context, type.GetBaseType(), term, qualifier);
}
Expand Down Expand Up @@ -409,7 +409,7 @@ private static IEdmVocabularyAnnotation GetCachedMetadataAnnotation(DataServiceC
if (key != null && context.MetadataAnnotationsDictionary.ContainsKey(key))
{
var annotations = context.MetadataAnnotationsDictionary[key]
.Where(a => a.Term.FullName().Equals(term) && a.Qualifier == qualifier);
.Where(a => a.Term.FullName().Equals(term, StringComparison.Ordinal) && a.Qualifier == qualifier);

// If there are more than one annotation per term and qualifier returned, we will return null
if (annotations.Count() == 1)
Expand Down
16 changes: 8 additions & 8 deletions src/Microsoft.OData.Client/ArraySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public T this[int index]
/// <returns>true if actually added, false if a duplicate was discovered</returns>
public bool Add(T item, Func<T, T, bool> equalityComparer)
{
if ((null != equalityComparer) && this.Contains(item, equalityComparer))
if ((equalityComparer != null) && this.Contains(item, equalityComparer))
{
return false;
}

int index = this.count++;
if ((null == this.items) || (index == this.items.Length))
if ((this.items == null) || (index == this.items.Length))
{ // grow array in size, with minimum size being 32
Array.Resize<T>(ref this.items, Math.Min(Math.Max(index, 16), Int32.MaxValue / 2) * 2);
}
Expand All @@ -84,7 +84,7 @@ public bool Add(T item, Func<T, T, bool> equalityComparer)
/// <returns>true if the element is contained</returns>
public bool Contains(T item, Func<T, T, bool> equalityComparer)
{
return (0 <= this.IndexOf(item, equalityComparer));
return (this.IndexOf(item, equalityComparer) >= 0);
}

/// <summary>
Expand Down Expand Up @@ -126,7 +126,7 @@ public int IndexOf(T item, Func<T, T, bool> comparer)
public int IndexOf<K>(K item, Func<T, K> select, Func<K, K, bool> comparer)
{
T[] array = this.items;
if (null != array)
if (array != null)
{
int length = this.count;
for (int i = 0; i < length; ++i)
Expand All @@ -148,7 +148,7 @@ public int IndexOf<K>(K item, Func<T, K> select, Func<K, K, bool> comparer)
public T Remove(T item, Func<T, T, bool> equalityComparer)
{
int index = this.IndexOf(item, equalityComparer);
if (0 <= index)
if (index >= 0)
{
item = this.items[index];
this.RemoveAt(index);
Expand All @@ -168,11 +168,11 @@ public void RemoveAt(int index)
array[index] = array[lastIndex];
array[lastIndex] = default(T);

if ((0 == lastIndex) && (256 <= array.Length))
if ((lastIndex == 0) && (array.Length >= 256))
{
this.items = null;
}
else if ((256 < array.Length) && (lastIndex < array.Length / 4))
else if ((array.Length > 256) && (lastIndex < array.Length / 4))
{ // shrink to half size when count is a quarter
Array.Resize(ref this.items, array.Length / 2);
}
Expand All @@ -189,7 +189,7 @@ public void RemoveAt(int index)
/// <param name="comparer">comparer</param>
public void Sort<K>(Func<T, K> selector, Func<K, K, int> comparer)
{
if (null != this.items)
if (this.items != null)
{
SelectorComparer<K> scomp;
scomp.Selector = selector;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OData.Client/Attribute/EntitySetAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class EntitySetAttribute : System.Attribute
/// </summary>
private readonly string entitySet;

/// <summary>Creates a new instance of the <see cref="T:Microsoft.OData.Client.EntitySetAttribute" />.</summary>
/// <summary>Creates a new instance of the <see cref="Microsoft.OData.Client.EntitySetAttribute" />.</summary>
/// <param name="entitySet">The entity set to which the class belongs.</param>
public EntitySetAttribute(string entitySet)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.OData.Client
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class EntityTypeAttribute : System.Attribute
{
/// <summary>Creates a new instance of the <see cref="T:Microsoft.OData.Client.EntityTypeAttribute" /> class.</summary>
/// <summary>Creates a new instance of the <see cref="Microsoft.OData.Client.EntityTypeAttribute" /> class.</summary>
public EntityTypeAttribute()
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Client/Attribute/KeyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class KeyAttribute : System.Attribute
/// <summary>Name of the properties that form the key.</summary>
private readonly ReadOnlyCollection<string> keyNames;

/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Client.KeyAttribute" /> class. </summary>
/// <summary>Initializes a new instance of the <see cref="Microsoft.OData.Client.KeyAttribute" /> class. </summary>
/// <param name="keyName">The string that contains name of the key attribute.</param>
public KeyAttribute(string keyName)
{
Expand All @@ -27,7 +27,7 @@ public KeyAttribute(string keyName)
this.keyNames = new ReadOnlyCollection<string>(new string[1] { keyName });
}

/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Client.KeyAttribute" /> class. </summary>
/// <summary>Initializes a new instance of the <see cref="Microsoft.OData.Client.KeyAttribute" /> class. </summary>
/// <param name="keyNames">An array of string values that contain key attribute names.</param>
public KeyAttribute(params string[] keyNames)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.OData.Client
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public sealed class NamedStreamAttribute : Attribute
{
/// <summary>Creates a new instance of the <see cref="T:Microsoft.OData.Client.NamedStreamAttribute" /> class.</summary>
/// <summary>Creates a new instance of the <see cref="Microsoft.OData.Client.NamedStreamAttribute" /> class.</summary>
/// <param name="name">The name of a binary stream that belongs to the attributed entity.</param>
public NamedStreamAttribute(string name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class OriginalNameAttribute : Attribute
/// <summary>The original name.</summary>
private readonly string originalName;

/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Client.OriginalNameAttribute" /> class. </summary>
/// <summary>Initializes a new instance of the <see cref="Microsoft.OData.Client.OriginalNameAttribute" /> class. </summary>
/// <param name="originalName">The string that contains original name of the variable.</param>
public OriginalNameAttribute(string originalName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OData.Client/BaseEntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Microsoft.OData.Client
{
/// <summary>
/// Base type of entity type to include <see cref="T:Microsoft.OData.Client.DataServiceContext" /> for function and action invocation
/// Base type of entity type to include <see cref="Microsoft.OData.Client.DataServiceContext" /> for function and action invocation
/// </summary>
public class BaseEntityType
{
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.OData.Client/BatchSaveResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,15 @@ private ODataRequestMessageWrapper CreateBatchRequest()
Uri requestUri = UriUtil.CreateUri(this.RequestInfo.BaseUriResolver.GetBaseUriWithSlash(), UriUtil.CreateUri("$batch", UriKind.Relative));
HeaderCollection headers = new HeaderCollection();
headers.SetRequestVersion(Util.ODataVersion4, this.RequestInfo.MaxProtocolVersionAsVersion);
if(useJsonBatch)
if (useJsonBatch)
{
headers.SetHeader(XmlConstants.HttpContentType, CreateApplicationJsonContentType());
}
else
{
headers.SetHeader(XmlConstants.HttpContentType, CreateMultiPartMimeContentType());
}

this.RequestInfo.Format.SetRequestAcceptHeaderForBatch(headers);

return this.CreateTopLevelRequest(XmlConstants.HttpMethodPost, requestUri, headers, this.RequestInfo.HttpStack, null /*descriptor*/);
Expand Down
Loading