© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
16 replies
kurumi

✅ XmlReader generic Mapper

Hello 👋 . I am trying to create generic mapper for my project, that is using XmlReader.
All my XML files have same structure, i.e.:
<ROOT>
  <OBJECT ID="52022696" OBJECTID="1456218" NAME="Abaya" TYPENAME="street" ISACTUAL="1" ISACTIVE="0"/>
  ...
</ROOT>
<ROOT>
  <OBJECT ID="52022696" OBJECTID="1456218" NAME="Abaya" TYPENAME="street" ISACTUAL="1" ISACTIVE="0"/>
  ...
</ROOT>

For model:
public class AddressObject
{
  public int Id { get; set; }

  public int ObjectId { get; set; }

  public string FullName { get; set; }
}
public class AddressObject
{
  public int Id { get; set; }

  public int ObjectId { get; set; }

  public string FullName { get; set; }
}


So, I want to use Mapper this way:
public XmlReaderCopyHelper<AddressObject> Addresses =>
    new XmlReaderCopyHelper<AddressObject>("OBJECT")
        .WithCondition("ISACTUAL", src => src == "1") // ! only if ISACTUAL is "1" map, otherwise skip
        .WithCondition("ISACTIVE", src => src == "1") // ! second condition
        .Map("ID", ao => ao.Id)
        .Map("OBJECTID", ao => ao.ObjectId)
        .Map(..., ao => ao.FullName); // ! it should map to $"{TYPENAME} {NAME}"
public XmlReaderCopyHelper<AddressObject> Addresses =>
    new XmlReaderCopyHelper<AddressObject>("OBJECT")
        .WithCondition("ISACTUAL", src => src == "1") // ! only if ISACTUAL is "1" map, otherwise skip
        .WithCondition("ISACTIVE", src => src == "1") // ! second condition
        .Map("ID", ao => ao.Id)
        .Map("OBJECTID", ao => ao.ObjectId)
        .Map(..., ao => ao.FullName); // ! it should map to $"{TYPENAME} {NAME}"
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Generic Dto Mapper
C#CC# / help
4y ago
Issue with XmlReader
C#CC# / help
2y ago
Is this mapper safe?
C#CC# / help
2y ago
❔ ✅ custom mapper and resolvers
C#CC# / help
3y ago