Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Value of DnsResourceRecord #36

Open
gt5700 opened this issue Oct 23, 2018 · 8 comments
Open

Expose Value of DnsResourceRecord #36

gt5700 opened this issue Oct 23, 2018 · 8 comments
Milestone

Comments

@gt5700
Copy link

gt5700 commented Oct 23, 2018

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?

@MichaCo
Copy link
Owner

MichaCo commented Oct 23, 2018

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).

@MichaCo MichaCo closed this as completed Oct 23, 2018
@gt5700
Copy link
Author

gt5700 commented Oct 23, 2018 via email

@MichaCo
Copy link
Owner

MichaCo commented Oct 23, 2018

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 ;)

@gt5700
Copy link
Author

gt5700 commented Oct 23, 2018 via email

@MichaCo
Copy link
Owner

MichaCo commented Oct 23, 2018

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 ;)

@gt5700
Copy link
Author

gt5700 commented Oct 23, 2018 via email

@MichaCo
Copy link
Owner

MichaCo commented Oct 24, 2018

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 ;)

@MichaCo MichaCo reopened this Oct 24, 2018
@gt5700
Copy link
Author

gt5700 commented Oct 25, 2018 via email

@MichaCo MichaCo added this to the Future milestone Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants