示例#1
0
        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));
        }
示例#2
0
        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);
        }
示例#3
0
        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);
            }
        }
示例#4
0
文件: Backend.cs 项目: lee1431/uno
 public bool Has(TypeOptions f)
 {
     return(TypeOptions.HasFlag(f));
 }