// Jonathan Pryor (jonpryor@vt.edu)
//
// (C) 2003 Novell, Inc.
-// (C) 2004 Jonathan Pryor
+// (C) 2004-2005 Jonathan Pryor
//
//
using System;
using System.Collections;
using System.IO;
+using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
return 1;
if (t2 == null)
return -1;
- return Comparer.DefaultInvariant.Compare (t1.FullName, t2.FullName);
+ return CultureInfo.InvariantCulture.CompareInfo.Compare (
+ t1.FullName, t2.FullName, CompareOptions.Ordinal);
}
}
return 1;
if (m2 == null)
return -1;
- return Comparer.DefaultInvariant.Compare (m1.Name, m2.Name);
+ return CultureInfo.InvariantCulture.CompareInfo.Compare (
+ m1.Name, m2.Name, CompareOptions.Ordinal);
+ }
+ }
+
+ private class _OrdinalStringComparer : IComparer {
+ public int Compare (object o1, object o2)
+ {
+ string s1 = o1 as string;
+ string s2 = o2 as string;
+ if (object.ReferenceEquals (s1, s2))
+ return 0;
+ if (s1 == null)
+ return 1;
+ if (s2 == null)
+ return -1;
+ return CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s2,
+ CompareOptions.Ordinal);
}
}
internal static IComparer MemberNameComparer = new _MemberNameComparer ();
+ internal static IComparer OrdinalStringComparer = new _OrdinalStringComparer ();
internal static string GetNativeName (string fn)
{
if (t.Namespace.StartsWith ("System"))
return "int /* warning: unknown mapping for type: " + t.Name + " */";
string ts = "struct " +
- MakeMap.GetNativeName (t.FullName).Replace ("+", "_").Replace ("&", "*");
+ MakeMap.GetNativeName (t.FullName).Replace ("+", "_").Replace ("&", "*")
+ .Replace ("[]", "*");
return ts;
}
}
typeof(ObsoleteAttribute), false);
string obsolete = "";
if (oa != null) {
- obsolete = "[Obsolete (\"" + oa.Message + "\")]\n\t\t";
+ obsolete = string.Format ("[Obsolete (\"{0}\", {1})]\n\t\t",
+ oa.Message, oa.IsError ? "true" : "false");
}
- scs.WriteLine ("\t\t[DllImport (LIB, " +
+ scs.WriteLine ("\t\t{3}[DllImport (LIB, " +
"EntryPoint=\"{0}_From{1}\")]\n" +
"\t\tprivate static extern int From{1} ({1} value, out {2} rval);\n",
- ns, t.Name, mtype);
+ ns, t.Name, mtype, obsolete);
scs.WriteLine ("\t\t{3}public static bool TryFrom{1} ({1} value, out {2} rval)\n" +
"\t\t{{\n" +
"\t\t\treturn From{1} (value, out rval) == 0;\n" +
"\t\t\t\tThrowArgumentException (value);", t.Name);
scs.WriteLine ("\t\t\treturn rval;");
scs.WriteLine ("\t\t}\n");
- scs.WriteLine ("\t\t[DllImport (LIB, " +
+ scs.WriteLine ("\t\t{3}[DllImport (LIB, " +
"EntryPoint=\"{0}_To{1}\")]\n" +
"\t\tprivate static extern int To{1} ({2} value, out {1} rval);\n",
- ns, t.Name, mtype);
+ ns, t.Name, mtype, obsolete);
scs.WriteLine ("\t\t{2}public static bool TryTo{1} ({0} value, out {1} rval)\n" +
"\t\t{{\n" +
"\t\t\treturn To{1} (value, out rval) == 0;\n" +
<param name=""value"">The managed value to convert.</param>
<param name=""rval"">The OS-specific equivalent value.</param>
<summary>Converts a <see cref=""T:{0}"" />
- to an OS-specific value.</summary>
+ enumeration value to an OS-specific value.</summary>
<returns><see langword=""true"" /> if the conversion was successful;
otherwise, <see langword=""false"" />.</returns>
<remarks><para>This is an exception-safe alternative to
private static IEnumerable Sort (ICollection c)
{
ArrayList al = new ArrayList (c);
- al.Sort ();
+ al.Sort (MakeMap.OrdinalStringComparer);
return al;
}