Questions tagged [duck-typing]

Duck typing is a style of typing in which an object's methods and properties determine the valid semantics, rather than its inheritance from a particular class or implementation of an explicit interface.

Filter by
Sorted by
Tagged with
6 votes
3 answers
135 views

Comparing similar types that don't share any interface

I have two types that don't share any interface but have similar properties and that I need to compare for equality. One of them is comming from a 3rd party library and one of them is mine. I ...
t3chb0t's user avatar
  • 44.3k
6 votes
1 answer
943 views

Fake duck typing with dynamic

There are sometimes situations where you have a couple of related classes with static fields or properties but you cannot access them via ...
t3chb0t's user avatar
  • 44.3k
2 votes
1 answer
77 views

HTTP request for a single URL or list of URLs based on arguments provided

I have the following code that includes a simple class AioRequest. I would like to be able to call an instance of this class directly with a single URL or a list of ...
JohnBoy's user avatar
  • 105
7 votes
1 answer
199 views

python3 utility: convert safely to int

I made this utility function to check for parameters. All it does is checking whether a given variable is an int, or a float/str that represent exactly an int (ie. no decimal part or NaN), and casting ...
Zorgatone's user avatar
  • 436
6 votes
3 answers
6k views

Generic extension method that will attempt to parse a string and return it's value or default(T)

So I got sick of several things about the way TryParse works. I implemented a generic ParseOrDefault function using reflection. It appears to work as expected, but I'm not fool enough to say my code ...
Sidney's user avatar
  • 215
3 votes
1 answer
841 views

Check that input is list of lists of coordinates

I have a factory method that should accept a list of coordinate lists, which are pairs of numbers, for example [[(2,4),(3,3),(2,4)],[(6,6),(7,6),(7,7),(6,7),(6,6)]]....
flotzilla's user avatar
  • 131
3 votes
2 answers
224 views

Function caller (to multiple receivers) interface

This class is designed to call a similar function of multiple objects of multiple classes using a single interface (it is not for calling functions that return a value). A potential usage will be ...
JaDogg's user avatar
  • 4,531