File DefaultContractResolver.cs
has 944 lines of code (exceeds 250 allowed). Consider refactoring. Open
using System;
using System.Collections;
#if !(NET35 || NET20 || PORTABLE || PORTABLE40)
using System.Collections.Concurrent;
#endif
Class DefaultContractResolver
has 43 methods (exceeds 20 allowed). Consider refactoring. Open
public class DefaultContractResolver : IContractResolver
{
private static readonly IContractResolver _instance = new DefaultContractResolver(true);
internal static IContractResolver Instance
Method GetSerializableMembers
has a Cognitive Complexity of 50 (exceeds 20 allowed). Consider refactoring. Open
protected virtual List<MemberInfo> GetSerializableMembers(Type objectType)
{
bool ignoreSerializableAttribute;
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
ignoreSerializableAttribute = IgnoreSerializableAttribute;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method SetPropertySettingsFromAttributes
has 94 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void SetPropertySettingsFromAttributes(JsonProperty property, object attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess)
{
#if !NET20
DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(declaringType);
Method GetSerializableMembers
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected virtual List<MemberInfo> GetSerializableMembers(Type objectType)
{
bool ignoreSerializableAttribute;
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
ignoreSerializableAttribute = IgnoreSerializableAttribute;
Method GetCallbackMethodsForType
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void GetCallbackMethodsForType(Type type, out List<SerializationCallback> onSerializing, out List<SerializationCallback> onSerialized, out List<SerializationCallback> onDeserializing, out List<SerializationCallback> onDeserialized, out List<SerializationErrorCallback> onError)
{
onSerializing = null;
onSerialized = null;
onDeserializing = null;
Method CreateObjectContract
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected virtual JsonObjectContract CreateObjectContract(Type objectType)
{
JsonObjectContract contract = new JsonObjectContract(objectType);
InitializeContract(contract);
Method SetExtensionDataDelegates
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static void SetExtensionDataDelegates(JsonObjectContract contract, MemberInfo member)
{
JsonExtensionDataAttribute extensionDataAttribute = ReflectionUtils.GetAttribute<JsonExtensionDataAttribute>(member);
if (extensionDataAttribute == null)
return;
Method ResolveCallbackMethods
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void ResolveCallbackMethods(JsonContract contract, Type t)
{
List<SerializationCallback> onSerializing;
List<SerializationCallback> onSerialized;
List<SerializationCallback> onDeserializing;
Method CreateContract
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected virtual JsonContract CreateContract(Type objectType)
{
if (IsJsonPrimitiveType(objectType))
return CreatePrimitiveContract(objectType);
Method GetExtensionDataMemberForType
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private MemberInfo GetExtensionDataMemberForType(Type type)
{
IEnumerable<MemberInfo> members = GetClassHierarchyForType(type).SelectMany(baseType =>
{
IList<MemberInfo> m = new List<MemberInfo>();
Method SetPropertySettingsFromAttributes
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
private void SetPropertySettingsFromAttributes(JsonProperty property, object attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess)
{
#if !NET20
DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(declaringType);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method GetCallbackMethodsForType
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private void GetCallbackMethodsForType(Type type, out List<SerializationCallback> onSerializing, out List<SerializationCallback> onSerialized, out List<SerializationCallback> onDeserializing, out List<SerializationCallback> onDeserialized, out List<SerializationErrorCallback> onError)
Method SetPropertySettingsFromAttributes
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private void SetPropertySettingsFromAttributes(JsonProperty property, object attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess)
Method IsValidCallback
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static bool IsValidCallback(MethodInfo method, ParameterInfo[] parameters, Type attributeType, MethodInfo currentCallback, ref Type prevAttributeType)
Avoid too many return
statements within this method. Open
return extensionDataMember;
Avoid too many return
statements within this method. Open
return CreateArrayContract(objectType);
Avoid too many return
statements within this method. Open
return CreateObjectContract(objectType);
Avoid too many return
statements within this method. Open
return CreateISerializableContract(objectType);
Avoid too many return
statements within this method. Open
return CreateLinqContract(objectType);
Avoid too many return
statements within this method. Open
return CreateDictionaryContract(objectType);
Avoid too many return
statements within this method. Open
return CreateStringContract(objectType);
Avoid too many return
statements within this method. Open
return CreateDynamicContract(objectType);
Avoid too many return
statements within this method. Open
return CreatePrimitiveContract(t);
Method GetCallbackMethodsForType
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
private void GetCallbackMethodsForType(Type type, out List<SerializationCallback> onSerializing, out List<SerializationCallback> onSerialized, out List<SerializationCallback> onDeserializing, out List<SerializationCallback> onDeserialized, out List<SerializationErrorCallback> onError)
{
onSerializing = null;
onSerialized = null;
onDeserializing = null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 5 locations. Consider refactoring. Open
if (IsValidCallback(method, parameters, typeof(OnDeserializedAttribute), currentOnDeserialized, ref prevAttributeType))
{
onDeserialized = onDeserialized ?? new List<SerializationCallback>();
onDeserialized.Add(JsonContract.CreateSerializationCallback(method));
currentOnDeserialized = method;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 71.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 5 locations. Consider refactoring. Open
if (IsValidCallback(method, parameters, typeof(OnSerializedAttribute), currentOnSerialized, ref prevAttributeType))
{
onSerialized = onSerialized ?? new List<SerializationCallback>();
onSerialized.Add(JsonContract.CreateSerializationCallback(method));
currentOnSerialized = method;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 71.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 5 locations. Consider refactoring. Open
if (IsValidCallback(method, parameters, typeof(OnDeserializingAttribute), currentOnDeserializing, ref prevAttributeType))
{
onDeserializing = onDeserializing ?? new List<SerializationCallback>();
onDeserializing.Add(JsonContract.CreateSerializationCallback(method));
currentOnDeserializing = method;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 71.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 5 locations. Consider refactoring. Open
if (IsValidCallback(method, parameters, typeof(OnSerializingAttribute), currentOnSerializing, ref prevAttributeType))
{
onSerializing = onSerializing ?? new List<SerializationCallback>();
onSerializing.Add(JsonContract.CreateSerializationCallback(method));
currentOnSerializing = method;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 71.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 5 locations. Consider refactoring. Open
if (IsValidCallback(method, parameters, typeof(OnErrorAttribute), currentOnError, ref prevAttributeType))
{
onError = onError ?? new List<SerializationErrorCallback>();
onError.Add(JsonContract.CreateSerializationErrorCallback(method));
currentOnError = method;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 71.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76