private static Action <object, SerializationContext> ForEnum(Type type, TypeOptions options, Func <Type, TypeDescriptor> descriptorSource) { if (options.HasFlag(TypeOptions.EnumsToStrings)) { return((obj, context) => context.Writer.Write(obj.ToString())); } var descriptor = descriptorSource(Enum.GetUnderlyingType(type)); return((obj, context) => descriptor.Writer(obj, context)); }
private static string BuildName(MemberInfo member, TypeOptions options) { var customName = member.GetCustomAttribute <JsonPropertyAttribute>()?.Name; if (!string.IsNullOrEmpty(customName)) { return(customName); } if (options.HasFlag(TypeOptions.CamelCase)) { return(CamelCase.ToCamelCase(member.Name)); } return(member.Name); }
public static void TypeEditor(this Stencil stencil, TypeHandle typeHandle, Action <TypeHandle, int> onSelection, SearcherFilter filter = null, TypeOptions options = TypeOptions.None) { var wasArray = typeHandle.IsVsArrayType(stencil); var missingTypeReference = TypeHandle.MissingType; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Type"); var selected = EditorGUILayout.DropdownButton(new GUIContent(typeHandle != missingTypeReference ? typeHandle.GetMetadata(stencil).FriendlyName : "<unknown type>"), FocusType.Passive, GUI.skin.button); if (Event.current.type == EventType.Repaint) { s_ButtonRect = GUILayoutUtility.GetLastRect(); } if (selected) { SearcherService.ShowTypes( stencil, EditorWindow.focusedWindow.rootVisualElement.LocalToWorld(s_ButtonRect.center), (t, i) => onSelection(wasArray ? t.MakeVsArrayType(stencil) : t, i), filter ); } EditorGUILayout.EndHorizontal(); if (!options.HasFlag(TypeOptions.AllowArray)) { return; } var newIsArray = EditorGUILayout.Toggle("Is Array", wasArray); if (newIsArray != wasArray) { onSelection(newIsArray ? typeHandle.MakeVsArrayType(stencil) : typeHandle.GetVsArrayElementType(stencil), 0); } }
public bool Has(TypeOptions f) { return(TypeOptions.HasFlag(f)); }