public static TField GetField <TField>([NotNull] this IHasCustomizableFields source, [NotNull] string name, TField defaultValue = default)
        {
            var value = source.GetField(name);

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

            if (TypeHelper.IsPrimitiveExtended(typeof(TField), includeEnums: true))
            {
                var conversionType = typeof(TField);
                if (TypeHelper.IsNullable(conversionType))
                {
                    conversionType = conversionType.GetFirstGenericArgumentIfNullable();
                }

                if (conversionType == typeof(Guid))
                {
                    return((TField)TypeDescriptor.GetConverter(conversionType).ConvertFromInvariantString(value.ToString()));
                }

                return((TField)Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture));
            }

            throw new AbpException("GetField<TField> does not support non-primitive types. Use non-generic GetField method and handle type casting manually.");
        }
        public static void SetCustomizeFieldsToRegularProperties([NotNull] this IHasCustomizableFields source)
        {
            var properties = source.GetType().GetProperties()
                             .Where(x => source.CustomizedFields.ContainsKey(x.Name) &&
                                    x.GetSetMethod(true) != null)
                             .ToList();

            foreach (var property in properties)
            {
                property.SetValue(source, source.CustomizedFields[property.Name]);
                source.RemoveField(property.Name);
            }
        }
 public static object GetField([NotNull] this IHasCustomizableFields source, [NotNull] string name, object defaultValue = null)
 {
     return(source.CustomizedFields?.GetOrDefault(name)
            ?? defaultValue);
 }
 public static bool HasField([NotNull] this IHasCustomizableFields source, [NotNull] string name)
 {
     return(source.CustomizedFields.ContainsKey(name));
 }