private void GenerateCreateDefaultConstructorIL(Type type, ILGenerator generator) { if (TypeExtensions.IsValueType(type)) { generator.DeclareLocal(type); generator.Emit(OpCodes.Ldloc_0); generator.Emit(OpCodes.Box, type); } else { ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, (Binder)null, ReflectionUtils.EmptyTypes, (ParameterModifier[])null); if (constructor == null) { throw new ArgumentException(StringUtils.FormatWith("Could not get constructor for {0}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)type)); } generator.Emit(OpCodes.Newobj, constructor); } ILGeneratorExtensions.Return(generator); }
private static bool IsCompatibleObject(object value) { return(value is T || value == null && (!TypeExtensions.IsValueType(typeof(T)) || ReflectionUtils.IsNullableType(typeof(T)))); }