3 // Sebastien Pouliot <sebastien@xamarin.com>
5 // Copyright 2013 Xamarin Inc. http://www.xamarin.com
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System.Xml.Linq;
30 namespace Xamarin.ApiDiff {
32 public static class Helper {
34 public static bool IsTrue (this XElement self, string name)
36 return (self.GetAttribute (name) == "true");
39 public static string GetAttribute (this XElement self, string name)
41 var n = self.Attribute (name);
47 // null == no obsolete, String.Empty == no description
48 public static string GetObsoleteMessage (this XElement self)
50 var cattrs = self.Element ("attributes");
54 foreach (var ca in cattrs.Elements ("attribute")) {
55 if (ca.GetAttribute ("name") != "System.ObsoleteAttribute")
57 var props = ca.Element ("properties");
59 return String.Empty; // no description
60 foreach (var p in props.Elements ("property")) {
61 if (p.GetAttribute ("name") != "Message")
63 return p.GetAttribute ("value");
69 // make it beautiful (.NET -> C#)
70 public static string GetTypeName (this XElement self, string name)
72 string type = self.GetAttribute (name);
77 return GetTypeName (type.Replace ('+', '.'));
80 static string GetTypeName (string type)
82 if (type.StartsWith ("System.Nullable`1[", StringComparison.Ordinal))
83 return type.Substring (18, type.Length - 19) + "?";
85 int pos = type.IndexOf ('`');
87 int end = type.LastIndexOf (']');
88 string subtype = type.Substring (pos + 3, end - pos - 3);
89 return type.Substring (0, pos) + "<" + GetTypeName (subtype) + ">";
101 case "System.UInt64":
105 case "System.Boolean":
107 case "System.Object":
109 case "System.Single":
111 case "System.Double":
119 case "System.UInt16":
122 if (type.StartsWith (State.Namespace, StringComparison.Ordinal))
123 type = type.Substring (State.Namespace.Length + 1);