public bool Validate(Logger logger) { if (!ServiceContract.IsServiceContractInterface(ServiceType)) { logger.ErrorFormat("{0} is not service contract.", ServiceType.Name); return(false); } return(true); }
public bool TryResolve( AttributeData attributeData, [NotNullWhen(true)] out ICodeGeneratorFactory?factory, [NotNullWhen(true)] out ContractDescription?contract) { factory = null; contract = null; if (attributeData.AttributeClass == null || attributeData.ConstructorArguments.Length != 1 || attributeData.ConstructorArguments[0].Value is not INamedTypeSymbol serviceType) { return(false); } var fullName = attributeData.AttributeClass.ToDisplayString(NullableFlowState.None); var isImport = false; if ("ServiceModel.Grpc.DesignTime.ImportGrpcServiceAttribute".Equals(fullName, StringComparison.Ordinal)) { isImport = true; } else if (!"ServiceModel.Grpc.DesignTime.ExportGrpcServiceAttribute".Equals(fullName, StringComparison.Ordinal)) { return(false); } var logger = new Logger(_context, _candidate, attributeData); if (isImport && !ServiceContract.IsServiceContractInterface(serviceType)) { logger.IsNotServiceContract(serviceType); return(false); } contract = new ContractDescription(serviceType); ShowCommonWarnings(logger, contract, serviceType); factory = isImport ? new CSharpClientCodeGeneratorFactory(contract, _canUseStaticExtensions) : CreateServiceCodeFactory(contract, attributeData); return(true); }