当前位置: 首页>>代码示例>>C#>>正文


C# System.Linq.GetType方法代码示例

本文整理汇总了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);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:13,代码来源:HtmlAttributePropertyHelperTest.cs

示例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));
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:13,代码来源:HtmlAttributePropertyHelperTest.cs

示例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);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:13,代码来源:HtmlAttributePropertyHelperTest.cs

示例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));
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:13,代码来源:PropertyHelperTest.cs

示例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));
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:13,代码来源:PropertyHelperTest.cs

示例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);
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:13,代码来源:PropertyHelperTest.cs

示例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);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:24,代码来源:ConventionsHelpersTests.cs

示例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);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:18,代码来源:ConventionsHelpersTests.cs

示例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.");
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:21,代码来源:ConventionsHelpersTests.cs

示例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);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:18,代码来源:ConventionsHelpersTests.cs

示例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");
 }
开发者ID:swxben,项目名称:danny-boy,代码行数:6,代码来源:can_pass_table_name_in_to_insert_update_and_select.cs

示例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)");
 }
开发者ID:swxben,项目名称:danny-boy,代码行数:6,代码来源:can_pass_table_name_in_to_insert_update_and_select.cs

示例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);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:23,代码来源:ConventionsHelpersTests.cs

示例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);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:18,代码来源:ConventionsHelpersTests.cs


注:本文中的System.Linq.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。