From a5cff1ba8af521aef1482de744d94eb157d2e496 Mon Sep 17 00:00:00 2001 From: Bruce Dunwiddie Date: Sun, 1 Sep 2019 03:40:35 -0500 Subject: [PATCH 1/3] Added code coverage report generation. --- .gitignore | 8 +- Data_Eval/Tests/CodeCoverage.bat | 3 + .../CodeWriting/CSharpCodeWriterTests.cs | 6 +- Data_Eval/Tests/Compilation/CompilerTests.cs | 8 +- .../Tests/Properties/Resources.Designer.cs | 113 --------------- Data_Eval/Tests/Properties/Resources.resx | 130 ------------------ Data_Eval/Tests/Resources/ResourceReader.cs | 45 ++++++ Data_Eval/Tests/Tests.csproj | 21 +-- 8 files changed, 69 insertions(+), 265 deletions(-) create mode 100644 Data_Eval/Tests/CodeCoverage.bat delete mode 100644 Data_Eval/Tests/Properties/Resources.Designer.cs delete mode 100644 Data_Eval/Tests/Properties/Resources.resx create mode 100644 Data_Eval/Tests/Resources/ResourceReader.cs diff --git a/.gitignore b/.gitignore index 6a2e433..4c62865 100644 --- a/.gitignore +++ b/.gitignore @@ -3,12 +3,8 @@ ################################################################################ /Data_Eval/.vs/ -/Data_Eval/Data_Eval/bin -/Data_Eval/Data_Eval/obj +/Data_Eval/*/bin +/Data_Eval/*/obj /Data_Eval/packages -/Data_Eval/Tests/bin -/Data_Eval/Tests/obj -/Data_Eval/TestExternalReference/bin -/Data_Eval/TestExternalReference/obj *.user *.nupkg diff --git a/Data_Eval/Tests/CodeCoverage.bat b/Data_Eval/Tests/CodeCoverage.bat new file mode 100644 index 0000000..cc3b917 --- /dev/null +++ b/Data_Eval/Tests/CodeCoverage.bat @@ -0,0 +1,3 @@ +%userprofile%\.nuget\packages\opencover\4.7.922\tools\OpenCover.Console.exe -target:"%ProgramFiles%\dotnet\dotnet.exe" -targetargs:"test Tests.csproj" -filter:"+[*Eval*]*" -excludebyattribute:"System.CodeDom.Compiler.GeneratedCodeAttribute" -register:user -output:"bin\Debug\CodeCoverageResult.xml" -oldStyle +%userprofile%\.nuget\packages\reportgenerator\4.2.17\tools\net47\ReportGenerator.exe "-reports:bin\Debug\CodeCoverageResult.xml" "-targetdir:bin\Debug\CodeCoverageReport" +pause diff --git a/Data_Eval/Tests/CodeWriting/CSharpCodeWriterTests.cs b/Data_Eval/Tests/CodeWriting/CSharpCodeWriterTests.cs index c963e93..49c4a9d 100644 --- a/Data_Eval/Tests/CodeWriting/CSharpCodeWriterTests.cs +++ b/Data_Eval/Tests/CodeWriting/CSharpCodeWriterTests.cs @@ -8,7 +8,7 @@ using Data.Eval.CodeWriting; -using Tests.Properties; +using Tests.Resources; namespace Tests.CodeWriting { @@ -31,7 +31,7 @@ public void CSharpCodeWriter_SimpleExpression() Assert.AreEqual( // line ending types don't matter. // making sure tests work on Windows and *nix platforms. - Resources.CSharpSimpleExpression.Replace("\r\n", "\n"), + ResourceReader.CSharpSimpleExpression.Replace("\r\n", "\n"), classText.Replace("\r\n", "\n")); } @@ -56,7 +56,7 @@ public void CSharpCodeWriter_SimpleVariable() methods: new List { }); Assert.AreEqual( - Resources.CSharpSimpleVariable.Replace("\r\n", "\n"), + ResourceReader.CSharpSimpleVariable.Replace("\r\n", "\n"), classText.Replace("\r\n", "\n")); } } diff --git a/Data_Eval/Tests/Compilation/CompilerTests.cs b/Data_Eval/Tests/Compilation/CompilerTests.cs index 5b6873b..cb66f97 100644 --- a/Data_Eval/Tests/Compilation/CompilerTests.cs +++ b/Data_Eval/Tests/Compilation/CompilerTests.cs @@ -8,7 +8,7 @@ using Data.Eval.Compilation; -using Tests.Properties; +using Tests.Resources; namespace Tests.Compilation { @@ -21,7 +21,7 @@ public void Compiler_CSharpSimpleExpression() var compiler = new Compiler(); Type newType = compiler.Compile( - Resources.CSharpSimpleExpression); + ResourceReader.CSharpSimpleExpression); Assert.IsNotNull(newType); } @@ -32,7 +32,7 @@ public void Compiler_CSharpSimpleVariable() var compiler = new Compiler(); Type newType = compiler.Compile( - Resources.CSharpSimpleVariable); + ResourceReader.CSharpSimpleVariable); Assert.IsNotNull(newType); } @@ -43,7 +43,7 @@ public void Compiler_CSharpNullableInt() var compiler = new Compiler(); Type newType = compiler.Compile( - Resources.CSharpNullableInt); + ResourceReader.CSharpNullableInt); Assert.IsNotNull(newType); } diff --git a/Data_Eval/Tests/Properties/Resources.Designer.cs b/Data_Eval/Tests/Properties/Resources.Designer.cs deleted file mode 100644 index 724427a..0000000 --- a/Data_Eval/Tests/Properties/Resources.Designer.cs +++ /dev/null @@ -1,113 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Tests.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tests.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to using System; - /// - ///public sealed class CustomEvaluator{ - /// private System.Int32? intValue; - /// public object Eval(){ - /// return intValue + 1; - /// } - ///} - ///. - /// - internal static string CSharpNullableInt { - get { - return ResourceManager.GetString("CSharpNullableInt", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to using System; - /// - ///public sealed class CustomEvaluator{ - /// public object Eval(){ - /// return 1 + 1; - /// } - ///} - ///. - /// - internal static string CSharpSimpleExpression { - get { - return ResourceManager.GetString("CSharpSimpleExpression", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to using System; - /// - ///public sealed class CustomEvaluator{ - /// private System.Int32 intValue; - /// public object Eval(){ - /// return intValue + 1; - /// } - ///} - ///. - /// - internal static string CSharpSimpleVariable { - get { - return ResourceManager.GetString("CSharpSimpleVariable", resourceCulture); - } - } - } -} diff --git a/Data_Eval/Tests/Properties/Resources.resx b/Data_Eval/Tests/Properties/Resources.resx deleted file mode 100644 index d2d28e0..0000000 --- a/Data_Eval/Tests/Properties/Resources.resx +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - ..\Resources\CSharpNullableInt.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - ..\Resources\CSharpSimpleExpression.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - ..\Resources\CSharpSimpleVariable.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - \ No newline at end of file diff --git a/Data_Eval/Tests/Resources/ResourceReader.cs b/Data_Eval/Tests/Resources/ResourceReader.cs new file mode 100644 index 0000000..c2cc878 --- /dev/null +++ b/Data_Eval/Tests/Resources/ResourceReader.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Text; + +namespace Tests.Resources +{ + public static class ResourceReader + { + public static string CSharpNullableInt + { + get + { + using (StreamReader reader = new StreamReader("./Resources/CSharpNullableInt.txt")) + { + return reader.ReadToEnd(); + } + } + } + + public static string CSharpSimpleExpression + { + get + { + using (StreamReader reader = new StreamReader("./Resources/CSharpSimpleExpression.txt")) + { + return reader.ReadToEnd(); + } + } + } + + public static string CSharpSimpleVariable + { + get + { + using (StreamReader reader = new StreamReader("./Resources/CSharpSimpleVariable.txt")) + { + return reader.ReadToEnd(); + } + } + } + + } +} diff --git a/Data_Eval/Tests/Tests.csproj b/Data_Eval/Tests/Tests.csproj index 1832660..b5f2659 100644 --- a/Data_Eval/Tests/Tests.csproj +++ b/Data_Eval/Tests/Tests.csproj @@ -11,6 +11,8 @@ + + @@ -19,18 +21,19 @@ - - True - True - Resources.resx - + + Always + + + Always + + + Always + - - ResXFileCodeGenerator - Resources.Designer.cs - + From de7d1ffb051b2eb1b5541a89a58d1e4498d69083 Mon Sep 17 00:00:00 2001 From: Bruce Dunwiddie Date: Sun, 1 Sep 2019 15:35:00 -0500 Subject: [PATCH 2/3] Cleaned up code smells reported by SonarCloud. Increased code coverage. --- .gitignore | 1 + .../Data_Eval/CodeWriting/CSharpCodeWriter.cs | 4 +- .../Compilation/CompilationException.cs | 6 +++ Data_Eval/Data_Eval/Evaluator.cs | 17 +++---- .../DefaultClassConstructorExpression.cs | 24 ---------- .../ExecuteInstanceMethodExpression.cs | 44 +------------------ .../GetInstanceMemberValueExpression.cs | 2 +- .../SetInstanceMemberValueExpression.cs | 2 +- Data_Eval/Tests/CodeQuality.bat | 9 ++++ Data_Eval/Tests/Compilation/CompilerTests.cs | 25 +++++++++++ .../SetInstanceMemberValueExpressionTests.cs | 33 -------------- .../Tests/Resources/CSharpNullableInt.txt | 2 +- .../Tests/Resources/CSharpSimpleVariable.txt | 2 +- Data_Eval/Tests/Resources/ResourceReader.cs | 23 +++++----- 14 files changed, 64 insertions(+), 130 deletions(-) create mode 100644 Data_Eval/Tests/CodeQuality.bat diff --git a/.gitignore b/.gitignore index 4c62865..489709a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ /Data_Eval/*/bin /Data_Eval/*/obj /Data_Eval/packages +/Data_Eval/Tests/.sonarqube *.user *.nupkg diff --git a/Data_Eval/Data_Eval/CodeWriting/CSharpCodeWriter.cs b/Data_Eval/Data_Eval/CodeWriting/CSharpCodeWriter.cs index cb53924..566279e 100644 --- a/Data_Eval/Data_Eval/CodeWriting/CSharpCodeWriter.cs +++ b/Data_Eval/Data_Eval/CodeWriting/CSharpCodeWriter.cs @@ -37,7 +37,7 @@ public string GetClassTextWithReturn( foreach (Variable variable in variables) { classText.AppendFormat( - "\tprivate {0} {1};\r\n", + "\tpublic {0} {1};\r\n", formatter.GetFullName(variable.Type), variable.Name); } @@ -95,7 +95,7 @@ public string GetClassTextWithNoReturn( foreach (Variable variable in variables) { classText.AppendFormat( - "\tprivate {0} {1};\r\n", + "\tpublic {0} {1};\r\n", formatter.GetFullName(variable.Type), variable.Name); } diff --git a/Data_Eval/Data_Eval/Compilation/CompilationException.cs b/Data_Eval/Data_Eval/Compilation/CompilationException.cs index bb694f5..8fee535 100644 --- a/Data_Eval/Data_Eval/Compilation/CompilationException.cs +++ b/Data_Eval/Data_Eval/Compilation/CompilationException.cs @@ -28,6 +28,12 @@ public CompilationException(string message, Exception innerException) } + private CompilationException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + + } + [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { diff --git a/Data_Eval/Data_Eval/Evaluator.cs b/Data_Eval/Data_Eval/Evaluator.cs index 35c48b4..d4acc40 100644 --- a/Data_Eval/Data_Eval/Evaluator.cs +++ b/Data_Eval/Data_Eval/Evaluator.cs @@ -11,11 +11,11 @@ namespace Data.Eval { public sealed class Evaluator { - private string expression; - private Dictionary variables = new Dictionary(); - private List references = new List(); - private List usings = new List(); - private List methods = new List(); + private readonly string expression; + private readonly Dictionary variables = new Dictionary(); + private readonly List references = new List(); + private readonly List usings = new List(); + private readonly List methods = new List(); private bool initialized = false; private Execution execution = null; private bool callerInitialized = false; @@ -50,11 +50,6 @@ public void SetVariable( { // TODO: check variable naming standards - if (variables == null) - { - variables = new Dictionary(); - } - if (variables.ContainsKey(name)) { variables[name].Value = value; @@ -382,8 +377,6 @@ private sealed class Execution public Func Constructor = null; - public Type Type = null; - public Dictionary Variables = new Dictionary(); } diff --git a/Data_Eval/Data_Eval/Invocation/Expressions/DefaultClassConstructorExpression.cs b/Data_Eval/Data_Eval/Invocation/Expressions/DefaultClassConstructorExpression.cs index ae685c8..faf95d5 100644 --- a/Data_Eval/Data_Eval/Invocation/Expressions/DefaultClassConstructorExpression.cs +++ b/Data_Eval/Data_Eval/Invocation/Expressions/DefaultClassConstructorExpression.cs @@ -18,29 +18,5 @@ public Func GetFunc( return func; } - - // http://stackoverflow.com/questions/390578/creating-instance-of-type-without-default-constructor-in-c-sharp-using-reflectio/16162475#16162475 - - //public static class New - //{ - // public static readonly Func Instance = Creator(); - - // static Func Creator() - // { - // Type t = typeof(T); - // if (t == typeof(string)) - // return Expression.Lambda>(Expression.Constant(string.Empty)).Compile(); - - // if (t.HasDefaultConstructor()) - // return Expression.Lambda>(Expression.New(t)).Compile(); - - // return () => (T)FormatterServices.GetUninitializedObject(t); - // } - //} - - //public static bool HasDefaultConstructor(this Type t) - //{ - // return t.IsValueType || t.GetConstructor(Type.EmptyTypes) != null; - //} } } diff --git a/Data_Eval/Data_Eval/Invocation/Expressions/ExecuteInstanceMethodExpression.cs b/Data_Eval/Data_Eval/Invocation/Expressions/ExecuteInstanceMethodExpression.cs index 8efa280..53bcd16 100644 --- a/Data_Eval/Data_Eval/Invocation/Expressions/ExecuteInstanceMethodExpression.cs +++ b/Data_Eval/Data_Eval/Invocation/Expressions/ExecuteInstanceMethodExpression.cs @@ -18,31 +18,10 @@ public Func GetFuncWithReturn( ParameterExpression allParameters = Expression.Parameter(typeof(object[]), "params"); - ParameterInfo[] methodParameters = method.GetParameters(); - - List parameters = new List(); - - for (int i = 0; i < methodParameters.Length; i++) - { - ParameterInfo parameter = methodParameters[i]; - - ConstantExpression indexExpr = Expression.Constant(i); - - BinaryExpression item = Expression.ArrayIndex( - allParameters, - indexExpr); - - UnaryExpression converted = Expression.Convert( - item, - parameter.ParameterType); - - parameters.Add(converted); - } - Expression methodExp = Expression.Call( Expression.Convert(instance, method.DeclaringType), method, - parameters.ToArray()); + new Expression[] { }); // http://stackoverflow.com/questions/8974837/expression-of-type-system-datetime-cannot-be-used-for-return-type-system-obje if (methodExp.Type.IsValueType) @@ -70,31 +49,12 @@ public Action GetFuncWithNoReturn( ParameterExpression allParameters = Expression.Parameter(typeof(object[]), "params"); - ParameterInfo[] methodParameters = method.GetParameters(); - List parameters = new List(); - for (int i = 0; i < methodParameters.Length; i++) - { - ParameterInfo parameter = methodParameters[i]; - - ConstantExpression indexExpr = Expression.Constant(i); - - BinaryExpression item = Expression.ArrayIndex( - allParameters, - indexExpr); - - UnaryExpression converted = Expression.Convert( - item, - parameter.ParameterType); - - parameters.Add(converted); - } - Expression methodExp = Expression.Call( Expression.Convert(instance, method.DeclaringType), method, - parameters.ToArray()); + new Expression[] { }); Expression> methodCall = Expression.Lambda>( methodExp, diff --git a/Data_Eval/Data_Eval/Invocation/Expressions/GetInstanceMemberValueExpression.cs b/Data_Eval/Data_Eval/Invocation/Expressions/GetInstanceMemberValueExpression.cs index 32c8c0f..4cc6fca 100644 --- a/Data_Eval/Data_Eval/Invocation/Expressions/GetInstanceMemberValueExpression.cs +++ b/Data_Eval/Data_Eval/Invocation/Expressions/GetInstanceMemberValueExpression.cs @@ -14,7 +14,7 @@ public Func GetFunc( { FieldInfo member = instanceType.GetField( memberName, - BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + BindingFlags.Public | BindingFlags.Instance); ParameterExpression instance = Expression.Parameter(typeof(object), "i"); diff --git a/Data_Eval/Data_Eval/Invocation/Expressions/SetInstanceMemberValueExpression.cs b/Data_Eval/Data_Eval/Invocation/Expressions/SetInstanceMemberValueExpression.cs index 660d04d..d9fb2b4 100644 --- a/Data_Eval/Data_Eval/Invocation/Expressions/SetInstanceMemberValueExpression.cs +++ b/Data_Eval/Data_Eval/Invocation/Expressions/SetInstanceMemberValueExpression.cs @@ -14,7 +14,7 @@ public Action GetAction( { FieldInfo member = instanceType.GetField( memberName, - BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + BindingFlags.Public | BindingFlags.Instance); ParameterExpression instance = Expression.Parameter(typeof(object), "i"); ParameterExpression argument = Expression.Parameter(typeof(object), "a"); diff --git a/Data_Eval/Tests/CodeQuality.bat b/Data_Eval/Tests/CodeQuality.bat new file mode 100644 index 0000000..ec46fc3 --- /dev/null +++ b/Data_Eval/Tests/CodeQuality.bat @@ -0,0 +1,9 @@ +rem run CodeCoverage.bat first + +SonarScanner.MSBuild.exe begin /k:"data-eval" /d:sonar.organization="bruce-dunwiddie-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=%SONARQUBE_TOKEN% /d:sonar.cs.opencover.reportsPaths="bin\Debug\CodeCoverageResult.xml" + +"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MsBuild.exe" ..\Data_Eval.sln /t:Rebuild + +SonarScanner.MSBuild.exe end /d:sonar.login=%SONARQUBE_TOKEN% + +pause diff --git a/Data_Eval/Tests/Compilation/CompilerTests.cs b/Data_Eval/Tests/Compilation/CompilerTests.cs index cb66f97..2f42fc3 100644 --- a/Data_Eval/Tests/Compilation/CompilerTests.cs +++ b/Data_Eval/Tests/Compilation/CompilerTests.cs @@ -47,5 +47,30 @@ public void Compiler_CSharpNullableInt() Assert.IsNotNull(newType); } + + [Test] + public void Compiler_Exception() + { + var compiler = new Compiler(); + + string codeToCompile = @" + using System; + + public sealed class CustomEvaluator{ + public System.Int32? intValue; + public object Eval(){ + return intValue + 1 + } + }"; + + CompilationException ex = Assert.Throws( + delegate + { + compiler.Compile(codeToCompile); + }); + + Assert.AreEqual("Class failed to compile.\n\tLine 6: ; expected", ex.Message); + Assert.AreEqual(codeToCompile, ex.GeneratedClassCode); + } } } diff --git a/Data_Eval/Tests/Invocation/Expressions/SetInstanceMemberValueExpressionTests.cs b/Data_Eval/Tests/Invocation/Expressions/SetInstanceMemberValueExpressionTests.cs index b8186eb..b206465 100644 --- a/Data_Eval/Tests/Invocation/Expressions/SetInstanceMemberValueExpressionTests.cs +++ b/Data_Eval/Tests/Invocation/Expressions/SetInstanceMemberValueExpressionTests.cs @@ -35,42 +35,9 @@ public void SetInstanceMemberValueExpression_Int() example.IntValue); } - [Test] - public void SetInstanceMemberValueExpression_PrivateInt() - { - var example = new ExampleClass(); - - var action = new SetInstanceMemberValueExpression() - .GetAction( - typeof(ExampleClass), - "PrivateIntValue"); - - action( - example, - 3); - - Assert.AreEqual( - 3, - example.GetPrivateIntValue()); - } - public class ExampleClass { public int IntValue; - - // warning CS0649: Field 'SetInstanceMemberValueExpressionTests.ExampleClass.PrivateIntValue' - // is never assigned to, and will always have its default value 0 - -#pragma warning disable 0649 - - private int PrivateIntValue; - -#pragma warning restore 0649 - - public int GetPrivateIntValue() - { - return PrivateIntValue; - } } } } diff --git a/Data_Eval/Tests/Resources/CSharpNullableInt.txt b/Data_Eval/Tests/Resources/CSharpNullableInt.txt index dff1cef..adc50aa 100644 --- a/Data_Eval/Tests/Resources/CSharpNullableInt.txt +++ b/Data_Eval/Tests/Resources/CSharpNullableInt.txt @@ -1,7 +1,7 @@ using System; public sealed class CustomEvaluator{ - private System.Int32? intValue; + public System.Int32? intValue; public object Eval(){ return intValue + 1; } diff --git a/Data_Eval/Tests/Resources/CSharpSimpleVariable.txt b/Data_Eval/Tests/Resources/CSharpSimpleVariable.txt index 6b82bd0..2fea193 100644 --- a/Data_Eval/Tests/Resources/CSharpSimpleVariable.txt +++ b/Data_Eval/Tests/Resources/CSharpSimpleVariable.txt @@ -1,7 +1,7 @@ using System; public sealed class CustomEvaluator{ - private System.Int32 intValue; + public System.Int32 intValue; public object Eval(){ return intValue + 1; } diff --git a/Data_Eval/Tests/Resources/ResourceReader.cs b/Data_Eval/Tests/Resources/ResourceReader.cs index c2cc878..c6a6b4a 100644 --- a/Data_Eval/Tests/Resources/ResourceReader.cs +++ b/Data_Eval/Tests/Resources/ResourceReader.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Reflection; using System.Text; namespace Tests.Resources @@ -12,10 +11,7 @@ public static string CSharpNullableInt { get { - using (StreamReader reader = new StreamReader("./Resources/CSharpNullableInt.txt")) - { - return reader.ReadToEnd(); - } + return ReadResourceFile("CSharpNullableInt.txt"); } } @@ -23,10 +19,7 @@ public static string CSharpSimpleExpression { get { - using (StreamReader reader = new StreamReader("./Resources/CSharpSimpleExpression.txt")) - { - return reader.ReadToEnd(); - } + return ReadResourceFile("CSharpSimpleExpression.txt"); } } @@ -34,12 +27,16 @@ public static string CSharpSimpleVariable { get { - using (StreamReader reader = new StreamReader("./Resources/CSharpSimpleVariable.txt")) - { - return reader.ReadToEnd(); - } + return ReadResourceFile("CSharpSimpleVariable.txt"); } } + private static string ReadResourceFile(string fileName) + { + using (StreamReader reader = new StreamReader("./Resources/" + fileName)) + { + return reader.ReadToEnd(); + } + } } } From 0d296b2e3dc7ab6090c4df7b5b49b2aee398b614 Mon Sep 17 00:00:00 2001 From: Bruce Dunwiddie Date: Sun, 1 Sep 2019 15:41:08 -0500 Subject: [PATCH 3/3] More SonarCloud reported code smells cleanup. --- Data_Eval/Data_Eval/Evaluator.cs | 8 ++++---- .../Expressions/ExecuteInstanceMethodExpression.cs | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Data_Eval/Data_Eval/Evaluator.cs b/Data_Eval/Data_Eval/Evaluator.cs index d4acc40..f789d5e 100644 --- a/Data_Eval/Data_Eval/Evaluator.cs +++ b/Data_Eval/Data_Eval/Evaluator.cs @@ -304,16 +304,16 @@ public T Eval() public static object Eval(string expression) { - string caller = Assembly.GetCallingAssembly().Location; + string callerLocation = Assembly.GetCallingAssembly().Location; - return new Evaluator(expression).EvalInternal(caller); + return new Evaluator(expression).EvalInternal(callerLocation); } public static T Eval(string expression) { - string caller = Assembly.GetCallingAssembly().Location; + string callerLocation = Assembly.GetCallingAssembly().Location; - return (T) new Evaluator(expression).EvalInternal(caller); + return (T) new Evaluator(expression).EvalInternal(callerLocation); } public void Exec() diff --git a/Data_Eval/Data_Eval/Invocation/Expressions/ExecuteInstanceMethodExpression.cs b/Data_Eval/Data_Eval/Invocation/Expressions/ExecuteInstanceMethodExpression.cs index 53bcd16..e93e4b0 100644 --- a/Data_Eval/Data_Eval/Invocation/Expressions/ExecuteInstanceMethodExpression.cs +++ b/Data_Eval/Data_Eval/Invocation/Expressions/ExecuteInstanceMethodExpression.cs @@ -49,8 +49,6 @@ public Action GetFuncWithNoReturn( ParameterExpression allParameters = Expression.Parameter(typeof(object[]), "params"); - List parameters = new List(); - Expression methodExp = Expression.Call( Expression.Convert(instance, method.DeclaringType), method,