Was.OrcSearch – Rev 1

Subversion Repositories:
Rev:
using Was.OrcSearch.Models.Interfaces;

namespace Was.OrcSearch.Models
{
    public class ObjectWithMetadata : IObjectWithMetadata
    {
        public ObjectWithMetadata(object instance, IMetadataCollection metadataCollection)
        {
            Instance = instance;
            MetadataCollection = metadataCollection;
        }

        public object Instance { get; }

        public IMetadataCollection MetadataCollection { get; }

        public virtual object GetMetadataValue(string key)
        {
            return GetMetadataValueWithInstance(Instance, key);
        }

        public virtual bool SetMetadataValue(string key, object value)
        {
            return SetMetadataValueWithInstance(Instance, key, value);
        }

        protected object GetMetadataValueWithInstance(object instance, string key)
        {
            var metadata = MetadataCollection.GetMetadata(key);
            if (metadata == null) return null;

            return metadata.GetValue(instance);
        }

        protected bool SetMetadataValueWithInstance(object instance, string key, object value)
        {
            var metadata = MetadataCollection.GetMetadata(key);
            if (metadata == null) return false;

            metadata.SetValue(instance, value);
            return true;
        }
    }
}

Generated by GNU Enscript 1.6.5.90.