Raven.Database.Indexing.CurrentIndexingScope.LoadDocument C# (CSharp) Method

LoadDocument() public method

public LoadDocument ( string key ) : dynamic
key string
return dynamic
		public dynamic LoadDocument(string key)
		{
			if (key == null)
				return new DynamicNullObject();

			var source = Source;
			if (source == null)
				throw new ArgumentException(
					"LoadDocument can only be called as part of the Map stage of the index, but was called with " + key +
					" without a source.");
			var id = source.__document_id as string;
			if (string.IsNullOrEmpty(id))
				throw new ArgumentException(
					"LoadDocument can only be called as part of the Map stage of the index, but was called with " + key +
					" without a document. Current source: " + source);

			if (string.Equals(key, id))
				return source;

			HashSet<string> set;
			if(referencedDocuments.TryGetValue(id, out set) == false)
				referencedDocuments.Add(id, set = new HashSet<string>(StringComparer.OrdinalIgnoreCase));
			set.Add(key);

			dynamic value;
			if (docsCache.TryGetValue(key, out value))
				return value;

			value = loadDocument(key);
			docsCache[key] = value;
			return value;
		}