public MethodCtorMatch GetCtorStaticCreatorToRun(DecodeName nameInfo, DecodedEntityClass entityInfo) { if (nameInfo.NameType == DecodedNameTypes.NoNameGiven) { var result = GetDefaultCtorOrMethod(_matchedCtorsAndStaticMethods, true); if (result != null) { return(result); } throw new InvalidOperationException($"The entity class {entityInfo.EntityType.Name} did find an ctor/static method that matches the {DtoType.Name}." + $" It only links ctor/static methods where ALL the method's parameters can be fulfilled by the DTO/VM non-read-only properties." + " The possible matches are \n" + string.Join("\n", _allPossibleCtorsAndStaticMatches)); } return(FindMethodCtorByName(nameInfo, _matchedCtorsAndStaticMethods, "ctor/static methods")); }
/// <summary> /// This checks if any name was given in the command, or the perDtoConfig specifies a name /// </summary> /// <param name="nameGivenInCommand"></param> /// <param name="createOrUpdate"></param> /// <returns></returns> public DecodeName GetSpecifiedName(string nameGivenInCommand, CrudTypes createOrUpdate) { var result = new DecodeName(nameGivenInCommand); if (result.NameType != DecodedNameTypes.NoNameGiven) { return(result); } switch (createOrUpdate) { case CrudTypes.Create: return(new DecodeName(_perDtoConfig?.CreateMethod)); case CrudTypes.Update: return(new DecodeName(_perDtoConfig?.UpdateMethod)); default: throw new ArgumentException("You should only use Create or Update here", nameof(createOrUpdate)); } }
private List <MethodCtorMatch> PreloadPossibleMethodCtorMatches(List <MethodCtorMatch> allPossibleMatches, DecodeName nameInfo, string errorString) { if (nameInfo.NameType == DecodedNameTypes.AutoMapper) { return(new List <MethodCtorMatch>()); } if (nameInfo.NameType != DecodedNameTypes.NoNameGiven) { //name as been defined in perDtoConfig return(new List <MethodCtorMatch> { FindMethodCtorByName(nameInfo, allPossibleMatches, (errorString == null ? null : errorString + "(PerDtoConfig)")) }); } //Nothing defined so try via the DTO name var nameFromDto = ExtractPossibleMethodNameFromDtoTypeName(); var dtoNamed = new DecodeName(nameFromDto); var foundMatch = FindMethodCtorByName(dtoNamed, allPossibleMatches, null); if (foundMatch != null) { return new List <MethodCtorMatch> { foundMatch } } ; //otherwise return all the possible versions return(allPossibleMatches); }