public void GetMemberNames_SimpleTestItem_ReturnsMemberNamesInOrder() { var memberNames = FormatterUtils.GetMemberNames(typeof(SimpleTestItem)); Assert.IsNotNull(memberNames); Assert.AreEqual(2, memberNames.Count); Assert.AreEqual("Value1", memberNames[0]); Assert.AreEqual("Value2", memberNames[1]); }
public void GetMemberNames_SimpleTestItem_ReturnsMemberNamesInOrder() { var memberNames = FormatterUtils.GetMemberNames(typeof(SimpleTestItem)); memberNames.Should().NotBeNull(); memberNames.Count.Should().Be(2); memberNames[0].Should().Be("Value1"); memberNames[1].Should().Be("Value2"); }
public void GetMemberNames_AnonymousType_ReturnsMemberNamesInOrderDefined() { var anonymous = new { prop1 = "value1", prop2 = "value2" }; var memberNames = FormatterUtils.GetMemberNames(anonymous.GetType()); Assert.IsNotNull(memberNames); Assert.AreEqual(2, memberNames.Count); Assert.AreEqual("prop1", memberNames[0]); Assert.AreEqual("prop2", memberNames[1]); }
public void GetMemberNames_AnonymousType_ReturnsMemberNamesInOrderDefined() { var anonymous = new { prop1 = "value1", prop2 = "value2" }; var memberNames = FormatterUtils.GetMemberNames(anonymous.GetType()); memberNames.Should().NotBeNull(); memberNames.Count.Should().Be(2); memberNames[0].Should().Be("prop1"); memberNames[1].Should().Be("prop2"); }
public void GetMemberNames_ComplexTestItem_ReturnsMemberNamesInOrder() { var memberNames = FormatterUtils.GetMemberNames(typeof(ComplexTestItem)); Assert.IsNotNull(memberNames); Assert.AreEqual(5, memberNames.Count); Assert.AreEqual("Value4", memberNames[0]); Assert.AreEqual("Value1", memberNames[1]); Assert.AreEqual("Value5", memberNames[2]); Assert.AreEqual("Value3", memberNames[3]); Assert.AreEqual("Value2", memberNames[4]); }
public void GetMemberNames_ComplexTestItem_ReturnsMemberNamesInOrder() { var memberNames = FormatterUtils.GetMemberNames(typeof(ComplexTestItem)); memberNames.Should().NotBeNull(); memberNames.Count.Should().Be(5); memberNames[0].Should().Be("Value4"); memberNames[1].Should().Be("Value1"); memberNames[2].Should().Be("Value5"); memberNames[3].Should().Be("Value3"); memberNames[4].Should().Be("Value2"); }
public ExcelSheetInfoCollection GetExcelSheetInfo(Type itemType, object data) { if (itemType.Name.StartsWith("Dictionary")) { return(null); } var sheets = FormatterUtils.GetMemberNames(itemType); var properties = GetSerialisablePropertyInfo(itemType); var sheetCollection = new ExcelSheetInfoCollection(); foreach (var sheet in sheets) { var prop = properties.FirstOrDefault(p => p.Name == sheet); ExcelSheetAttribute attr = FormatterUtils.GetAttribute <ExcelSheetAttribute>(prop); if (prop == null || attr == null) { continue; } var sheetInfo = new ExcelSheetInfo() { SheetType = prop.PropertyType, SheetName = sheet, ExcelSheetAttribute = attr, PropertyName = prop.Name, SheetObject = FormatterUtils.GetFieldOrPropertyValue(data, prop.Name) }; if (prop.PropertyType.Name.StartsWith("List") && sheetInfo.SheetObject != null) { sheetInfo.SheetType = FormatterUtils.GetEnumerableItemType(sheetInfo.SheetObject.GetType()); } sheetCollection.Add(sheetInfo); } return(sheetCollection); }
/// <summary> /// Get a list of all non-ignored public instance property names for a class. /// </summary> /// <param name="itemType">Type of item being serialised.</param> /// <param name="data">The collection of values being serialised. (Not used, provided for use by derived /// types.)</param> public virtual IEnumerable <string> GetSerialisableMemberNames(Type itemType, object data) { return(FormatterUtils.GetMemberNames(itemType)); }