コード例 #1
0
        public static void IndexObject(ObjectDto persistObj)
        {
            var t = persistObj.GetType();

            var props = t.GetProperties().Where(
                prop => Attribute.IsDefined(prop, typeof(UniqueAttribute)));

            PropertyInfo propertyToBeUniquelyIndexed = null;

            foreach (var p in props)
            {
                propertyToBeUniquelyIndexed = p;
                // There is only one unique property allowed per class.
                // So we can safely break:
                break;
            }

            object propertyValueToBeIndexed = propertyToBeUniquelyIndexed.GetValue(persistObj);

            _persistentObj.DeletePreviousIndex(persistObj.Uuid);
            _persistentObj.IndexObject(persistObj.GetType().AssemblyQualifiedName, persistObj.Uuid, propertyValueToBeIndexed.ToString());
        }