Exemplo n.º 1
0
        /// <summary>
        /// Creates a display field metadata for the specified reference field.
        /// </summary>
        /// <param name="parentField">
        /// The parent reference field.
        /// </param>
        /// <param name="itemType">
        /// The cross-reference item type.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property that represents the display field.
        /// </param>
        /// <param name="displayFieldMetadata">
        /// The created display field metadata.
        /// </param>
        /// <returns>
        /// <c>true</c> if the display field metadata is created successfully; otherwise, <c>false</c>.
        /// </returns>
        public static bool TryCreateDisplayField(IReferenceFieldMetadata parentField, Type itemType, string propertyName, out DisplayFieldMetadata displayFieldMetadata)
        {
            if (parentField == null)
                throw new ArgumentNullException("parentField");

            if (itemType == null)
                throw new ArgumentNullException("itemType");

            if (string.IsNullOrEmpty(propertyName))
                throw new ArgumentException(@"Property name is null or empty.", propertyName);

            displayFieldMetadata = null;

            var property = itemType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
            if (property == null)
            {
                return false;
            }

            var displayFieldAttribute = property.GetCustomAttribute<ReferenceDisplayFieldAttribute>(false);
            if (displayFieldAttribute == null)
            {
                return false;
            }

            if (string.IsNullOrEmpty(displayFieldAttribute.FullPath))
            {
                return false;
            }

            var joinFields = new List<IReferenceFieldMetadata>();
            var referencedProcess = parentField.ReferencedProcess;
            var fieldNames = displayFieldAttribute.FullPath.Split(new[] { "." }, StringSplitOptions.None);
            for (var i = 0; i < fieldNames.Length - 1; ++i)
            {
                IFieldMetadata field;
                if (!referencedProcess.TryGetField(fieldNames[i], out field))
                {
                    return false;
                }

                var joinField = field as IReferenceFieldMetadata;
                if (joinField == null)
                {
                    return false;
                }

                joinFields.Add(joinField);
                referencedProcess = joinField.ReferencedProcess;
            }

            IFieldMetadata displayField;
            if (!referencedProcess.TryGetField(fieldNames.Last(), out displayField))
            {
                return false;
            }

            displayFieldMetadata = new DisplayFieldMetadata(property.Name, displayField, joinFields);

            return true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the name of the database view that returns the links for the specified reference field.
        /// </summary>
        /// <param name="field">
        /// The reference field metadata.
        /// </param>
        /// <returns>
        /// The view name.
        /// </returns>
        public static string GetReferenceFieldIdMappingsViewName(IReferenceFieldMetadata field)
        {
            if (field == null)
                throw new ArgumentNullException("field");

            return GetReferenceFieldIdMappingsViewName(field.DeclaringProcess.Name, field.Name);
        }