private ITuple ChangeTupleConstant(ITuple tuple) { Object[] allArguments = null; Type type = ChangeType(tuple.GetType()); if (type != tuple.GetType()) { allArguments = new Object[tuple.Length]; for (int i = 0; i < tuple.Length; i++) { Object value = tuple[i]; if (value is DateTimeOffset dateTimeOffset) { allArguments[i] = dateTimeOffset.UtcDateTime; } else if (value is Decimal d) { allArguments[i] = (double)d; } else { allArguments[i] = value; } } return(CreateTuple(type, 0)); } return(tuple); ITuple CreateTuple(Type tupleType, int index) { Type[] typeArguments = tupleType.GetGenericArguments(); ITuple restTuple = null; if (typeArguments.Length == 8) { restTuple = CreateTuple(typeArguments[7], index + 7); } var arguments = new Object[typeArguments.Length]; if (restTuple == null) { Array.Copy(allArguments, index, arguments, 0, typeArguments.Length); } else { Array.Copy(allArguments, index, arguments, 0, 7); arguments[7] = restTuple; } return((ITuple)tupleType.GetConstructor(tupleType.GetGenericArguments()).Invoke(arguments)); } }
public static void VerifyAllMocks(ITuple mocks) { Mock[] values = mocks .GetType() .GetFields() .Select(f => f.GetValue(mocks)) .Cast <Mock>() .ToArray(); VerifyAllMocks(values); }
protected void AssertAreSame(ITuple source, ITuple target, int startIndex, int targetStartIndex, int count) { for (int i = 0; i < count; i++) { bool available = source.GetFieldState(i + startIndex).IsAvailable(); try { Assert.AreEqual(available, target.GetFieldState(i + targetStartIndex).IsAvailable()); Assert.AreEqual(source.GetValue(i + startIndex), target.GetValue(i + targetStartIndex)); } catch (AssertionException) { Console.Out.WriteLine(string.Format("Tuple type: {0}", target.GetType().Name)); Console.Out.WriteLine(string.Format("Field Index: {0}", i)); Console.Out.WriteLine(); } } }
public WhereComponent(ITuple alias, Expression <Func <TEntity, bool> > selector) { var aliases = alias.GetType().GetFields(); var aliasesValues = aliases.Select(p => (string)p.GetValue(alias)).ToArray(); IEnumerable <ExpressionProperty> expressionProperties; if (typeof(ITuple).IsAssignableFrom(typeof(TEntity))) { expressionProperties = selector.Parameters[0].ToExpressionPropertyOfTuple(aliasesValues); } else { expressionProperties = new[] { selector.Parameters[0].ToExpressionProperty() } }; ConditionalComponent = new ConditionalComponent((BinaryExpression)selector.Body, expressionProperties); }
protected void AssertAreSame(ITuple dummyTuple, ITuple tuple) { for (int i = 0; i < dummyTuple.Count; i++) { bool available = dummyTuple.GetFieldState(i).IsAvailable(); try { Assert.AreEqual(available, tuple.GetFieldState(i).IsAvailable()); } catch (AssertionException) { Console.Out.WriteLine(string.Format("Tuple type: {0}", tuple.GetType().Name)); Console.Out.WriteLine(string.Format("Field Index: {0}", i)); Console.Out.WriteLine(); } } Assert.AreEqual(dummyTuple.GetHashCode(), tuple.GetHashCode()); Assert.IsTrue(dummyTuple.Equals(tuple)); Assert.IsTrue(tuple.Equals(dummyTuple)); }
public static T Convert <T>(this ITuple tuple) where T : new() { var typedProperties = typeof(T).GetProperties(); var tupleFields = tuple.GetType().GetFields(); if (typedProperties.Length != tupleFields.Length) { throw Api.Create.Exception("Properties count not matching"); } var typedInstance = new T(); for (var i = 0; i < typedProperties.Length; ++i) { var typedProperty = typedProperties[i]; var tupleField = tupleFields[i]; typedProperty.SetValue(typedInstance, tupleField.GetValue(tuple)); } return(typedInstance); }
internal static string ToString(ITuple tuple) { StringBuilder result = new StringBuilder(); result.Append("("); FieldInfo[] fields = tuple.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic); for (int i = 0; i < fields.Length; i++) { if (i > 0) { result.Append(", "); } FieldInfo f = fields[i]; } result.Append(")"); return(result.ToString()); }