本文整理汇总了C#中System.Linq.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.GetType方法的具体用法?C# System.Linq.GetType怎么用?C# System.Linq.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HtmlAttributePropertyHelper_ReturnsNameCorrectly
public void HtmlAttributePropertyHelper_ReturnsNameCorrectly()
{
// Arrange
var anonymous = new { foo = "bar" };
var property = anonymous.GetType().GetTypeInfo().DeclaredProperties.First();
// Act
var helper = new HtmlAttributePropertyHelper(property);
// Assert
Assert.Equal("foo", property.Name);
Assert.Equal("foo", helper.Name);
}
示例2: HtmlAttributePropertyHelper_ReturnsValueCorrectly_ForValueTypes
public void HtmlAttributePropertyHelper_ReturnsValueCorrectly_ForValueTypes()
{
// Arrange
var anonymous = new { foo = 32 };
var property = anonymous.GetType().GetProperties().First();
// Act
var helper = new HtmlAttributePropertyHelper(property);
// Assert
Assert.Equal("foo", helper.Name);
Assert.Equal(32, helper.GetValue(anonymous));
}
示例3: HtmlAttributePropertyHelper_RenamesPropertyNames
public void HtmlAttributePropertyHelper_RenamesPropertyNames()
{
// Arrange
var anonymous = new { bar_baz = "foo" };
var property = anonymous.GetType().GetTypeInfo().DeclaredProperties.First();
// Act
var helper = new HtmlAttributePropertyHelper(property);
// Assert
Assert.Equal("bar_baz", property.Name);
Assert.Equal("bar-baz", helper.Name);
}
示例4: PropertyHelperReturnsValueCorrectly
public void PropertyHelperReturnsValueCorrectly()
{
// Arrange
var anonymous = new { bar = "baz" };
PropertyInfo property = anonymous.GetType().GetProperties().First();
// Act
PropertyHelper helper = new PropertyHelper(property);
// Assert
Assert.Equal("bar", helper.Name);
Assert.Equal("baz", helper.GetValue(anonymous));
}
示例5: PropertyHelperReturnsValueCorrectlyForValueTypes
public void PropertyHelperReturnsValueCorrectlyForValueTypes()
{
// Arrange
var anonymous = new { foo = 32 };
PropertyInfo property = anonymous.GetType().GetProperties().First();
// Act
PropertyHelper helper = new PropertyHelper(property);
// Assert
Assert.Equal("foo", helper.Name);
Assert.Equal(32, helper.GetValue(anonymous));
}
示例6: PropertyHelperReturnsNameCorrectly
public void PropertyHelperReturnsNameCorrectly()
{
// Arrange
var anonymous = new { foo = "bar" };
PropertyInfo property = anonymous.GetType().GetProperties().First();
// Act
PropertyHelper helper = new PropertyHelper(property);
// Assert
Assert.Equal("foo", property.Name);
Assert.Equal("foo", helper.Name);
}
示例7: GetEntityKeyValue_MultipleKeys_DerivedType
public void GetEntityKeyValue_MultipleKeys_DerivedType()
{
// Arrange
Mock<IEntityTypeConfiguration> baseEntityType = new Mock<IEntityTypeConfiguration>();
var entityInstance = new { Key1 = "key1", Key2 = 2, Key3 = true };
PrimitivePropertyConfiguration[] keys =
{
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key1"), baseEntityType.Object),
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key2"), baseEntityType.Object),
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key3"), baseEntityType.Object),
};
baseEntityType.Setup(e => e.Keys).Returns(keys);
Mock<IEntityTypeConfiguration> derivedEntityType = new Mock<IEntityTypeConfiguration>();
derivedEntityType.Setup(e => e.BaseType).Returns(baseEntityType.Object);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(new EntityInstanceContext { EntityInstance = entityInstance }, derivedEntityType.Object);
// Assert
Assert.Equal("Key1='key1',Key2=2,Key3=true", keyValue);
}
示例8: GetEntityKeyValue_DerivedType
public void GetEntityKeyValue_DerivedType()
{
// Arrange
var entityInstance = new { Key = "key" };
Mock<IEntityTypeConfiguration> baseEntityType = new Mock<IEntityTypeConfiguration>();
PrimitivePropertyConfiguration[] keys = { new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key"), baseEntityType.Object) };
baseEntityType.Setup(e => e.Keys).Returns(keys);
Mock<IEntityTypeConfiguration> derivedEntityType = new Mock<IEntityTypeConfiguration>();
derivedEntityType.Setup(e => e.BaseType).Returns(baseEntityType.Object);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(new EntityInstanceContext { EntityInstance = entityInstance }, derivedEntityType.Object);
// Assert
Assert.Equal("'key'", keyValue);
}
示例9: GetEntityKeyValue_ThrowsForNullKeys_WithMultipleKeys
public void GetEntityKeyValue_ThrowsForNullKeys_WithMultipleKeys()
{
// Arrange
IStructuralTypeConfiguration structuralType = new Mock<IStructuralTypeConfiguration>().Object;
var entityInstance = new { Key1 = "abc", Key2 = "def", Key3 = (string)null };
PrimitivePropertyConfiguration[] keys =
{
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key1"), structuralType),
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key2"), structuralType),
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key3"), structuralType),
};
Mock<IEntityTypeConfiguration> entityType = new Mock<IEntityTypeConfiguration>();
entityType.Setup(e => e.Keys).Returns(keys);
entityType.Setup(e => e.FullName).Returns("EntityType");
// Act & Assert
Assert.Throws<InvalidOperationException>(
() => ConventionsHelpers.GetEntityKeyValue(new EntityInstanceContext { EntityInstance = entityInstance }, entityType.Object),
"Key property 'Key3' of type 'EntityType' is null. Key properties cannot have null values.");
}
示例10: GetEntityKeyValue_SingleKey_DifferentDataTypes
public void GetEntityKeyValue_SingleKey_DifferentDataTypes(object value, object expectedValue)
{
// Arrange
IStructuralTypeConfiguration structuralType = new Mock<IStructuralTypeConfiguration>().Object;
var entityInstance = new { Key = value };
PrimitivePropertyConfiguration[] keys = { new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key"), structuralType) };
Mock<IEntityTypeConfiguration> entityType = new Mock<IEntityTypeConfiguration>();
entityType
.Setup(e => e.Keys)
.Returns(keys);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(new EntityInstanceContext { EntityInstance = entityInstance }, entityType.Object);
// Assert
Assert.Equal(expectedValue, keyValue);
}
示例11: update_sql_is_sane
public void update_sql_is_sane()
{
var thing = new { ColA = "aaa", ColB = "bbb", Id = 1 };
var sql = DataAccess.GetUpdateSqlFor(thing.GetType(), new[] { "Id" }, "Things");
sql.Trim().ShouldBe("UPDATE Things SET ColA = @ColA, ColB = @ColB WHERE 1=1 AND Id = @Id");
}
示例12: insert_sql_is_sane
public void insert_sql_is_sane()
{
var thing = new { ColA = "aaa", ColB = "bbb" };
var sql = DataAccess.GetInsertSqlFor(thing.GetType(), "Things");
sql.Trim().ShouldBe("INSERT INTO Things(ColA, ColB) VALUES(@ColA, @ColB)");
}
示例13: GetEntityKeyValue_MultipleKeys
public void GetEntityKeyValue_MultipleKeys()
{
// Arrange
StructuralTypeConfiguration structuralType = new Mock<StructuralTypeConfiguration>().Object;
var entityInstance = new { Key1 = "key1", Key2 = 2, Key3 = true };
PrimitivePropertyConfiguration[] keys =
{
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key1"), structuralType),
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key2"), structuralType),
new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key3"), structuralType),
};
Mock<EntityTypeConfiguration> entityType = new Mock<EntityTypeConfiguration>();
entityType
.Setup(e => e.Keys)
.Returns(keys);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(new EntityInstanceContext { EntityInstance = entityInstance }, entityType.Object);
// Assert
Assert.Equal("Key1='key1',Key2=2,Key3=true", keyValue);
}
示例14: GetEntityKeyValue_SingleKey
public void GetEntityKeyValue_SingleKey()
{
// Arrange
StructuralTypeConfiguration structuralType = new Mock<StructuralTypeConfiguration>().Object;
var entityInstance = new { Key = "key" };
PrimitivePropertyConfiguration[] keys = { new PrimitivePropertyConfiguration(entityInstance.GetType().GetProperty("Key"), structuralType) };
Mock<EntityTypeConfiguration> entityType = new Mock<EntityTypeConfiguration>();
entityType
.Setup(e => e.Keys)
.Returns(keys);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(new EntityInstanceContext { EntityInstance = entityInstance }, entityType.Object);
// Assert
Assert.Equal("'key'", keyValue);
}