Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="wvObject"></param>
        /// <param name="item"></param>
        /// <param name="matchType"></param>
        /// <returns></returns>
        public static bool IsMatch <T>(this Hyland.Unity.WorkView.Object wvObject, T item, WorkViewMatchType matchType = WorkViewMatchType.OnlyKeys)
        {
            Type itemType          = item.GetType();
            var  definedAttributes = itemType.GetProperties().Where(pi => WorkViewAttributeAttribute.IsDefined(pi));

            List <PropertyInfo> matchableProperties = null;

            switch (matchType)
            {
            case WorkViewMatchType.OnlyKeys:
                matchableProperties = definedAttributes.Where(pi => WorkViewAttributeAttribute.IsKey(pi)).ToList();
                break;

            case WorkViewMatchType.NonOptional:
                matchableProperties = definedAttributes.Where(pi => !WorkViewAttributeAttribute.IsOptional(pi)).ToList();
                break;

            case WorkViewMatchType.AllDefinedAttributes:
                matchableProperties = definedAttributes.ToList();
                break;

            default:
                break;
            }

            //
            foreach (var matchProperty in matchableProperties)
            {
                var attributeValue = wvObject.AttributeValueByAddress(WorkViewAttributeAttribute.GetAttributeAddress(matchProperty));

                if (matchProperty.GetValue(item).ToString() != attributeValue.Value.ToString())
                {
                    return(false);
                }
            }

            return(true);
        }