Skip to content

GovindMalviya/uap-csharp

 
 

Repository files navigation

ua_parser C# Library

This is the CSharp implementation of ua-parser. The implementation uses the shared regex patterns and overrides from regexes.yaml. The assembly embeds the latest regex patterns which are loaded into the default parser. You can create a parser with more updated regex patterns by using the static methods on Parser to pass in specific patterns in yaml format.

Build and Run Tests:

.\build.bat

Or install through Nuget:

PM> Install-Package UAParser

Usage:

  using UAParser;

...

  string uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3";

  // get a parser with the embedded regex patterns, methods exist for creating with provided regex patterns 
  var uaParser = Parser.GetDefault();

  ClientInfo c = uaParser.Parse(uaString);

  Console.WriteLine(c.UserAgent.Family); // => "Mobile Safari"
  Console.WriteLine(c.UserAgent.Major);  // => "5"
  Console.WriteLine(c.UserAgent.Minor);  // => "1"

  Console.WriteLine(c.OS.Family);        // => "iOS"
  Console.WriteLine(c.OS.Major);         // => "5"
  Console.WriteLine(c.OS.Minor);         // => "1"

  Console.WriteLine(c.Device.Family);    // => "iPhone"

Authors:

About

C# implementation of ua-parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.8%
  • Shell 0.2%