public static Expression GenerateDictionaryGenericExpression(List <ParameterExpression> variables, ParameterExpression source, ParameterExpression clone, Type sourceType, ParameterExpression refTrackerParam) { var ctor = sourceType.GetConstructor(new Type[0]); if (ctor == null) { throw new MissingConstructorException("Type " + sourceType + " must have a public constructor without parameter."); } var genericDictionaryType = DictionaryHelper.GetDictionaryType(sourceType); var comparerConstructor = DictionaryHelper.GetComparerConstructor(sourceType); var cloneDictionaryWithDefaultComparer = CloneDictionaryWithDefaultComparer(genericDictionaryType, variables, source, clone, sourceType, refTrackerParam); if (comparerConstructor == null) { return(cloneDictionaryWithDefaultComparer); } return(Expression.IfThenElse(Expression.IsTrue(Expression.Call(DictionaryMih.IsDefaultEqualityComparer(), Expression.Constant(genericDictionaryType.GetGenericArguments()[0]), Expression.Property(source, nameof(Dictionary <int, int> .Comparer)))), cloneDictionaryWithDefaultComparer, CloneDictionaryWithCustomComparer(genericDictionaryType, comparerConstructor, variables, source, clone, sourceType, refTrackerParam))); }
public static Expression GenerateDictionaryGenericExpression(Type type, List <ParameterExpression> variables, ParameterExpression outputStream, ParameterExpression objToSerialize, ParameterExpression objTracking) { var ctor = type.GetConstructor(new Type[0]); if (ctor == null) { throw new MissingConstructorException("Type " + type + " must have a public constructor without parameter."); } var notTrackedExpressions = new List <Expression>(); var genericDictionaryType = DictionaryHelper.GetDictionaryType(type); var comparerConstructor = DictionaryHelper.GetComparerConstructor(type); var serializeDictionaryWithDefaultComparer = SerializeDictionaryWithDefaultComparer(genericDictionaryType, variables, type, outputStream, objToSerialize, objTracking); if (comparerConstructor == null) { notTrackedExpressions.Add(serializeDictionaryWithDefaultComparer); } else { notTrackedExpressions.Add(Expression.IfThenElse(Expression.IsTrue(Expression.Call(DictionaryMih.IsDefaultEqualityComparer(), Expression.Constant(genericDictionaryType.GetGenericArguments()[0]), Expression.Property(objToSerialize, nameof(Dictionary <int, int> .Comparer)))), serializeDictionaryWithDefaultComparer, SerializeDictionaryWithCustomComparer(genericDictionaryType, variables, type, outputStream, objToSerialize, objTracking))); } return(Serializer.GenerateNullTrackedOrUntrackedExpression(type, outputStream, objToSerialize, objTracking, notTrackedExpressions, variables)); }