[Mono-list] New Mono.Runtime.GetDisplayName() method
Kornél Pál
kornelpal at hotmail.com
Sun Jun 5 18:29:40 EDT 2005
Hi,
As a result of long discussion about the lack of a method to obtain the version of the Mono Runtime a new Mono.Runtime.GetDisplayName() method was added to mscorlib.dll.
It was added to the mscorlib.dll because it has to be specific to Mono and each runtime has its own corlib that cannot be used with any other runtime. Using mscorlib.dll has the disadvantage that this method cannot be public to preserve compatibility with .NET Framework. But this is usually not a problem as applications should be runtime independent and thus they shouldn't use types specific to a single runtime.
This method returns the name and version of the runtime as string that should not be used any other purpose to display this information on the screen or in a log file. The exact format may be changed in the future but it will contain at least the name and the version of the runtime in some format.
You can use it using reflection it is static has no parameters and returns a string.
Examples of using the method:
// This is a simple example that throws exception if the method cannot be found
Console.WriteLine((string)typeof(object).Assembly.GetType("Mono.Runtime").InvokeMember("GetDisplayName", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding, null, null, null));
// This is an advanced example that invokes the method only if it can be found
Type monoRuntimeType;
MethodInfo getDisplayNameMethod;
if ((monoRuntimeType = typeof(object).Assembly.GetType("Mono.Runtime")) != null && (getDisplayNameMethod = monoRuntimeType.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding, null, Type.EmptyTypes, null)) != null)
Console.WriteLine((string)getDisplayNameMethod.Invoke(null, null));
else
Console.WriteLine("Mono.Runtime.GetDisplayName not implemented");
Kornél
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://galactus.ximian.com/pipermail/mono-list/attachments/20050606/6e8b09d6/attachment-0001.html
More information about the Mono-list
mailing list