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

Remove Castle.Core.Internal.CollectionExtensions #563

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Deprecations:
- Removed support for Code Access Security (CAS). (@stakx, #502)
- Removed support for Remoting. This library no longer defines any types deriving from `MarshalByRefObject`, and `ProxyUtil.IsProxy` (which used to recognize remoting/"transparent" proxies) now tests only for DynamicProxy proxies. (@stakx, #507)
- The following public members have been removed:
- `Castle.Core.Internal.CollectionExtensions` (class)
- `Castle.Core.Internal.Lock` (class) along with all related types and methods
- `Castle.Core.Internal.PermissionUtil.IsGranted` (method)
- `Castle.Core.Pair<,>` (type). Use `System.ValueTuple<,>` or `System.Tuple<,>` instead.
Expand Down
8 changes: 0 additions & 8 deletions ref/Castle.Core-net45.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,14 +1945,6 @@ public static T[] GetTypeAttributes<T>(System.Type type)
where T : System.Attribute { }
public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { }
}
public static class CollectionExtensions
{
public static bool AreEquivalent<T>(System.Collections.Generic.IList<T> listA, System.Collections.Generic.IList<T> listB) { }
public static T Find<T>(this T[] items, System.Predicate<T> predicate) { }
public static T[] FindAll<T>(this T[] items, System.Predicate<T> predicate) { }
public static int GetContentsHashCode<T>(System.Collections.Generic.IList<T> list) { }
public static bool IsNullOrEmpty(this System.Collections.IEnumerable @this) { }
}
public class InternalsVisible
{
public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB";
Expand Down
8 changes: 0 additions & 8 deletions ref/Castle.Core-netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,14 +1939,6 @@ public static T[] GetTypeAttributes<T>(System.Type type)
where T : System.Attribute { }
public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { }
}
public static class CollectionExtensions
{
public static bool AreEquivalent<T>(System.Collections.Generic.IList<T> listA, System.Collections.Generic.IList<T> listB) { }
public static T Find<T>(this T[] items, System.Predicate<T> predicate) { }
public static T[] FindAll<T>(this T[] items, System.Predicate<T> predicate) { }
public static int GetContentsHashCode<T>(System.Collections.Generic.IList<T> list) { }
public static bool IsNullOrEmpty(this System.Collections.IEnumerable @this) { }
}
public class InternalsVisible
{
public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB";
Expand Down
8 changes: 0 additions & 8 deletions ref/Castle.Core-netstandard2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,14 +1939,6 @@ public static T[] GetTypeAttributes<T>(System.Type type)
where T : System.Attribute { }
public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { }
}
public static class CollectionExtensions
{
public static bool AreEquivalent<T>(System.Collections.Generic.IList<T> listA, System.Collections.Generic.IList<T> listB) { }
public static T Find<T>(this T[] items, System.Predicate<T> predicate) { }
public static T[] FindAll<T>(this T[] items, System.Predicate<T> predicate) { }
public static int GetContentsHashCode<T>(System.Collections.Generic.IList<T> list) { }
public static bool IsNullOrEmpty(this System.Collections.IEnumerable @this) { }
}
public class InternalsVisible
{
public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB";
Expand Down
122 changes: 0 additions & 122 deletions src/Castle.Core/Core/Internal/CollectionExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private Expression SetMethodInterceptors(ClassEmitter @class, INamingScope namin

private void EmitLoadGenricMethodArguments(MethodEmitter methodEmitter, MethodInfo method, Reference invocationLocal)
{
var genericParameters = method.GetGenericArguments().FindAll(t => t.IsGenericParameter);
var genericParameters = Array.FindAll(method.GetGenericArguments(), t => t.IsGenericParameter);
var genericParamsArrayLocal = methodEmitter.CodeBuilder.DeclareLocal(typeof(Type[]));
methodEmitter.CodeBuilder.AddStatement(
new AssignStatement(genericParamsArrayLocal, new NewArrayExpression(genericParameters.Length, typeof(Type))));
Expand Down
62 changes: 56 additions & 6 deletions src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ namespace Castle.DynamicProxy
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
#endif

using Castle.Core.Internal;
using Castle.DynamicProxy.Internal;

// prevent collision with new class in netstandard 2.1
using CollectionExtensions = Castle.Core.Internal.CollectionExtensions;

/// <summary>
/// <see cref="ProxyGenerationOptions"/> allows customization of the behavior of proxies created by
/// an <see cref="IProxyGenerator"/> (or proxy types generated by an <see cref="IProxyBuilder"/>).
Expand Down Expand Up @@ -280,7 +277,7 @@ public override bool Equals(object obj)
{
return false;
}
if (!CollectionExtensions.AreEquivalent(AdditionalAttributes, proxyGenerationOptions.AdditionalAttributes))
if (!HasEquivalentAdditionalAttributes(proxyGenerationOptions))
{
return false;
}
Expand All @@ -296,8 +293,61 @@ public override int GetHashCode()
result = 29*result + (Selector != null ? 1 : 0);
result = 29*result + MixinData.GetHashCode();
result = 29*result + (BaseTypeForInterfaceProxy != null ? BaseTypeForInterfaceProxy.GetHashCode() : 0);
result = 29*result + CollectionExtensions.GetContentsHashCode(AdditionalAttributes);
result = 29*result + GetAdditionalAttributesHashCode();
Comment on lines -299 to +296
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetHashCode does not have to be precise (only fast), so we could just use AdditionalAttributes.Count instead of summing the attributes' hash codes. I've not done so because there are some unit tests affected by it; someone in the past must have thought it important that options.GetHashCode differ for different attributes.

return result;
}

private int GetAdditionalAttributesHashCode()
{
var result = 0;
for (var i = 0; i < additionalAttributes.Count; i++)
{
if (additionalAttributes[i] != null)
{
// simply add since order does not matter
result += additionalAttributes[i].GetHashCode();
}
}

return result;
}

private bool HasEquivalentAdditionalAttributes(ProxyGenerationOptions other)
{
var listA = additionalAttributes;
var listB = other.additionalAttributes;

if (listA.Count != listB.Count)
{
return false;
}

// copy contents to another list so that contents can be removed as they are found,
// in order to consider duplicates
var listBAvailableContents = listB.ToList();

// order is not important, just make sure that each entry in A is also found in B
for (var i = 0; i < listA.Count; i++)
{
var found = false;

for (var j = 0; j < listBAvailableContents.Count; j++)
{
if (Equals(listA[i], listBAvailableContents[j]))
{
found = true;
listBAvailableContents.RemoveAt(j);
break;
}
}

if (!found)
{
return false;
}
}

return true;
}
}
}