MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / BuildEntriesDefault

Method BuildEntriesDefault

Source/Editor/GUI/EnumComboBox.cs:241–288  ·  view source on GitHub ↗

Builds the default entries for the given enum type. The type. The output entries. The formatting mode.

(Type type, List<Entry> entries, EnumDisplayAttribute.FormatMode formatMode = EnumDisplayAttribute.FormatMode.Default)

Source from the content-addressed store, hash-verified

239 /// <param name="entries">The output entries.</param>
240 /// <param name="formatMode">The formatting mode.</param>
241 public static void BuildEntriesDefault(Type type, List<Entry> entries, EnumDisplayAttribute.FormatMode formatMode = EnumDisplayAttribute.FormatMode.Default)
242 {
243 FieldInfo[] fields = type.GetFields();
244 entries.Capacity = Mathf.Max(fields.Length - 1, entries.Capacity);
245 if (formatMode == EnumDisplayAttribute.FormatMode.Default)
246 {
247 // Override display mode from enum itself
248 var attr = type.GetCustomAttribute<EnumDisplayAttribute>();
249 if (attr != null)
250 {
251 formatMode = attr.Mode;
252 }
253 }
254 for (int i = 0; i < fields.Length; i++)
255 {
256 var field = fields[i];
257 if (field.Name.Equals("value__", StringComparison.Ordinal))
258 continue;
259
260 var attributes = field.GetCustomAttributes(false);
261 if (attributes.Any(x => x is HideInEditorAttribute))
262 continue;
263
264 string name;
265 var nameAttr = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute);
266 if (nameAttr != null)
267 {
268 name = nameAttr.Name;
269 }
270 else
271 {
272 switch (formatMode)
273 {
274 case EnumDisplayAttribute.FormatMode.Default:
275 name = Utilities.Utils.GetPropertyNameUI(field.Name);
276 break;
277 case EnumDisplayAttribute.FormatMode.None:
278 name = field.Name;
279 break;
280 default: throw new ArgumentOutOfRangeException(nameof(formatMode), formatMode, null);
281 }
282 }
283
284 string tooltip = Editor.Instance.CodeDocs.GetTooltip(new ScriptMemberInfo(field), attributes);
285
286 entries.Add(new Entry(name, Convert.ToInt64(field.GetRawConstantValue()), tooltip));
287 }
288 }
289
290 /// <inheritdoc />
291 protected override void OnLayoutMenuButton(ContextMenuButton button, int index, bool construct = false)

Callers 3

UpdateBoxesMethod · 0.80
UpdateBoxesMethod · 0.80

Calls 7

AnyMethod · 0.80
GetPropertyNameUIMethod · 0.80
GetFieldsMethod · 0.45
MaxMethod · 0.45
EqualsMethod · 0.45
GetTooltipMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected