Exemple #1
0
            public static MatcherJson FromMatcher(InputDeviceMatcher matcher)
            {
                if (matcher.empty)
                {
                    return(new MatcherJson());
                }

                var json = new MatcherJson();

                foreach (var pattern in matcher.m_Patterns)
                {
                    var key   = pattern.Key;
                    var value = pattern.Value.ToString();

                    if (key == kInterfaceKey)
                    {
                        if (json.@interface == null)
                        {
                            json.@interface = value;
                        }
                        else
                        {
                            ArrayHelpers.Append(ref json.interfaces, value);
                        }
                    }
                    else if (key == kDeviceClassKey)
                    {
                        if (json.deviceClass == null)
                        {
                            json.deviceClass = value;
                        }
                        else
                        {
                            ArrayHelpers.Append(ref json.deviceClasses, value);
                        }
                    }
                    else if (key == kManufacturerKey)
                    {
                        if (json.manufacturer == null)
                        {
                            json.manufacturer = value;
                        }
                        else
                        {
                            ArrayHelpers.Append(ref json.manufacturers, value);
                        }
                    }
                    else if (key == kProductKey)
                    {
                        if (json.product == null)
                        {
                            json.product = value;
                        }
                        else
                        {
                            ArrayHelpers.Append(ref json.products, value);
                        }
                    }
                    else if (key == kVersionKey)
                    {
                        if (json.version == null)
                        {
                            json.version = value;
                        }
                        else
                        {
                            ArrayHelpers.Append(ref json.versions, value);
                        }
                    }
                    else
                    {
                        ArrayHelpers.Append(ref json.capabilities, new Capability {
                            path = key, value = value
                        });
                    }
                }

                return(json);
            }
Exemple #2
0
        public string ToJson()
        {
            var value = MatcherJson.FromMatcher(this);

            return(JsonUtility.ToJson(value));
        }