protected override MethodDef?CreateMethodDef(MethodInfo methodInfo, IInvocation initialInvocation) { ValidateType(initialInvocation.TargetType); var options = ComputedOptionsProvider.GetComputedOptions(methodInfo); if (options == null) { return(null); } var methodDef = (ComputeMethodDef)Services.Activate( options.ComputeMethodDefType, this, methodInfo); return(methodDef.IsValid ? methodDef : null); }
protected override void ValidateTypeInternal(Type type) { var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy; foreach (var method in type.GetMethods(bindingFlags)) { var attr = ComputedOptionsProvider.GetComputeMethodAttribute(method); var options = ComputedOptionsProvider.GetComputedOptions(method); if (attr == null || options == null) { continue; } if (method.IsStatic) { throw Errors.ComputeServiceMethodAttributeOnStaticMethod(method); } if (!method.IsVirtual) { throw Errors.ComputeServiceMethodAttributeOnNonVirtualMethod(method); } if (method.IsFinal) { // All implemented interface members are marked as "virtual final" // unless they are truly virtual throw Errors.ComputeServiceMethodAttributeOnNonVirtualMethod(method); } var returnType = method.ReturnType; if (!returnType.IsTaskOrValueTask()) { throw Errors.ComputeServiceMethodAttributeOnNonAsyncMethod(method); } if (returnType.GetTaskOrValueTaskArgument() == null) { throw Errors.ComputeServiceMethodAttributeOnAsyncMethodReturningNonGenericTask(method); } var attributeName = nameof(ComputeMethodAttribute) #if NETSTANDARD2_0 .Replace(nameof(Attribute), "");