Esempio n. 1
0
        public static string GetPrimitiveTypePropertyDisplayText(object val, PropertyInfo propInfo, string defaultValue)
        {
            if (val == null || val.ToString().Length == 0)
            {
                if (defaultValue == null)
                {
                    return(string.Empty);
                }
                else
                {
                    return(defaultValue);
                }
            }

            string format = EntityExtensions.GetPropertyDisplayFormat(propInfo);

            return(FormatValue(val, propInfo, format, false));
        }
Esempio n. 2
0
        public static bool TryParseToTargetPropertyType(string value, PropertyInfo propInfo, out object parsedValue, out bool hasNewEntityIndicator, string format = null, bool returnNullEvenIfNonNullable = false)
        {
            hasNewEntityIndicator = false;

            if (string.IsNullOrEmpty(format))
            {
                var displayFormatAtt = (DisplayFormatAttribute)ReflectionHelper.GetPropertyAttribute(propInfo, typeof(DisplayFormatAttribute));
                if (displayFormatAtt != null)
                {
                    if (displayFormatAtt.ApplyFormatInEditMode && !string.IsNullOrEmpty(displayFormatAtt.DataFormatString))
                    {
                        format = displayFormatAtt.DataFormatString;
                    }
                }
            }

            var generalDataType = EntityExtensions.GetGeneralDataType(propInfo);

            switch (generalDataType)
            {
            case GeneralDataType.Enum:
                return(TryParseToEnumPropertyType(value, propInfo, out parsedValue, returnNullEvenIfNonNullable));

            case GeneralDataType.ReferenceList:
                return(TryParseToReferenceListPropertyType(value, propInfo, out parsedValue, returnNullEvenIfNonNullable));

            case GeneralDataType.MultiValueReferenceList:
                return(TryParseToMultiValueReferenceListPropertyType(value, propInfo, out parsedValue));

            case GeneralDataType.EntityReference:
                return(TryParseToEntityReferencePropertyType(value, propInfo, out parsedValue, out hasNewEntityIndicator));

            default:
                return(TryParseToValueTypePropertyType(value, propInfo, out parsedValue, format, returnNullEvenIfNonNullable));
            }
        }
Esempio n. 3
0
        private async Task <object> GetPropertyValueAsync <TRow, TId>(TRow entity, string propertyName, bool isExport, string defaultValue = "") where TRow : class, IEntity <TId>
        {
            try
            {
                PropertyInfo propInfo     = null;
                object       parentEntity = null;

                var val = IsDynamic
                    ? await DynamicPropertyManager.Value.GetEntityPropertyAsync <TRow, TId>(entity, propertyName)
                    : ReflectionHelper.GetPropertyValue(entity, propertyName, out parentEntity, out propInfo);

                if (val == null)
                {
                    return(defaultValue);
                }

                var valueType = val.GetType();

                if (valueType.IsEnum)
                {
                    var itemValue = Convert.ToInt64(val);

                    var enumType = valueType;
                    if (enumType.IsNullable())
                    {
                        enumType = Nullable.GetUnderlyingType(enumType);
                    }

                    return(ReflectionHelper.GetEnumDescription(enumType, itemValue));
                }

                if (valueType.IsEntityType())
                {
                    var displayProperty = valueType.GetEntityConfiguration().DisplayNamePropertyInfo;
                    var displayText     = displayProperty != null
                        ? displayProperty.GetValue(val)?.ToString()
                        : val.ToString();

                    if (DataTableConfig != null && !DataTableConfig.UseDtos || isExport)
                    {
                        return(displayText);
                    }

                    var dto = new EntityWithDisplayNameDto <string>(val.GetId().ToString(), displayText);
                    return(dto);
                }


                var propConfig = parentEntity != null && propInfo != null
                    ? parentEntity.GetType().GetEntityConfiguration()[propInfo.Name]
                    : null;

                if (propConfig != null)
                {
                    if (propConfig.GeneralType == Configuration.Runtime.GeneralDataType.ReferenceList)
                    {
                        var refListHelper = StaticContext.IocManager.Resolve <IReferenceListHelper>();
                        var itemValue     = Convert.ToInt64(val);
                        var displayText   = refListHelper.GetItemDisplayText(propConfig.ReferenceListNamespace, propConfig.ReferenceListName, itemValue);

                        if (DataTableConfig != null && !DataTableConfig.UseDtos || isExport)
                        {
                            return(displayText);
                        }

                        var dto = new ReferenceListItemValueDto
                        {
                            Item      = displayText,
                            ItemValue = itemValue
                        };
                        return(dto);
                    }
                    else
                    {
                        return(EntityExtensions.GetPrimitiveTypePropertyDisplayText(val, propInfo, defaultValue));
                    }
                }

                return(val);
            }
            catch (Exception ex)
            {
                throw new Exception(
                          $"An error occured whilst trying to retrieve DisplayText of property '{propertyName}' on type of '{entity.GetType().FullName}'.", ex);
            }
        }
Esempio n. 4
0
        internal static bool TryParseToValueTypePropertyType(string value, PropertyInfo propInfo, out object parsedValue, string format = null, bool returnNullEvenIfNonNullable = false)
        {
            var generalDataType = EntityExtensions.GetGeneralDataType(propInfo);

            return(TryParseToValueTypePropertyType(value, propInfo, generalDataType, out parsedValue, format, returnNullEvenIfNonNullable));
        }