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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net11.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
Console.WriteLine("Application Started");
using DifferencesBetweenDynamicTypes;

dynamic dynamicPerson = new Person();

dynamicPerson.Name = "Daniel";
dynamicPerson.Age = 30;
dynamicPerson.Address = "1234 Good Street";

dynamicPerson.PrintInfo();
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ public void WhenHandlePropertyChangesMethodIsCalled_ThenChangeDynamicObjectPrope
};

person.Name = "John Doe";
person.Name = "Jane Doe";
((IDictionary<string, object>)person).Remove("Name");

Assert.Equal("John Doe", person.Name);
Assert.False(((IDictionary<string, object>)person).ContainsKey("Name"));
}

[Fact]
Expand All @@ -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<RuntimeBinderException>(() => book.Title);
}

[Fact]
public void WhenReadingMemberThatWasNeverSet_ThenThrowRuntimeBinderException()
{
dynamic dynamicPerson = new Person();

Assert.Throws<RuntimeBinderException>(() => dynamicPerson.Email);
}

[Fact]
public void WhenUsingExpandoObjectAsDictionary_ThenReadValuesWithoutDynamic()
{
IDictionary<string, object?> book = new ExpandoObject();

book["Author"] = "John Doe";
book["Year"] = 2023;

Assert.Equal("John Doe", book["Author"]);
Assert.Equal(2, book.Count);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net11.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,13 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="10.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading