private MethodInfo SanityCheckCallback(MethodInfo callback) { metaType.ThrowIfFrozen(); if (callback == null) { return(callback); // fine } if (callback.IsStatic) { throw new ArgumentException("Callbacks cannot be static", "callback"); } ParameterInfo[] args = callback.GetParameters(); if (callback.ReturnType == typeof(void) && (args.Length == 0 || (args.Length == 1 && (args[0].ParameterType == typeof(SerializationContext) #if PLAT_BINARYFORMATTER || args[0].ParameterType == typeof(System.Runtime.Serialization.StreamingContext) #endif )))) { } else { throw CreateInvalidCallbackSignature(callback); } return(callback); }
/// <summary> /// Adds a known sub-type to the inheritance model /// </summary> public MetaType AddSubType(int fieldNumber, Type derivedType) { if (!(type.IsClass || type.IsInterface) || type.IsSealed) { throw new InvalidOperationException("Sub-types can only be added to non-sealed classes"); } if (typeof(IEnumerable).IsAssignableFrom(type)) { throw new ArgumentException("Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be subclassed"); } ThrowIfFrozen(); MetaType derivedMeta = model[derivedType]; derivedMeta.ThrowIfFrozen(); SubType subType = new SubType(fieldNumber, derivedMeta); ThrowIfFrozen(); derivedMeta.SetBaseType(this); // includes ThrowIfFrozen if (subTypes == null) { subTypes = new BasicList(); } subTypes.Add(subType); return(this); }
private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback) { metaType.ThrowIfFrozen(); if (callback == null) return callback; // fine if (callback.IsStatic) throw new ArgumentException("Callbacks cannot be static", nameof(callback)); if (callback.ReturnType != model.MapType(typeof(void)) || !CheckCallbackParameters(model, callback)) { throw CreateInvalidCallbackSignature(callback); } return callback; }
private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback) { metaType.ThrowIfFrozen(); if (callback == null) { return(callback); // fine } if (callback.ReturnType != model.MapType(typeof(void)) || !CheckCallbackParameters(model, callback)) { throw CreateInvalidCallbackSignature(callback); } return(callback); }
private MethodInfo SanityCheckCallback(MethodInfo callback) { metaType.ThrowIfFrozen(); if (callback == null) { return(callback); // fine } if (callback.IsStatic) { throw new ArgumentException("Callbacks cannot be static", "callback"); } if (callback.ReturnType != typeof(void) || !CheckCallbackParameters(callback)) { throw CreateInvalidCallbackSignature(callback); } return(callback); }
private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback) { metaType.ThrowIfFrozen(); if (callback == (MethodInfo)null) { return(callback); } if (callback.IsStatic) { throw new ArgumentException("Callbacks cannot be static", "callback"); } if (!(callback.ReturnType != model.MapType(typeof(void))) && CheckCallbackParameters(model, callback)) { return(callback); } throw CreateInvalidCallbackSignature(callback); }