public InputDeviceMatcher ToMatcher() { var matcher = new InputDeviceMatcher(); ////TODO: get rid of the piecemeal array allocation and do it in one step // Interfaces. if (!string.IsNullOrEmpty(@interface)) { matcher = matcher.WithInterface(@interface); } if (interfaces != null) { foreach (var value in interfaces) { matcher = matcher.WithInterface(value); } } // Device classes. if (!string.IsNullOrEmpty(deviceClass)) { matcher = matcher.WithDeviceClass(deviceClass); } if (deviceClasses != null) { foreach (var value in deviceClasses) { matcher = matcher.WithDeviceClass(value); } } // Manufacturer. if (!string.IsNullOrEmpty(manufacturer)) { matcher = matcher.WithManufacturer(manufacturer); } if (manufacturers != null) { foreach (var value in manufacturers) { matcher = matcher.WithManufacturer(value); } } // Product. if (!string.IsNullOrEmpty(product)) { matcher = matcher.WithProduct(product); } if (products != null) { foreach (var value in products) { matcher = matcher.WithProduct(value); } } // Version. if (!string.IsNullOrEmpty(version)) { matcher = matcher.WithVersion(version); } if (versions != null) { foreach (var value in versions) { matcher = matcher.WithVersion(value); } } // Capabilities. if (capabilities != null) { foreach (var value in capabilities) { ////FIXME: we're turning all values into strings here matcher = matcher.WithCapability(value.path, value.value); } } return(matcher); }
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); }