Check if a generic T implements an interface

Generics, oddly enough, use extends for interfaces as well.1 You’ll want to use: public class Foo<T extends SomeInterface>{ //use T as you wish } This is actually a requirement for the implementation, not a true/false check. For a true/false check, use unbounded generics(class Foo<T>{) and make sure you obtain a Class<T> so you have a … Read more

When is using the C# ref keyword ever a good idea?

The Framework Design Guidelines (a book by Krzysztof Cwalina and Brad Abrams) recommend to avoid both ref and out parameters. AVOID using out or ref parameters. Using out or ref parameters requires experience with pointers, understanding how value types and reference types differ, and handling methods with multiple return values. Also, the difference between out … Read more

interface as return type

Yes, you can return an interface. Let’s say classes A and B each implement interface Ic: public interface Ic { int Type { get; } string Name { get; } } public class A : Ic { . . . } public class B : Ic . . . } public Ic func(bool flag) { … Read more

.NET: Unable to cast object to interface it implements

I hat the same problems with a library of mine providing “plugin”-functionality… I got it finally working… Here was my problem: I had one main assembly using plugins, one assembly with the plugin (Plugin.dll) AND (important) another assembly providing the plugin-functionality (Library.dll). The Plugin.dll referenced the main assembly (in order to be able to extend … Read more

Joda-Time: DateTime, DateMidnight and LocalDate usage

I see advantages in having almost all the Interfaces using LocalDateTime (at the Service Layer at least) so that my Application doesn’t have to manage Timezones and can safely assume Times always in UTC. I’m not sure I understand your line of thinking here. LocalDateTime and DateTime represent two quite different concepts. It’s not the … Read more

In Unity, how does Unity magically call all “Interfaces”?

When it comes to XXXUpdate, OnCollisionXXX and other MonoBehaviours, the way Unity registers is not reflection as it has been widely believed but some internal compilation process. HOW UPDATE IS CALLED No, Unity doesn’t use System.Reflection to find a magic method every time it needs to call one. Instead, the first time a MonoBehaviour of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)