public void Set <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey, T value) { Dictionary <Guid, object> conceptInfoMetadata; string conceptKey = conceptInfo.GetKey(); if (!_metadata.TryGetValue(conceptKey, out conceptInfoMetadata)) { conceptInfoMetadata = new Dictionary <Guid, object>(); _metadata.Add(conceptKey, conceptInfoMetadata); } object oldValue; if (!conceptInfoMetadata.TryGetValue(metadataKey.Id, out oldValue)) { conceptInfoMetadata.Add(metadataKey.Id, value); } else { if (!SameValue(value, oldValue)) { throw new FrameworkException( $"Different metadata value is already set for concept {conceptInfo.GetUserDescription()}, key {metadataKey}." + $" Previous value '{oldValue}', new value '{value}'."); } } }
public T Get <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey) { Func <string> missingMetadataMessage = () => "There is no requested metadata for concept " + conceptInfo.GetUserDescription() + ". Metadata key is " + metadataKey + "."; var conceptInfoMetadata = _metadata.GetValue(conceptInfo.GetKey(), missingMetadataMessage); var metadataValue = conceptInfoMetadata.GetValue(metadataKey.Id, missingMetadataMessage); return((T)metadataValue); }
public bool Contains <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey) { Dictionary <Guid, object> conceptInfoMetadata; if (!_metadata.TryGetValue(conceptInfo.GetKey(), out conceptInfoMetadata)) { return(false); } return(conceptInfoMetadata.ContainsKey(metadataKey.Id)); }
public T GetOrDefault <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey, T defaultValue) { return(Contains(conceptInfo, metadataKey) ? Get(conceptInfo, metadataKey) : defaultValue); }