public override string ToPresentation(ICharacteristic characteristic) { var valueType = ReflectionUtils.GetGenericTypeArguments(characteristic.GetType()).First().GetCorrectTypeName(); var id = characteristic.Id; var value = SourceCodeHelper.ToSourceCode(characteristic.ObjectValue); return($"Characteristic<{valueType}>.Create(\"{id}\").Mutate({value})"); }
public override string ToPresentation(JobMode jobMode, Characteristic characteristic) { // TODO: DO NOT hardcode Characteristic suffix var id = characteristic.Id; var type = characteristic.DeclaringType.FullName; var value = SourceCodeHelper.ToSourceCode(characteristic[jobMode]); return($"{type}.{id}Characteristic[job] = {value}"); }
internal static object[] CreateForParams(MemberInfo source, object[] values) { if (values.IsEmpty() || values.All(value => SourceCodeHelper.IsCompilationTimeConstant(value))) { return(values); } return(values.Select((value, index) => new SmartParamameter(source, value, index)).ToArray()); }
public override string ToPresentation(object characteristicValue, Characteristic characteristic) { // TODO: DO NOT hardcode Characteristic suffix string id = characteristic.Id; string type = characteristic.DeclaringType.FullName; string value = SourceCodeHelper.ToSourceCode(characteristicValue); return($"{type}.{id}Characteristic[job] = {value}"); }
public void ToSourceCodeSimpleTest(object original, string expected) { string actual = SourceCodeHelper.ToSourceCode(original); output.WriteLine("ORIGINAL : " + original + " (" + original?.GetType() + ")"); output.WriteLine("ACTUAL : " + actual); output.WriteLine("EXPRECTED : " + expected); Assert.Equal(expected, actual); }
internal static object[] CreateForParams(MemberInfo source, object[] values) { // IEnumerable<object> if (values.IsEmpty() || values.All(SourceCodeHelper.IsCompilationTimeConstant)) { return(values); } // IEnumerable<object[]> if (values.All(value => value is object[] array && array.Length == 1 && SourceCodeHelper.IsCompilationTimeConstant(array[0]))) { return(values.Select(x => ((object[])x)[0]).ToArray()); } return(values.Select((value, index) => new SmartParameter(source, value, index)).ToArray()); }
internal static IParam FromObject(object array) { var type = array.GetType(); if (!type.IsArray) { throw new InvalidOperationException("The argument must be an array"); } if (!SourceCodeHelper.IsCompilationTimeConstant(type.GetElementType())) { throw new InvalidOperationException("The argument must be an array of primitives"); } var arrayParamType = typeof(ArrayParam <>).MakeGenericType(type.GetElementType()); return((IParam)arrayParamType.GetMethod(nameof(ForPrimitives), BindingFlags.Public | BindingFlags.Static).Invoke(null, new [] { array })); }
private static string GetParamsContent(Benchmark benchmark) { return(string.Join( string.Empty, benchmark.Parameters.Items.Select( parameter => $"{(parameter.IsStatic ? "" : "instance.")}{parameter.Name} = {SourceCodeHelper.ToSourceCode(parameter.Value)};"))); }
public string ToSourceCode() => $"new {typeof(T).GetCorrectCSharpTypeName()}[] {{ {string.Join(", ", array.Select(item => toSourceCode?.Invoke(item) ?? SourceCodeHelper.ToSourceCode(item)))} }}";
public string ToSourceCode() => $"new[] {{ {string.Join(", ", array.Select(item => toSourceCode?.Invoke(item) ?? SourceCodeHelper.ToSourceCode(item)))} }}";