C# Dynamic Event Subscription

You can compile expression trees to use void methods without any arguments as event handlers for events of any type. To accommodate other event handler types, you have to map the event handler’s parameters to the events somehow. using System; using System.Linq; using System.Linq.Expressions; using System.Reflection; class ExampleEventArgs : EventArgs { public int IntArg {get; … Read more

Why use reflection to access class members when MethodHandle is faster?

Reflection and method handles serve different purposes, and exist at different levels of abstraction. You should use the one that is right for the problem you are solving. Reflection is a general-purpose introspection mechanism, which includes many features that the method handle mechanism lacks, such as enumerating the members of a class (Class.getMethods()), inspecting the … Read more

In golang, is it possible to get reflect.Type from the type itself, from name as string?

On 1, yes, kinda: var v1 reflect.Type = reflect.TypeOf((*t1)(nil)).Elem() fmt.Println(v1) // prints “main.t1” No instantiation needed. However, Go doesn’t have type literals, which is I think what you’re asking for. To get the runtime value of a type, you need to have a value of some sort. If you don’t want to or can’t create … Read more

Passing C# parameters which can “fit” an interface, but do not actually implement it

Try to use the library Impromptu-Interface [The Impromptu-Interface] framework to allow you to wrap any object (static or dynamic) with a static interface even though it didn’t inherit from it. It does this by emitting cached dynamic binding code inside a proxy. This allows you to do something like this: var person = new Person(); … Read more

Exclude property from getType().GetProperties()

Extension methods and attributes will help you: public class SkipPropertyAttribute : Attribute { } public static class TypeExtensions { public static PropertyInfo[] GetFilteredProperties(this Type type) { return type.GetProperties().Where(pi => pi.GetCustomAttributes(typeof(SkipPropertyAttribute), true).Length == 0).ToArray(); } } public class Test { public string One { get; set; } [SkipProperty] public string Two { get; set; } } … Read more

LoggerFactory.getLogger(ClassName.class) vs LoggerFactory.getLogger(this.getClass().getName())

Late entry! As I am likely to be searching for this in the future. There is a way to create copy/paste friendly Logger instances (granted this is almost never a good reason to do something!) by using Java 7’s MethodHandles class. private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

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