public static GetKeywordOrTypeName ( |
||
conceptInfoType | ||
return | string |
private void ReportObsoleteConcepts(DslContainer dslContainer) { var obsoleteConceptsByType = dslContainer.Concepts .GroupBy(concept => concept.GetType()) .Select(conceptsGroup => new { ConceptType = conceptsGroup.Key, ConceptKeyword = ConceptInfoHelper.GetKeywordOrTypeName(conceptsGroup.Key), Concepts = conceptsGroup.ToList(), ObsoleteAttribute = (ObsoleteAttribute)conceptsGroup.Key.GetCustomAttributes(typeof(ObsoleteAttribute), false).SingleOrDefault() }) .Where(conceptsGroup => conceptsGroup.ObsoleteAttribute != null) .ToList(); // Obsolete concepts in the report are grouped by concept keyword and obsolete message. var obsoleteConceptsByUserReport = obsoleteConceptsByType .GroupBy(conceptsGroup => new { conceptsGroup.ConceptKeyword, conceptsGroup.ObsoleteAttribute.Message }) .Select(conceptsGroup => new { conceptsGroup.Key.ConceptKeyword, ObsoleteMessage = conceptsGroup.Key.Message, Concepts = conceptsGroup.SelectMany(group => group.Concepts) }) .ToList(); foreach (var conceptsGroup in obsoleteConceptsByUserReport) { _logger.Warning(() => string.Format("Obsolete concept {0} ({1} occurrences). {2}", conceptsGroup.Concepts.First().GetUserDescription(), conceptsGroup.Concepts.Count(), conceptsGroup.ObsoleteMessage)); } }
public ValueOrError <object> ReadMemberValue(ConceptMember member, ITokenReader tokenReader, IConceptInfo lastConcept, bool firstMember, ref bool lastPropertyWasInlineParent, ref bool lastConceptUsed, bool readingAReference) { try { if (lastPropertyWasInlineParent && member.IsKey && !member.IsConceptInfo) // TODO: Removing "IsConceptInfo" from this condition would produce a mismatch. Think of a better solution for parsing the concept key. { if (!tokenReader.TryRead(".")) { return(ValueOrError <object> .CreateError(string.Format( "Parent property and the following key value ({0}) must be separated with a dot. Expected \".\"", member.Name))); } } lastPropertyWasInlineParent = false; if (member.IsStringType) { return(tokenReader.ReadText().ChangeType <object>()); } if (member.ValueType == typeof(IConceptInfo)) { if (firstMember && lastConcept != null) { lastConceptUsed = true; return((object)lastConcept); } else { return(ValueOrError <object> .CreateError("Member of type IConceptInfo can only be used as a first member and enclosed within the referenced parent concept.")); } } if (member.IsConceptInfo && lastConcept != null && member.ValueType.IsInstanceOfType(lastConcept) && member.ValueType.IsAssignableFrom(ConceptInfoType)) // Recursive "parent" property { lastConceptUsed = true; return((object)lastConcept); } if (member.IsConceptInfo && lastConcept != null && member.ValueType.IsInstanceOfType(lastConcept) && firstMember) { lastConceptUsed = true; return((object)lastConcept); } if (member.IsConceptInfo && firstMember) { if (member.ValueType == ConceptInfoType) { return(ValueOrError.CreateError(string.Format( "Recursive concept {0} cannot be used as a root because its parent property ({1}) must reference another concept. Use a non-recursive concept for the root and a derivation of the root concept with additional parent property as a recursive concept.", ConceptInfoHelper.GetKeywordOrTypeName(ConceptInfoType), member.Name))); } if (!readingAReference && Members.Where(m => m.IsParsable).Count() == 1) { // This validation is not necessary for consistent parsing. It is enforced simply to avoid ambiguity when parsing // similar concepts such as "Logging { AllProperties; }", "History { AllProperties; }" and "Persisted { AllProperties; }". var parentMembers = ConceptMembers.Get(member.ValueType).Where(m => m.IsParsable).ToArray(); if (parentMembers.Count() == 1 && parentMembers.Single().IsConceptInfo) { return(ValueOrError.CreateError(string.Format( "{0} must be enclosed within the referenced parent concept {1}. A single-reference concept that references another single-reference concept must always be used with embedded syntax to avoid ambiguity.", ConceptInfoHelper.GetKeywordOrTypeName(ConceptInfoType), ConceptInfoHelper.GetKeywordOrTypeName(member.ValueType)))); } } GenericParser subParser = new GenericParser(member.ValueType, ""); lastConceptUsed = true; lastPropertyWasInlineParent = true; return(subParser.ParseMembers(tokenReader, lastConcept, true).ChangeType <object>()); } if (member.IsConceptInfo) { GenericParser subParser = new GenericParser(member.ValueType, ""); return(subParser.ParseMembers(tokenReader, null, true).ChangeType <object>()); } return(ValueOrError.CreateError(string.Format( "GenericParser does not support members of type \"{0}\". Try using string or implementation of IConceptInfo.", member.ValueType.Name))); } catch (DslSyntaxException ex) { return(ValueOrError <object> .CreateError(ex.Message)); } }
private ValueOrError <object> ReadMemberValue(ConceptMember member, ITokenReader tokenReader, IConceptInfo useLastConcept, bool firstMember, ref bool parsedFirstReferenceElement, bool readingAReference) { try { if (member.IsStringType) { if (useLastConcept != null) { return(ValueOrError <object> .CreateError($"This concept cannot be nested within {useLastConcept.GetType().Name}. Trying to read {ConceptInfoType.Name}.")); } if (readingAReference && parsedFirstReferenceElement) { if (!tokenReader.TryRead(".")) { return(ValueOrError <object> .CreateError(string.Format( "Parent property and the following key value ({0}) must be separated with a dot. Expected \".\"", member.Name))); } } parsedFirstReferenceElement = true; // Legacy syntax: if (!readingAReference && member.IsKey && member.IsStringType && !firstMember) { if (tokenReader.TryRead(".")) { AddWarning($"Obsolete syntax: Remove '.' from {Keyword} statement. {((TokenReader)tokenReader).ReportPosition()}."); } } return(tokenReader.ReadText().ChangeType <object>()); } if (member.ValueType == typeof(IConceptInfo)) { if (useLastConcept != null) { return((object)useLastConcept); } else { return(ValueOrError <object> .CreateError($"Member of type IConceptInfo can only be nested within" + $" the referenced parent concept. It must be a first member or marked with {nameof(ConceptParentAttribute)}.")); } } if (useLastConcept != null && member.ValueType.IsInstanceOfType(useLastConcept)) { return((object)useLastConcept); } if (member.IsConceptInfo && firstMember && !readingAReference && Members.Count(m => m.IsParsable) == 1) { // This validation is not necessary for consistent parsing. It is enforced simply to avoid ambiguity for future concept overloads // when parsing similar concepts such as "Logging { AllProperties; }", "History { AllProperties; }" and "Persisted { AllProperties; }". var parentMembers = ConceptMembers.Get(member.ValueType).Where(m => m.IsParsable).ToArray(); if (parentMembers.Count() == 1 && parentMembers.Single().IsConceptInfo) { return(ValueOrError.CreateError($"{ConceptInfoHelper.GetKeywordOrTypeName(ConceptInfoType)} must be nested" + $" within the referenced parent concept {ConceptInfoHelper.GetKeywordOrTypeName(member.ValueType)}." + $" A single-reference concept that references another single-reference concept must always be used with nested syntax to avoid ambiguity.")); } } if (member.IsConceptInfo) { if (firstMember && member.ValueType == ConceptInfoType) { return(ValueOrError.CreateError(string.Format( "Recursive concept {0} cannot be used as a root because its parent property ({1}) must reference another concept. Use a non-recursive concept for the root and a derivation of the root concept with additional parent property as a recursive concept.", ConceptInfoHelper.GetKeywordOrTypeName(ConceptInfoType), member.Name))); } GenericParser subParser = new GenericParser(member.ValueType, ""); return(subParser.ParseMembers(tokenReader, useLastConcept, true, ref parsedFirstReferenceElement).ChangeType <object>()); } return(ValueOrError.CreateError(string.Format( "GenericParser does not support members of type \"{0}\". Try using string or implementation of IConceptInfo.", member.ValueType.Name))); } catch (DslSyntaxException ex) { return(ValueOrError <object> .CreateError(ex.Message)); } }