예제 #1
0
        public static IFieldInfo Create(PropertyInfo prop, IEditableRoot editableRoot, IField field, object rawValue, IValidationContext validationContext)
        {
            var customAttr = prop.GetCustomAttribute<CommonSettingsAttribute>();
            var promptAttr = prop.GetCustomAttribute<PromptAttribute>();
            var docAttr = prop.GetCustomAttribute<DocumentationAttribute>();
            var fieldTypeAttr = prop.GetCustomAttribute<FieldTypeAttribute>();
            var hasCalculatedAttr = prop.GetCustomAttributes(typeof(CalculatedAttribute), false).Any();
            var hasDefaultExpressionAttr = prop.GetCustomAttributes(typeof(HasDefaultExpressionAttribute), false).Any();

            //Set common properties
            var fieldInfo = CreateFieldInfo(fieldTypeAttr.ColumnType, prop, rawValue, editableRoot);
            fieldInfo.Id = editableRoot.Id;
            fieldInfo.SystemName = field.SystemName;
            fieldInfo.DisplayName = customAttr.Name;
            fieldInfo.Width = customAttr.Width;
            fieldInfo.CanRead = editableRoot.CanReadProperty(prop.Name);
            fieldInfo.IsRequired = validationContext != null && validationContext.IsRequired(editableRoot.ProcessName, field.SystemName, editableRoot.GetCurrentStateGuid());
            fieldInfo.CanRead = editableRoot.CanReadProperty(prop.Name);
            fieldInfo.CanWrite = editableRoot.CanWriteProperty(prop.Name) && !hasCalculatedAttr;
            fieldInfo.BackColor = GetBackColor(editableRoot, prop);
            fieldInfo.Prompt = promptAttr == null
                ? string.Format(CultureInfo.InvariantCulture,
                    LanguageService.Translate("Tooltip_EnterPrompt"), customAttr.Name)
                : promptAttr.PromptString;

            fieldInfo.IsDocumentationAvailable = docAttr != null;

            if (hasCalculatedAttr || hasDefaultExpressionAttr)
            {
                fieldInfo.ExpressionType = hasCalculatedAttr ? FieldExpressionType.Calculated : FieldExpressionType.Default;
                fieldInfo.Expression = GetExpression(editableRoot, prop);
            }

            // docAttr == null ? string.Empty : ClrUnicodeConverter.ToText(docAttr.DocumentationBody),

            return fieldInfo;
        }