-
Notifications
You must be signed in to change notification settings - Fork 13
fix #35 #38
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
fix #35 #38
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -347,7 +347,10 @@ private static bool ShouldDeepCloneStructReadonlyFields(Type type) | |||||||||||
|
|
||||||||||||
| internal static object? GenerateProcessMethod(Type realType, bool asObject) => GenerateProcessMethod(realType, asObject && realType.IsValueType(), new ExpressionPosition(0, 0)); | ||||||||||||
| public static bool IsListType(Type type) => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>); | ||||||||||||
| public static bool IsSetType(Type type) => type.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ISet<>)); | ||||||||||||
| public static bool IsSetType(Type type) => GetSetInterface(type) is not null; | ||||||||||||
|
|
||||||||||||
| private static Type? GetSetInterface(Type type) => | ||||||||||||
| type.GetInterfaces().FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ISet<>)); | ||||||||||||
|
|
||||||||||||
| public static bool IsConcurrentBagOrQueue(Type type) | ||||||||||||
| { | ||||||||||||
|
|
@@ -1862,7 +1865,14 @@ private static object GenerateProcessSetMethod(Type type, ExpressionPosition pos | |||||||||||
| return Expression.Lambda<Func<object, FastCloneState, object>>(pFrom, pFrom, pState).Compile(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| Type elementType = type.GenericArguments()[0]; | ||||||||||||
| Type? setInterface = GetSetInterface(type); | ||||||||||||
| if (setInterface is null) | ||||||||||||
| return GenerateMemberwiseCloner(type, position); | ||||||||||||
|
|
||||||||||||
| Type[] genericArguments = type.GenericArguments(); | ||||||||||||
| Type elementType = genericArguments.Length > 0 | ||||||||||||
| ? genericArguments[0] | ||||||||||||
| : setInterface.GetGenericArguments()[0]; | ||||||||||||
|
||||||||||||
| Type[] genericArguments = type.GenericArguments(); | |
| Type elementType = genericArguments.Length > 0 | |
| ? genericArguments[0] | |
| : setInterface.GetGenericArguments()[0]; | |
| Type elementType = setInterface.GetGenericArguments()[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenerateProcessMethodalready branches intoGenerateProcessSetMethodonly whenIsSetType(type)is true, andIsSetTypeusesGetSetInterface(type).GenerateProcessSetMethodthen callsGetSetInterface(type)again and has asetInterface is nullfallback that should be unreachable. Consider computing the set interface once (e.g., return it from the predicate or pass it intoGenerateProcessSetMethod) to avoid the extraGetInterfaces()scan and dead branch.