tests/DotNetCommon.Test/Extensions/GenericExtensions/GettingPropertyNamesTests.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
namespace DotNetCommon.Test.Extensions.GenericExtensions
{
using System;
using System.Dynamic;
using NUnit.Framework;
using Shouldly;
using DotNetCommon.Extensions;
[TestFixture]
internal sealed class GettingPropertyNamesTests
{
[Test]
public void When_getting_property_names_of_expando_object()
{
dynamic expando = new ExpandoObject();
expando.Name = "Foo";
expando.Age = 1;
var propertyNames = ((object)expando).GetPropertyNames(true, false);
propertyNames.ShouldNotBeNull();
propertyNames.Length.ShouldBe(2);
propertyNames[0].ShouldBe("Name");
propertyNames[1].ShouldBe("Age");
}
[Test]
public void When_getting_property_names_of_a_class()
{
var model = new SomeClass();
var propertyNames = ((object)model).GetPropertyNames(true, false);
propertyNames.ShouldNotBeNull();
propertyNames.Length.ShouldBe(2);
propertyNames[0].ShouldBe("Name");
propertyNames[1].ShouldBe("Age");
}
[Test]
public void When_getting_property_names_of_a_struct()
{
var model = new SomeStruct();
var propertyNames = ((object)model).GetPropertyNames(true, false);
propertyNames.ShouldNotBeNull();
propertyNames.Length.ShouldBe(2);
propertyNames[0].ShouldBe("Name");
propertyNames[1].ShouldBe("Age");
}
private sealed class SomeClass
{
public string Name { get; set; }
public int Age { get; set; }
private string AnotherName { get; set; }
public static int AnotherAge { get; set; }
}
private struct SomeStruct
{
public string Name { get; set; }
后面还有 6 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
