Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
3answers
110 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 ...
6
votes
1answer
407 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 ...
2
votes
1answer
53 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 ...
7
votes
1answer
136 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 ...
6
votes
3answers
4k 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 ...
3
votes
1answer
601 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)]]....
3
votes
2answers
161 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 ...