Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified samples/docx/TestIfStatement.docx
Binary file not shown.
51 changes: 33 additions & 18 deletions src/MiniWord/MiniWord.Implment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ private static bool EvaluateStatement(string tagValue, string comparisonOperator
var tagValueEvaluation = EvaluateValue(tagValue);

switch (tagValueEvaluation)
{
case double dtg when double.TryParse(value, out var doubleNumber):
{
case double dtg:
if(double.TryParse(value, out var doubleNumber)) {
switch (comparisonOperator)
{
case "==":
Expand All @@ -256,9 +257,14 @@ private static bool EvaluateStatement(string tagValue, string comparisonOperator
checkStatement = dtg <= doubleNumber;
break;
}
} else {
checkStatement = comparisonOperator == "!=";
}

break;
case int itg when int.TryParse(value, out var intNumber):
break;
case int itg:
if(int.TryParse(value, out var intNumber))
{
switch (comparisonOperator)
{
case "==":
Expand All @@ -280,9 +286,14 @@ private static bool EvaluateStatement(string tagValue, string comparisonOperator
checkStatement = itg <= intNumber;
break;
}
} else {
checkStatement = comparisonOperator == "!=";
}

break;
case DateTime dttg when DateTime.TryParse(value, out var date):
break;
case DateTime dttg:
if(DateTime.TryParse(value, out var date))
{
switch (comparisonOperator)
{
case "==":
Expand All @@ -304,18 +315,22 @@ private static bool EvaluateStatement(string tagValue, string comparisonOperator
checkStatement = dttg <= date;
break;
}
} else {
checkStatement = comparisonOperator == "!=";
}

break;
case string stg:
switch (comparisonOperator)
{
case "==":
checkStatement = stg == value;
break;
case "!=":
checkStatement = stg != value;
break;
}

break;
case string stg:
switch (comparisonOperator)
{
case "==":
checkStatement = stg == value;
break;
case "!=":
checkStatement = stg != value;
break;
}
break;
case bool btg when bool.TryParse(value, out var boolean):
switch (comparisonOperator)
Expand All @@ -327,7 +342,7 @@ private static bool EvaluateStatement(string tagValue, string comparisonOperator
checkStatement = btg == boolean;
break;
}

break;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/MiniWordTests/MiniWordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void MiniWordIfStatement_FirstIf()
["VIP"] = true,
["Points"] = 123,
["APP"] = "Demo APP",
["NullVal"] = null,
};
MiniWord.SaveAsByTemplate(path, templatePath, value);
//Console.WriteLine(path);
Expand All @@ -153,6 +154,9 @@ public void MiniWordIfStatement_FirstIf()
Assert.Contains("Points are greater than 100", docXml);
Assert.Contains("CreateDate is not less than 2021", docXml);
Assert.DoesNotContain("CreateDate is not greater than 2021", docXml);
Assert.Contains("CreateDate is not equal to MiniSofteware", docXml);
Assert.Contains("CreateDate is not NULL", docXml);
Assert.Contains("NullVal is NULL", docXml);
}

[Fact]
Expand Down