Visitar URL original
Expose Value of DnsResourceRecord · Issue #36 · MichaCo/DnsClient.NET · GitHub
Skip to content

Expose Value of DnsResourceRecord #36

Open

Description

@gt5700

I can't work out how to get the string "Value" of the DnsResourceRecord without having to either split the output of "ToString()" on the tab characters, or to test the DnsResourceRecords type and access a type specific "value" property.

There is a private protected abstract RecordToString() method that each deriving DnsResourceRecord type implements appropriately, Would it be possible to expose the result of this method as either a property or method?

Activity

  1. MichaConrad commented on Oct 23, 2018

    @MichaConrad
    Collaborator

    Each type has specific properties which are parsed and populated by this library.
    You're supposed to use those instead of parsing a string or binary data yourself.
    Depending on the method, yes, you might have to type check the result. There are a couple of helper methods doing that for you though. result.Answers.ARecords() returns all A records from the query result...

    The RecordToString is used internally for "pretty" printing the record. There is no point exposing that method.
    ToString should also never be used within business logic to determine the value of an object (that's true in general).

  2. gt5700 commented on Oct 23, 2018

    @gt5700
    Author
  3. MichaConrad commented on Oct 23, 2018

    @MichaConrad
    Collaborator

    Well, the returned value of ToString might also change in future version. There is no type safe guarantee that the returned value will be the same format or order of values.

    That's up to you to decide what to use ofc, just saying ;)
    Using type safe properties of the actual records is usually the way to go ;)

  4. gt5700 commented on Oct 23, 2018

    @gt5700
    Author
  5. MichaConrad commented on Oct 23, 2018

    @MichaConrad
    Collaborator

    I don't really get what you mean with value only. Most resource records have many different fields (not just one value). Others have lists of strings or binary data, enum values etc...
    I also don't really get what you are doing with regex over dns values to be honest... maybe you can post an example for your use case. But so far, all that sounds pretty horrible to me ;)

  6. gt5700 commented on Oct 23, 2018

    @gt5700
    Author
  7. MichaConrad commented on Oct 24, 2018

    @MichaConrad
    Collaborator

    Ok, I kind of get it. I might make that method public/rename it slightly. But that might take a while till it gets published

    On the other hand, I would write a small switch statement which uses the configured query type and then, with A and AAAA you can cast the answers to AddressRecords and then use the IPAddress property. etc...
    That's not really a lot of code and much much safer anyways, too ;)

  8. gt5700 commented on Oct 25, 2018

    @gt5700
    Author
  9. added this to the Future milestone on Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions