diff --git a/csharp-advanced-topics/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes.csproj b/csharp-advanced-topics/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes.csproj
index f02677bf64..5bf6c9b8cf 100644
--- a/csharp-advanced-topics/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes.csproj
+++ b/csharp-advanced-topics/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes.csproj
@@ -2,7 +2,7 @@
Exe
- net7.0
+ net11.0
enable
enable
diff --git a/csharp-advanced-topics/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes/Program.cs b/csharp-advanced-topics/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes/Program.cs
index ee70bff2f0..0c446a976a 100644
--- a/csharp-advanced-topics/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes/Program.cs
+++ b/csharp-advanced-topics/DifferencesBetweenDynamicTypes/DifferencesBetweenDynamicTypes/Program.cs
@@ -1 +1,9 @@
-Console.WriteLine("Application Started");
\ No newline at end of file
+using DifferencesBetweenDynamicTypes;
+
+dynamic dynamicPerson = new Person();
+
+dynamicPerson.Name = "Daniel";
+dynamicPerson.Age = 30;
+dynamicPerson.Address = "1234 Good Street";
+
+dynamicPerson.PrintInfo();
diff --git a/csharp-advanced-topics/DifferencesBetweenDynamicTypes/Tests/DynamicTypesUnitTest.cs b/csharp-advanced-topics/DifferencesBetweenDynamicTypes/Tests/DynamicTypesUnitTest.cs
index c35d350872..224e1c0448 100644
--- a/csharp-advanced-topics/DifferencesBetweenDynamicTypes/Tests/DynamicTypesUnitTest.cs
+++ b/csharp-advanced-topics/DifferencesBetweenDynamicTypes/Tests/DynamicTypesUnitTest.cs
@@ -92,8 +92,10 @@ public void WhenHandlePropertyChangesMethodIsCalled_ThenChangeDynamicObjectPrope
};
person.Name = "John Doe";
+ person.Name = "Jane Doe";
+ ((IDictionary)person).Remove("Name");
- Assert.Equal("John Doe", person.Name);
+ Assert.False(((IDictionary)person).ContainsKey("Name"));
}
[Fact]
@@ -109,4 +111,32 @@ public void WhenDynamicObjectIsInherited_ThenSetDynamicObjectValues()
Assert.Equal(30, dynamicPerson.Age);
Assert.Equal("1234 Good Street", dynamicPerson.Address);
}
+
+ [Fact]
+ public void WhenReadingMissingExpandoObjectMember_ThenThrowRuntimeBinderException()
+ {
+ dynamic book = new ExpandoObject();
+
+ Assert.Throws(() => book.Title);
+ }
+
+ [Fact]
+ public void WhenReadingMemberThatWasNeverSet_ThenThrowRuntimeBinderException()
+ {
+ dynamic dynamicPerson = new Person();
+
+ Assert.Throws(() => dynamicPerson.Email);
+ }
+
+ [Fact]
+ public void WhenUsingExpandoObjectAsDictionary_ThenReadValuesWithoutDynamic()
+ {
+ IDictionary book = new ExpandoObject();
+
+ book["Author"] = "John Doe";
+ book["Year"] = 2023;
+
+ Assert.Equal("John Doe", book["Author"]);
+ Assert.Equal(2, book.Count);
+ }
}
\ No newline at end of file
diff --git a/csharp-advanced-topics/DifferencesBetweenDynamicTypes/Tests/Tests.csproj b/csharp-advanced-topics/DifferencesBetweenDynamicTypes/Tests/Tests.csproj
index 1e7804ee89..e5016c41d4 100644
--- a/csharp-advanced-topics/DifferencesBetweenDynamicTypes/Tests/Tests.csproj
+++ b/csharp-advanced-topics/DifferencesBetweenDynamicTypes/Tests/Tests.csproj
@@ -1,7 +1,7 @@
- net7.0
+ net11.0
enable
enable
@@ -10,13 +10,13 @@
-
-
-
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all