Beispiel #1
0
        /// <summary>
        /// Gets the name of the CRM Entity attribute.
        /// </summary>
        /// <typeparam name="T">
        /// Type of the property
        /// </typeparam>
        /// <param name="propertyExpression">
        /// The property expression.
        /// </param>
        /// <param name="method">
        /// The method.
        /// </param>
        /// <returns>
        /// The name of the entity attribute
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// Attribute name extraction method is not supported.
        /// </exception>
        public static string ExtractEntityAttributeName <T>(this Expression <Func <T> > propertyExpression, FieldNameExractMethod method)
        {
            switch (method)
            {
            case FieldNameExractMethod.UsingPropertyName:
                return(propertyExpression.ExtractPropertyName().ToLowerInvariant());

            case FieldNameExractMethod.UsingLogicalNameAttribute:
                var propertyAttribute = propertyExpression.ExtractPropertyAttribute <T, AttributeLogicalNameAttribute>();
                return(propertyAttribute.LogicalName.ToLowerInvariant());

            default:
                throw new NotImplementedException("Attribute name extraction method is not supported.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the formatted value.
        /// </summary>
        /// <typeparam name="T">
        /// Type of the attribute
        /// </typeparam>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <param name="propertyExpression">
        /// The property expression.
        /// </param>
        /// <param name="method">
        /// The method.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string GetFormattedValue <T>(this Entity entity, Expression <Func <T> > propertyExpression, FieldNameExractMethod method = FieldNameExractMethod.UsingPropertyName)
        {
            var propertyName = propertyExpression.ExtractPropertyName().ToLowerInvariant();

            return(entity.GetFormattedValue(propertyName));
        }
Beispiel #3
0
        /// <summary>
        /// Adds the column to the column set.
        /// </summary>
        /// <typeparam name="T">
        /// Type of the column
        /// </typeparam>
        /// <param name="columnSet">
        /// The column set.
        /// </param>
        /// <param name="propertyExpression">
        /// The property expression.
        /// </param>
        /// <param name="method">
        /// The method.
        /// </param>
        public static void AddColumn <T>(this ColumnSet columnSet, Expression <Func <T> > propertyExpression, FieldNameExractMethod method = FieldNameExractMethod.UsingPropertyName)
        {
            var entityAttributeName = propertyExpression.ExtractEntityAttributeName(method);

            columnSet.AddColumn(entityAttributeName);
        }
Beispiel #4
0
        /// <summary>
        /// Removes the attribute.
        /// </summary>
        /// <typeparam name="T">
        /// Type of the column
        /// </typeparam>
        /// <param name="attributeCollection">
        /// The attribute collection.
        /// </param>
        /// <param name="propertyExpression">
        /// The property expression.
        /// </param>
        /// <param name="method">
        /// The method.
        /// </param>
        public static void Remove <T>(this AttributeCollection attributeCollection, Expression <Func <T> > propertyExpression, FieldNameExractMethod method = FieldNameExractMethod.UsingPropertyName)
        {
            var entityAttributeName = propertyExpression.ExtractEntityAttributeName(method);

            attributeCollection.Remove(entityAttributeName);
        }
Beispiel #5
0
        /// <summary>
        /// Determines whether the ColumnSet contains the column specified by lambda expression.
        /// </summary>
        /// <typeparam name="T">
        /// Type of the column
        /// </typeparam>
        /// <param name="columnSet">
        /// The column set.
        /// </param>
        /// <param name="propertyExpression">
        /// The property expression.
        /// </param>
        /// <param name="method">
        /// The method.
        /// </param>
        /// <returns>
        /// <c>True</c> if the column found
        /// </returns>
        public static bool Contains <T>(this ColumnSet columnSet, Expression <Func <T> > propertyExpression, FieldNameExractMethod method = FieldNameExractMethod.UsingPropertyName)
        {
            var entityAttributeName = propertyExpression.ExtractEntityAttributeName(method);

            return(columnSet.Columns.Contains(entityAttributeName));
        }