internal override bool VisitRef(string pathFrom, VisitCallback preChildren, VisitCallback postChildren) { bool result = false; if (this.Arguments?.Count > 0) { // custom enumeration of args to force a path onto these things that just might not have a name int lItem = this.Arguments.Count; for (int iItem = 0; iItem < lItem; iItem++) { CdmArgumentDefinition element = this.Arguments[iItem]; if (element != null) { string argPath = $"{pathFrom}/arguments/a{iItem}"; if (element.Visit(argPath, preChildren, postChildren)) { result = true; break; } } } } return(result); }
/// <inheritdoc /> public override CdmObject Copy(ResolveOptions resOpt = null, CdmObject host = null) { if (resOpt == null) { resOpt = new ResolveOptions(this, this.Ctx.Corpus.DefaultResolutionDirectives); } CdmArgumentDefinition copy; if (host == null) { copy = new CdmArgumentDefinition(this.Ctx, this.Name); } else { copy = host as CdmArgumentDefinition; copy.Ctx = this.Ctx; copy.Name = this.Name; } if (this.Value != null) { if (this.Value is CdmObject) { copy.Value = ((CdmObject)this.Value).Copy(resOpt); } else { copy.Value = this.Value; } } copy.ResolvedParameter = this.ResolvedParameter; copy.Explanation = this.Explanation; return(copy); }
public override CdmObject Copy(ResolveOptions resOpt = null) { if (resOpt == null) { resOpt = new ResolveOptions(this); } CdmArgumentDefinition copy = new CdmArgumentDefinition(this.Ctx, this.Name); if (this.Value != null) { if (this.Value is CdmObject) { copy.Value = ((CdmObject)this.Value).Copy(resOpt); } else { // Value is a string or JValue copy.Value = (string)this.Value; } } copy.ResolvedParameter = this.ResolvedParameter; copy.Explanation = this.Explanation; return(copy); }
/// <summary> /// Verifies if the trait argument data type matches what is specified on the trait definition. /// </summary> /// <param name="objects"></param> /// <param name="resOpt"></param> internal void ResolveTraitArguments(ResolveOptions resOpt) { ResolveContext ctx = this.Ctx as ResolveContext; foreach (var obj in this.InternalObjects) { if (obj is CdmTraitReference traitRef) { CdmTraitDefinition traitDef = traitRef.FetchObjectDefinition <CdmTraitDefinition>(resOpt); if (traitDef == null) { continue; } for (int argumentIndex = 0; argumentIndex < traitRef.Arguments.Count; ++argumentIndex) { CdmArgumentDefinition argument = traitRef.Arguments[argumentIndex]; try { ctx.RelativePath = argument.DeclaredPath; ParameterCollection paramCollection = traitDef.FetchAllParameters(resOpt); CdmParameterDefinition paramFound = paramCollection.ResolveParameter(argumentIndex, argument.Name); argument.ResolvedParameter = paramFound; // if parameter type is entity, then the value should be an entity or ref to one // same is true of 'dataType' dataType dynamic argumentValue = paramFound.ConstTypeCheck(resOpt, this, argument.Value); if (argumentValue != null) { argument.Value = argumentValue; } } catch (Exception e) { Logger.Error(ctx, Tag, nameof(ResolveTraitArguments), this.AtCorpusPath, CdmLogCode.ErrTraitResolutionFailure, traitDef.GetName(), e.ToString()); } } traitRef.ResolvedArguments = true; } } }