/// <inheritdoc /> public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (!Attribute.Show) { return(-2.0f); } // Check for multiline or textarea attributes object[] customAttributes = fieldInfo.GetCustomAttributes(false); for (int i = 0; i < customAttributes.Length; i++) { if (customAttributes[i] is MultilineAttribute) { return((float)((!EditorGUIUtility.wideMode ? 16.0 : 0.0) + 16.0) + (float)((((MultilineAttribute)customAttributes[i]).lines - 1) * 13)); } else if (customAttributes[i] is TextAreaAttribute) { PropertyInfo propertyInfo = typeof(EditorGUIUtility).GetProperty("contextWidth", BindingFlags.Static | BindingFlags.NonPublic); float contextWidth = (float)propertyInfo.GetValue(null, null); TextAreaAttribute textAreaAttribute = (TextAreaAttribute)customAttributes[i]; return(32f + (float)((Mathf.Clamp(Mathf.CeilToInt(EditorStyles.textArea.CalcHeight( new GUIContent(property.stringValue), contextWidth) / 13f), textAreaAttribute.minLines, textAreaAttribute.maxLines) - 1) * 13)); } } return(base.GetPropertyHeight(property, label)); }
public static void SettingField(Setting setting, Func <string, string> callback) { if (setting == null) { return; } TextAreaAttribute textAreaAttr = setting.field.GetCustomAttribute <TextAreaAttribute>(); if (setting.type == typeof(string)) { string stringValue = (string)setting.field.GetValue(setting.obj); EditorGUILayout.BeginHorizontal(); if (textAreaAttr != null) { stringValue = EditorGUILayout.TextArea(setting.label, stringValue); } else { stringValue = EditorGUILayout.TextField(setting.label, stringValue); } if (GUILayout.Button("...", Styles.buttonStyle)) { stringValue = callback?.Invoke(stringValue); } EditorGUILayout.EndHorizontal(); setting.field.SetValue(setting.obj, stringValue); } firstElement = false; }
public sealed override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (property.propertyType != SerializedPropertyType.String) { return(EditorGUI.GetPropertyHeight(property, label, true)); } TextAreaAttribute attr = attribute as TextAreaAttribute; int nl = 1; { foreach (var c in property.stringValue) { if (c == '\n') { nl++; } } } if (nl < attr.minLines) { nl = attr.minLines; } if (nl > attr.maxLines) { nl = attr.maxLines; } //Debug.Log("space" + EditorGUIUtility.standardVerticalSpacing.ToString()); height = EditorGUIUtility.singleLineHeight - 3; return(height * (nl + 1) + 3 * 2); }
// Start is called before the first frame update void Start() { System.Type t = type.GetType(); //print("FullName: " + t.Name); FieldInfo[] info = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); for (int i = 0; i < info.Length; i++) { //print("PropName: " + info[i].Name); //print("Type: " + info[i].FieldType); //print("Value: " + info[i].GetValue(type)); object[] obj = info[i].GetCustomAttributes(false); TextAreaAttribute att = (TextAreaAttribute)info[i].GetCustomAttribute(typeof(TextAreaAttribute), false); if (att != null) { //print(att.minLines); //print(att.maxLines); } for (int a = 0; a < obj.Length; a++) { //print("Attri: " + obj[a]); } } }
public LocalizedStringDrawer(FieldInfo fieldInfo, object value, object parentValue, int arrayIndex) : base(fieldInfo, value, parentValue, arrayIndex) { _textArea = (TextAreaAttribute)fieldInfo.GetCustomAttributes(typeof(TextAreaAttribute), true).FirstOrDefault(); _keyField = typeof(LocalizedString).GetField("_key", BindingFlags.Instance | BindingFlags.NonPublic); Update(); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { TextAreaAttribute attribute = base.attribute as TextAreaAttribute; string stringValue = property.stringValue; int num2 = Mathf.Clamp(Mathf.CeilToInt(EditorStyles.textArea.CalcHeight(GUIContent.Temp(stringValue), EditorGUIUtility.contextWidth) / 13f), attribute.minLines, attribute.maxLines); return(32f + ((num2 - 1) * 13)); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { _textArea = (TextAreaAttribute)fieldInfo.GetCustomAttributes(typeof(TextAreaAttribute), true).FirstOrDefault(); if (_textArea != null) { return(ReflectionDrawerStyles.singleLineHeight * 2 + (ReflectionDrawerStyles.singleLineHeight * Mathf.Max(_textArea.maxLines, 3))); } return(ReflectionDrawerStyles.singleLineHeight * 2); }
protected void ReadTextAreaAttribute() { var taAttrList = base.fieldInfo.GetCustomAttributes(typeof(TextAreaAttribute), true); if (taAttrList.Length > 0) { textAreaAttribute = (TextAreaAttribute)taAttrList[0]; } checkedForTextArea = true; }
private static void SetTextArea(ExpandoObject field, TextAreaAttribute textarea) { field.TryAdd("type", ReactFormItemType.TextArea); field.TryAdd("textarea", new { textarea.Placeholder, textarea.Rows, textarea.MaxLength, textarea.Disabled, }); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { TextAreaAttribute textAreaAttribute = attribute as TextAreaAttribute; string text = property.stringValue; float fullTextHeight = EditorStyles.textArea.CalcHeight(GUIContent.Temp(text), EditorGUIUtility.contextWidth); int lines = Mathf.CeilToInt(fullTextHeight / kLineHeight); lines = Mathf.Clamp(lines, textAreaAttribute.minLines, textAreaAttribute.maxLines); return(EditorGUI.kSingleLineHeight // header + EditorGUI.kSingleLineHeight // first line + (lines - 1) * kLineHeight); // remaining lines }
public override void Draw(InspectorField field, GUIStyle style) { GUILayout.BeginHorizontal(); float width = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 0; TextFieldAttribute text = field.GetAttribute <TextFieldAttribute>(); MultilineAttribute multiline = field.GetAttribute <MultilineAttribute>(); TextAreaAttribute area = field.GetAttribute <TextAreaAttribute>(); object value = GetValue(field); EditorGUI.BeginChangeCheck(); GUIUtility.GetControlID(field.Path.GetHashCode(), FocusType.Passive); string result = ""; if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard)) { if (style != null) { result = EditorGUILayout.TextField((string)value, style); } else { result = EditorGUILayout.TextField((string)value); } } else if (multiline != null || area != null || text.Type == TextFieldType.Area) { if (style != null) { result = EditorGUILayout.TextArea((string)value, style); } else { result = EditorGUILayout.TextArea((string)value); } } else if (text.Type == TextFieldType.Password) { if (style != null) { result = EditorGUILayout.PasswordField((string)value, style); } else { result = EditorGUILayout.PasswordField((string)value); } } else if (text.Type == TextFieldType.Tag) { if (style != null) { result = EditorGUILayout.TagField((string)value, style); } else { result = EditorGUILayout.TagField((string)value); } } else if (text.Type == TextFieldType.File) { if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2))) { result = EditorUtility.OpenFilePanel(text.Title, text.Path, text.Extension); } if (field.Mixed) { GUILayout.Label("---"); } else { GUILayout.Label((string)value); } } else if (text.Type == TextFieldType.Folder) { if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2))) { result = EditorUtility.OpenFolderPanel(text.Title, "", ""); } if (field.Mixed) { GUILayout.Label("---"); } else { GUILayout.Label((string)value); } } if (EditorGUI.EndChangeCheck()) { field.SetValue(result); } EditorGUIUtility.labelWidth = width; GUILayout.EndHorizontal(); }
public override void Draw(InspectorField field, GUIStyle style) { GUILayout.BeginHorizontal(); float width = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 0; TextFieldAttribute text = field.GetAttribute <TextFieldAttribute>(); MultilineAttribute multiline = field.GetAttribute <MultilineAttribute>(); TextAreaAttribute area = field.GetAttribute <TextAreaAttribute>(); object value = GetValue(field); EditorGUI.BeginChangeCheck(); GUIUtility.GetControlID(field.Path.GetHashCode(), FocusType.Passive); string result = ""; if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard)) { if (style != null) { result = EditorGUILayout.TextField((string)value, style); } else { result = EditorGUILayout.TextField((string)value); } } else if (multiline != null || area != null || text.Type == TextFieldType.Area) { if (style != null) { result = EditorGUILayout.TextArea((string)value, style); } else { result = EditorGUILayout.TextArea((string)value); } } else if (text.Type == TextFieldType.Password) { if (style != null) { result = EditorGUILayout.PasswordField((string)value, style); } else { result = EditorGUILayout.PasswordField((string)value); } } else if (text.Type == TextFieldType.Tag) { if (style != null) { result = EditorGUILayout.TagField((string)value, style); } else { result = EditorGUILayout.TagField((string)value); } } else if (text.Type == TextFieldType.File) { if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2))) { result = EditorUtility.OpenFilePanel(text.Title, text.Path, text.Extension); } if (field.Mixed) { GUILayout.Label("---"); } else { GUILayout.Label((string)value); } } else if (text.Type == TextFieldType.Folder) { if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2))) { result = EditorUtility.OpenFolderPanel(text.Title, "", ""); } if (field.Mixed) { GUILayout.Label("---"); } else { GUILayout.Label((string)value); } } //Custom else if (text.Type == TextFieldType.Prefab) { if (String.IsNullOrEmpty(text.Path)) { string prefabRemoved = field.GetValue <string>().Replace("Prefabs/", ""); //string prefabRemoved = field.GetValue<string>(); string[] PrefabListNoPrefix = UnityDrawerStatics.PrefabList .Select(x => x.Replace("Prefabs/", "")) .ToArray(); PrefabListNoPrefix = AddNoneToStringArray(PrefabListNoPrefix); //int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.PrefabList, prefabRemoved), 0); int sel = Math.Max(Array.IndexOf(PrefabListNoPrefix, prefabRemoved), 0); int idx = EditorGUILayout.Popup(sel, PrefabListNoPrefix); //result = "Prefabs/" + UnityDrawerStatics.PrefabList[idx]; //result = UnityDrawerStatics.PrefabList[idx]; result = "Prefabs/" + PrefabListNoPrefix[idx]; } else { //Debug.Log($"Pruning by {text.Path}"); string[] pruned = PrunePrefabListByPath(UnityDrawerStatics.PrefabList, text.Path); pruned = AddNoneToStringArray(pruned); string prefabRemoved = field.GetValue <string>().Replace("Prefabs/", ""); int sel = Math.Max(Array.IndexOf(pruned, prefabRemoved), 0); int idx = EditorGUILayout.Popup(sel, pruned); result = "Prefabs/" + pruned[idx]; //Debug.Log($"Result of prune is {result}"); } } else if (text.Type == TextFieldType.Entity) { int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.EntityList, field.GetValue <string>()), 0); int idx = EditorGUILayout.Popup(sel, UnityDrawerStatics.EntityList); result = UnityDrawerStatics.EntityList[idx]; } else if (text.Type == TextFieldType.Component) { int sel = Math.Max(Array.IndexOf(UnityDrawerStatics.ComponentList, field.GetValue <string>()), 0); int idx = EditorGUILayout.Popup(sel, UnityDrawerStatics.ComponentList); result = UnityDrawerStatics.ComponentList[idx]; } if (EditorGUI.EndChangeCheck()) { field.SetValue(result); } EditorGUIUtility.labelWidth = width; GUILayout.EndHorizontal(); }
public StringDrawer(FieldInfo fieldInfo, object value, object parentValue, int arrayIndex) : base(fieldInfo, value, parentValue, arrayIndex) { _textArea = (TextAreaAttribute)fieldInfo.GetCustomAttributes(typeof(TextAreaAttribute), true).FirstOrDefault(); }
public static KeyValuePair <string, List <ProductValue> > CreateValue(this TextAreaAttribute attribute, string data, string locale = null, string scope = null) { return(attribute.CreateValue((object)data, locale, scope)); }
public void Load(NodeBase node = null) { //Set current base Base = node != null ? node : Base; //Set position transform.localPosition = new Vector3(Base.NodePosition.x, Base.NodePosition.y); //Set label Label.text = Base.Label; #region Set Input ports for (int i = 0; i < Base.InputPorts.Count; i++) { CachePool.I().GetObject("Prefabs/InputPort", (obj) => { obj.transform.SetParent(InputParent, false); RuntimePort rp = obj.GetComponent <RuntimePort>(); rp.Load(Base.InputPorts[i]); InputPorts.Add(rp); RuntimeGraph.I().Ports.Add(rp.Base.UID, rp); }); } #endregion #region Set Output ports for (int i = 0; i < Base.OutputPorts.Count; i++) { CachePool.I().GetObject("Prefabs/OutputPort", (obj) => { obj.transform.SetParent(OutputParent, false); RuntimePort rp = obj.GetComponent <RuntimePort>(); rp.Load(Base.OutputPorts[i]); OutputPorts.Add(rp); RuntimeGraph.I().Ports.Add(rp.Base.UID, rp); }); } #endregion #region Set Content System.Type t = Base.GetType(); FieldInfo[] info = t.GetFields(); int ContentCounter = 0; int FieldsCount = 0; for (int i = 0; i < info.Length; i++) { HideFieldAttribute hideAtt = (HideFieldAttribute)info[i].GetCustomAttribute(typeof(HideFieldAttribute), false); if (hideAtt != null) { continue; } FieldsCount++; if (!Base.ShowedPropertiesList.Contains(info[i].Name)) { continue; } ContentCounter++; System.Type CurType = info[i].FieldType; string HumanReadableName = info[i].Name.Replace("_", " "); if (CurType == RuntimeGraph.I().stringType) { TextAreaAttribute att = (TextAreaAttribute)info[i].GetCustomAttribute(typeof(TextAreaAttribute), false); if (att == null) { GetInputer("String", HumanReadableName, info[i].GetValue(Base)); } else { GetInputer("StringMultiline", HumanReadableName, info[i].GetValue(Base)); } } else if (CurType == RuntimeGraph.I().intType) { RangeAttribute att = (RangeAttribute)info[i].GetCustomAttribute(typeof(RangeAttribute), false); if (att == null) { GetInputer("Int", HumanReadableName, info[i].GetValue(Base)); } else { CachePool.I().GetObject("Prefabs/Content/Int_Range", (obj) => { obj.transform.SetParent(ContentParent, false); IntRange inputer = obj.GetComponent <IntRange>(); inputer.SetLabel(HumanReadableName); inputer.SetValue(info[i].GetValue(Base)); inputer.SetRange(att.min, att.max); BaseInputer.Add(HumanReadableName, inputer); }); } } else if (CurType == RuntimeGraph.I().floatType) { RangeAttribute att = (RangeAttribute)info[i].GetCustomAttribute(typeof(RangeAttribute), false); if (att == null) { GetInputer("Decimal", HumanReadableName, info[i].GetValue(Base)); } else { CachePool.I().GetObject("Prefabs/Content/Decimal_Range", (obj) => { obj.transform.SetParent(ContentParent, false); DecimalRange inputer = obj.GetComponent <DecimalRange>(); inputer.SetLabel(HumanReadableName); inputer.SetValue(info[i].GetValue(Base)); inputer.SetRange(att.min, att.max); BaseInputer.Add(HumanReadableName, inputer); }); } } else if (CurType == RuntimeGraph.I().Vector2Type) { GetInputer("Vector2", HumanReadableName, info[i].GetValue(Base)); } else if (CurType == RuntimeGraph.I().Vector3Type) { GetInputer("Vector3", HumanReadableName, info[i].GetValue(Base)); } else if (CurType == RuntimeGraph.I().Vector4Type) { GetInputer("Vector4", HumanReadableName, info[i].GetValue(Base)); } else if (CurType == RuntimeGraph.I().QuaternionType) { GetInputer("Vector4", HumanReadableName, info[i].GetValue(Base)); } else if (CurType == RuntimeGraph.I().boolType) { GetInputer("Toggle", HumanReadableName, info[i].GetValue(Base)); } else if (CurType == RuntimeGraph.I().enumType) { GetInputer("Dropdown", HumanReadableName, info[i].GetValue(Base)); CachePool.I().GetObject("Prefabs/Content/Dropdown", (obj) => { obj.transform.SetParent(ContentParent, false); DropdownMenu inputer = obj.GetComponent <DropdownMenu>(); object temp = info[i].GetValue(Base); inputer.SetEnum(info[i].FieldType); inputer.SetLabel(HumanReadableName); inputer.SetValue(temp); BaseInputer.Add(HumanReadableName, inputer); }); } } #endregion #region Set Add Button if (ContentCounter < FieldsCount) { CachePool.I().GetObject("Prefabs/Content/AddButton", (obj) => { obj.transform.SetParent(ContentParent, false); }); } #endregion }
/// <inheritdoc /> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Retrieve attributes List <ConditionalAttribute> conditionalAttributes = new List <ConditionalAttribute>(); // ColorUsageAttribute colorUsageAttribute = null; #if UNITY_5_3_OR_NEWER DelayedAttribute delayedAttribute = null; #endif MultilineAttribute multilineAttribute = null; TextAreaAttribute textAreaAttribute = null; RangeAttribute rangeAttribute = null; ReadOnlyAttribute readOnlyAttribute = null; object[] customAttributes = fieldInfo.GetCustomAttributes(false); for (int i = 0; i < customAttributes.Length; i++) { if (customAttributes[i] is ConditionalAttribute) { conditionalAttributes.Add((ConditionalAttribute)customAttributes[i]); } // else if (customAttributes[i] is ColorUsageAttribute) // { // colorUsageAttribute = (ColorUsageAttribute)customAttributes[i]; // } #if UNITY_5_3_OR_NEWER else if (customAttributes[i] is DelayedAttribute) { delayedAttribute = (DelayedAttribute)customAttributes[i]; } #endif else if (customAttributes[i] is MultilineAttribute) { multilineAttribute = (MultilineAttribute)customAttributes[i]; } else if (customAttributes[i] is TextAreaAttribute) { textAreaAttribute = (TextAreaAttribute)customAttributes[i]; } else if (customAttributes[i] is RangeAttribute) { rangeAttribute = (RangeAttribute)customAttributes[i]; } else if (customAttributes[i] is ReadOnlyAttribute) { readOnlyAttribute = (ReadOnlyAttribute)customAttributes[i]; } else if (customAttributes[i] is TooltipAttribute || customAttributes[i] is SerializeField || customAttributes[i] is NonSerializedAttribute) { // Ignored attributes } else { Debug.LogWarning("ConditionalPropertyDrawer needs implementation for type " + customAttributes[i].ToString()); } } int conditionCount = 0; for (int i = 0; i < conditionalAttributes.Count; i++) { if (conditionalAttributes[i].Conditions != null) { conditionCount += conditionalAttributes[i].Conditions.Length; } } ConditionalAttribute.Condition[] conditions = new ConditionalAttribute.Condition[conditionCount]; int index = 0; for (int i = 0; i < conditionalAttributes.Count; i++) { if (conditionalAttributes[i].Conditions != null) { ConditionalAttribute.Condition[] conds = conditionalAttributes[i].Conditions; for (int j = 0; j < conds.Length; j++) { conditions[index++] = conds[j]; } } } Attribute.Show = true; try { Attribute.Show = ShouldShow(property, conditions); } catch (Exception e) { Debug.LogException(e); } if (Attribute.Show) { if (readOnlyAttribute != null) { GUI.enabled = false; } // Implementations obtained through inspection #if UNITY_5_3_OR_NEWER if (delayedAttribute != null) { PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.DelayedDrawer,UnityEditor"); propertyDrawer.OnGUI(position, property, label); } else #endif /* if (colorUsageAttribute != null) * { * * EditorGUI.BeginChangeCheck(); #if UNITY_5_3_OR_NEWER * ColorPickerHDRConfig hdrConfig = new ColorPickerHDRConfig( * colorUsageAttribute.minBrightness, colorUsageAttribute.maxBrightness, * colorUsageAttribute.minExposureValue, colorUsageAttribute.maxExposureValue); * Color color = EditorGUI.ColorField(position, label, property.colorValue, * true, colorUsageAttribute.showAlpha, colorUsageAttribute.hdr, hdrConfig); #else * Color color = EditorGUI.ColorField(position, label, property.colorValue); #endif * if (EditorGUI.EndChangeCheck()) * { * property.colorValue = color; * } * } * else */ if (multilineAttribute != null) { PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.MultilineDrawer,UnityEditor"); propertyDrawer.OnGUI(position, property, label); } else if (textAreaAttribute != null) { PropertyDrawer propertyDrawer = GetPropertyDrawer("UnityEditor.TextAreaDrawer,UnityEditor"); propertyDrawer.OnGUI(position, property, label); } else if (rangeAttribute != null) { if (property.propertyType == SerializedPropertyType.Float) { EditorGUI.Slider(position, property, rangeAttribute.min, rangeAttribute.max, label); } else if (property.propertyType == SerializedPropertyType.Integer) { EditorGUI.IntSlider(position, property, (int)rangeAttribute.min, (int)rangeAttribute.max, label); } else { EditorGUI.LabelField(position, label.text, "Use Range with float or int."); } } else { EditorGUI.PropertyField(position, property, label, false); } if (readOnlyAttribute != null) { GUI.enabled = true; } } }
private void LoadAttributes(ModelMetadata metadata) { //TO-DO: Refazer os métodos para tornar-los mais dinâmicos... if (metadata != null) { MetadataAttribute commonAttribute = new MetadataAttribute() { AttributeName = "Common" + "Attribute", Property = new Dictionary <string, object>() { { "DisplayName", metadata.DisplayName }, { "ShortDisplayName", metadata.ShortDisplayName }, { "IsRequired", metadata.IsRequired }, { "IsReadOnly", metadata.IsReadOnly }, { "IsNullableValueType", metadata.IsNullableValueType }, { "Description", metadata.Description }, { "Watermark", metadata.Watermark }, { "ShowForDisplay", metadata.ShowForDisplay }, { "ShowForEdit", metadata.ShowForEdit }, { "DataTypeName", metadata.DataTypeName }, { "IsComplexType", metadata.IsComplexType }, { "EditFormatString", metadata.EditFormatString }, { "HideSurroundingHtml", metadata.HideSurroundingHtml }, { "HtmlEncode", metadata.HtmlEncode }, { "ConvertEmptyStringToNull", metadata.ConvertEmptyStringToNull }, { "NullDisplayText", metadata.NullDisplayText }, { "SimpleDisplayText", metadata.SimpleDisplayText }, { "TemplateHint", metadata.TemplateHint }, { "DisplayFormatString", metadata.DisplayFormatString }, } }; metadataAttributes.Add(commonAttribute); } HtmlAttributesAttribute htmlAttributesAttribute = GetModelMetadataAttributes(metadata).OfType <HtmlAttributesAttribute>().FirstOrDefault(); if (htmlAttributesAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "HtmlAttributes" + "Attribute", Property = new Dictionary <string, object>() { { "ID", htmlAttributesAttribute.ID }, { "Name", htmlAttributesAttribute.Name }, { "Class", htmlAttributesAttribute.Class }, { "Style", htmlAttributesAttribute.Style }, { "Width", htmlAttributesAttribute.Width }, { "Height", htmlAttributesAttribute.Height }, { "Placeholder", htmlAttributesAttribute.Placeholder }, } }; metadataAttributes.Add(metaAttribute); } DataTypeAttribute dataTypeAttribute = GetModelMetadataAttributes(metadata).OfType <DataTypeAttribute>().FirstOrDefault(); if (dataTypeAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "DataType" + "Attribute", Property = new Dictionary <string, object>() { { "DataType", dataTypeAttribute.DataType }, { "ErrorMessage", dataTypeAttribute.ErrorMessage }, { "ErrorMessageResourceName", dataTypeAttribute.ErrorMessageResourceName }, { "RequiresValidationContext", dataTypeAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } DataTypeFieldAttribute dataTypeFieldAttribute = GetModelMetadataAttributes(metadata).OfType <DataTypeFieldAttribute>().FirstOrDefault(); if (dataTypeFieldAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "DataTypeField" + "Attribute", Property = new Dictionary <string, object>() { { "DataType", dataTypeFieldAttribute.DataType }, { "ErrorMessage", dataTypeFieldAttribute.ErrorMessage }, { "ErrorMessageResourceName", dataTypeFieldAttribute.ErrorMessageResourceName }, { "RequiresValidationContext", dataTypeFieldAttribute.RequiresValidationContext }, { "Cols", dataTypeFieldAttribute.Cols }, { "Rows", dataTypeFieldAttribute.Rows }, { "Wrap", (dataTypeFieldAttribute.HardWrap ? "hard" : null) }, { "MinLength", dataTypeFieldAttribute.MinLength }, { "MaxLength", dataTypeFieldAttribute.MaxLength }, } }; metadataAttributes.Add(metaAttribute); } RegularExpressionAttribute regularExpressionAttribute = GetModelMetadataAttributes(metadata).OfType <RegularExpressionAttribute>().FirstOrDefault(); if (regularExpressionAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "RegularExpression" + "Attribute", Property = new Dictionary <string, object>() { { "Pattern", regularExpressionAttribute.Pattern }, { "ErrorMessage", regularExpressionAttribute.ErrorMessage }, { "ErrorMessageResourceName", regularExpressionAttribute.ErrorMessageResourceName }, { "RequiresValidationContext", regularExpressionAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } StringLengthAttribute stringLengthAttribute = GetModelMetadataAttributes(metadata).OfType <StringLengthAttribute>().FirstOrDefault(); if (stringLengthAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "StringLength" + "Attribute", Property = new Dictionary <string, object>() { { "MinimumLength", stringLengthAttribute.MinimumLength }, { "MaximumLength", stringLengthAttribute.MaximumLength }, { "ErrorMessage", stringLengthAttribute.ErrorMessage }, { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) }, { "ErrorMessageResourceName", stringLengthAttribute.ErrorMessageResourceName }, { "RequiresValidationContext", stringLengthAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } MinLengthAttribute minLengthAttribute = GetModelMetadataAttributes(metadata).OfType <MinLengthAttribute>().FirstOrDefault(); if (minLengthAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "MinLength" + "Attribute", Property = new Dictionary <string, object>() { { "Length", minLengthAttribute.Length }, { "TypeId", minLengthAttribute.TypeId }, { "ErrorMessage", minLengthAttribute.ErrorMessage }, { "ErrorMessageResourceName", minLengthAttribute.ErrorMessageResourceName }, { "RequiresValidationContext", minLengthAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } MaxLengthAttribute maxLengthAttribute = GetModelMetadataAttributes(metadata).OfType <MaxLengthAttribute>().FirstOrDefault(); if (maxLengthAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "MaxLength" + "Attribute", Property = new Dictionary <string, object>() { { "Length", maxLengthAttribute.Length }, { "TypeId", maxLengthAttribute.TypeId }, { "ErrorMessage", maxLengthAttribute.ErrorMessage }, { "ErrorMessageResourceName", maxLengthAttribute.ErrorMessageResourceName }, { "RequiresValidationContext", maxLengthAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } DisplayAttribute displayAttribute = GetModelMetadataAttributes(metadata).OfType <DisplayAttribute>().FirstOrDefault(); if (displayAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "Display" + "Attribute", Property = new Dictionary <string, object>() { { "ShortName", displayAttribute.ShortName }, { "Name", displayAttribute.Name }, { "Prompt", displayAttribute.Prompt }, { "GroupName", displayAttribute.GroupName }, { "Description", displayAttribute.Description }, } }; metadataAttributes.Add(metaAttribute); } RequiredAttribute requiredAttribute = GetModelMetadataAttributes(metadata).OfType <RequiredAttribute>().FirstOrDefault(); if (requiredAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "Required" + "Attribute", Property = new Dictionary <string, object>() { { "IsRequired", true }, { "AllowEmptyStrings", requiredAttribute.AllowEmptyStrings }, { "ErrorMessage", requiredAttribute.ErrorMessage }, { "ErrorMessageResourceName", requiredAttribute.ErrorMessageResourceName }, { "RequiresValidationContext", requiredAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } RangeAttribute rangeAttribute = GetModelMetadataAttributes(metadata).OfType <RangeAttribute>().FirstOrDefault(); if (rangeAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "Range" + "Attribute", Property = new Dictionary <string, object>() { { "OperandType", rangeAttribute.OperandType }, { "AllowEmptyStrings", rangeAttribute.Minimum }, { "Maximum", rangeAttribute.Maximum }, { "ErrorMessage", rangeAttribute.ErrorMessage }, { "ErrorMessageResourceName", rangeAttribute.ErrorMessageResourceName }, { "RequiresValidationContext", rangeAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } DisplayFormatAttribute displayFormatAttribute = GetModelMetadataAttributes(metadata).OfType <DisplayFormatAttribute>().FirstOrDefault(); if (displayFormatAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "DisplayFormat" + "Attribute", Property = new Dictionary <string, object>() { { "DataFormatString", displayFormatAttribute.DataFormatString }, { "ApplyFormatInEditMode", displayFormatAttribute.ApplyFormatInEditMode }, { "ConvertEmptyStringToNull", displayFormatAttribute.ConvertEmptyStringToNull }, { "HtmlEncode", displayFormatAttribute.HtmlEncode }, { "NullDisplayText", displayFormatAttribute.NullDisplayText }, { "IsDefault" + "Attribute", displayFormatAttribute.IsDefaultAttribute() }, } }; metadataAttributes.Add(metaAttribute); } CreditCardAttribute creditCardAttribute = GetModelMetadataAttributes(metadata).OfType <CreditCardAttribute>().FirstOrDefault(); if (creditCardAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "CreditCard" + "Attribute", Property = new Dictionary <string, object>() { { "DataType", creditCardAttribute.DataType }, { "CustomDataType", creditCardAttribute.CustomDataType }, { "DisplayFormat", creditCardAttribute.DisplayFormat }, { "ErrorMessage", creditCardAttribute.ErrorMessage }, { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) }, { "ErrorMessageResourceName", creditCardAttribute.ErrorMessageResourceName }, { "ErrorMessageResourceType", creditCardAttribute.ErrorMessageResourceType }, { "RequiresValidationContext", creditCardAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } CustomValidationAttribute customValidationAttribute = GetModelMetadataAttributes(metadata).OfType <CustomValidationAttribute>().FirstOrDefault(); if (customValidationAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "CustomValidation" + "Attribute", Property = new Dictionary <string, object>() { { "ValidatorType", customValidationAttribute.ValidatorType }, { "Method", customValidationAttribute.Method }, { "ErrorMessage", creditCardAttribute.ErrorMessage }, { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) }, { "ErrorMessageResourceName", creditCardAttribute.ErrorMessageResourceName }, { "ErrorMessageResourceType", creditCardAttribute.ErrorMessageResourceType }, { "RequiresValidationContext", creditCardAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } EmailAddressAttribute emailAddressAttribute = GetModelMetadataAttributes(metadata).OfType <EmailAddressAttribute>().FirstOrDefault(); if (emailAddressAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "EmailAddress" + "Attribute", Property = new Dictionary <string, object>() { { "DataType", emailAddressAttribute.DataType }, { "CustomDataType", emailAddressAttribute.CustomDataType }, { "DisplayFormat", emailAddressAttribute.DisplayFormat }, { "ErrorMessage", creditCardAttribute.ErrorMessage }, { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) }, { "ErrorMessageResourceName", creditCardAttribute.ErrorMessageResourceName }, { "ErrorMessageResourceType", creditCardAttribute.ErrorMessageResourceType }, { "RequiresValidationContext", creditCardAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } FileExtensionsAttribute fileExtensionsAttribute = GetModelMetadataAttributes(metadata).OfType <FileExtensionsAttribute>().FirstOrDefault(); if (fileExtensionsAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "FileExtensions" + "Attribute", Property = new Dictionary <string, object>() { { "DataType", emailAddressAttribute.DataType }, { "CustomDataType", emailAddressAttribute.CustomDataType }, { "DisplayFormat", emailAddressAttribute.DisplayFormat }, { "ErrorMessage", creditCardAttribute.ErrorMessage }, { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) }, { "ErrorMessageResourceName", creditCardAttribute.ErrorMessageResourceName }, { "ErrorMessageResourceType", creditCardAttribute.ErrorMessageResourceType }, { "RequiresValidationContext", creditCardAttribute.RequiresValidationContext }, } }; metadataAttributes.Add(metaAttribute); } TimestampAttribute timestampAttribute = GetModelMetadataAttributes(metadata).OfType <TimestampAttribute>().FirstOrDefault(); if (timestampAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "FileExtensions" + "Attribute", Property = new Dictionary <string, object>() { { "TypeId", timestampAttribute.TypeId }, } }; metadataAttributes.Add(metaAttribute); } ViewDisabledAttribute viewDisabledAttribute = GetModelMetadataAttributes(metadata).OfType <ViewDisabledAttribute>().FirstOrDefault(); if (viewDisabledAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "ViewDisabled" + "Attribute", Property = new Dictionary <string, object>() { { "Declared", true }, } }; metadataAttributes.Add(metaAttribute); } TextAreaAttribute textAreaAttribute = GetModelMetadataAttributes(metadata).OfType <TextAreaAttribute>().FirstOrDefault(); if (textAreaAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "TextArea" + "Attribute", Property = new Dictionary <string, object>() { { "Cols", textAreaAttribute.Cols }, { "Rows", textAreaAttribute.Rows }, { "Wrap", (textAreaAttribute.HardWrap ? "hard" : null) }, { "MinLength", textAreaAttribute.MinLength }, { "MaxLength", textAreaAttribute.MaxLength }, } }; metadataAttributes.Add(metaAttribute); } OnlyNumberAttribute onlyNumberAttribute = GetModelMetadataAttributes(metadata).OfType <OnlyNumberAttribute>().FirstOrDefault(); if (onlyNumberAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "OnlyNumber" + "Attribute", Property = new Dictionary <string, object>() { { "Declared", true }, { "ClassDecorator", "onlyNumber" }, } }; metadataAttributes.Add(metaAttribute); } CurrencyAttribute currencyAttribute = GetModelMetadataAttributes(metadata).OfType <CurrencyAttribute>().FirstOrDefault(); if (currencyAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "Currency" + "Attribute", Property = new Dictionary <string, object>() { { "Declared", true }, { "ClassDecorator", "onlyNumber" }, { "Pattern", "currency" }, } }; metadataAttributes.Add(metaAttribute); } NoEspecialCharsAttribute noEspecialCharsAttribute = GetModelMetadataAttributes(metadata).OfType <NoEspecialCharsAttribute>().FirstOrDefault(); if (noEspecialCharsAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "NoEspecialChars" + "Attribute", Property = new Dictionary <string, object>() { { "Declared", true }, { "ClassDecorator", "noCaracEsp" }, } }; metadataAttributes.Add(metaAttribute); } ProgressAttribute progressAttribute = GetModelMetadataAttributes(metadata).OfType <ProgressAttribute>().FirstOrDefault(); if (progressAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "Progress" + "Attribute", Property = new Dictionary <string, object>() { { "MinValue", progressAttribute.MinValue }, { "MaxValue", progressAttribute.MaxValue }, { "Step", progressAttribute.Step }, } }; metadataAttributes.Add(metaAttribute); } PlaceHolderAttribute placeHolderAttribute = GetModelMetadataAttributes(metadata).OfType <PlaceHolderAttribute>().FirstOrDefault(); if (placeHolderAttribute != null) { MetadataAttribute metaAttribute = new MetadataAttribute() { AttributeName = "PlaceHolder" + "Attribute", Property = new Dictionary <string, object>() { { "Declared", true }, { "Text", placeHolderAttribute.Text }, } }; metadataAttributes.Add(metaAttribute); } }