static SerializableFormatter() { var current = typeof(T); ConstructorInfo constructor = null; do { constructor = current.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(SerializationInfo), typeof(StreamingContext) }, null); current = current.BaseType; }while (constructor == null && current != typeof(object) && current != null); if (constructor != null) { // TODO: Fancy compiled delegate ISerializableConstructor = (info, context) => { T obj = (T)FormatterServices.GetUninitializedObject(typeof(T)); constructor.Invoke(obj, new object[] { info, context }); return(obj); }; } else { DefaultLoggers.DefaultLogger.LogWarning("Type " + typeof(T).Name + " implements the interface ISerializable but does not implement the required constructor with signature " + typeof(T).Name + "(SerializationInfo info, StreamingContext context). The interface declaration will be ignored, and the formatter fallbacks to reflection."); ReflectionFormatter = new ReflectionFormatter <T>(); } }