|
using System.Web;
namespace DllImportDoc
{
/// <summary>
/// Summary description for Parameters.
/// </summary>
public class Parameters
{
private string type, name, description;
/// <summary>
///
/// </summary>
/// <param name="s"></param>
public Parameters( string s )
{
if ( s.StartsWith( Keyword.Parameter ) )
s = s.Substring( Keyword.Parameter.Length+1 );
string[] breakItUp = s.Split( '|' );
string[] declaration = breakItUp[0].Trim().Split( ' ' );
type = declaration[0].Trim();
name = declaration[1].Trim();
description = breakItUp[1];
if ( description == null )
description = " ";
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public string ToHtmlTable()
{
return string.Format("<tr><td valign='top'>{0}</td><td valign='top'>{1}</td></tr>\n", name, description);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public string ToNativeCode()
{
// the .Replace statement is so that "UINT[]*" will be "UINT*" in native
// and "uint[]" in managed code
return HttpUtility.HtmlEncode( string.Format("{0} {1}", type.Replace( "[]", "" ), name) );
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public string ToManagedCode()
{
string response = null;
if ( type.EndsWith( "*" ) )
response = "ref ";
switch( type )
{
case "UINT":
case "DWORD":
case "UINT*":
case "DWORD*":
response += "uint";
break;
case "UINT*[]":
response += "uint[]";
break;
case "LPGUID":
response += "ref Guid";
break;
case "GUID":
response += "Guid";
break;
case "char*":
case "CHAR*":
case "TCHAR*":
// overwrite the "ref" already in response
response = "StringBuilder";
break;
case "int":
case "INT":
response += "int";
break;
case "BOOL":
case "BOOL*":
response += "bool";
break;
case "BYTE":
response += "byte[]";
break;
case "BYTE*":
// overwrite the "ref" already in response
response = "byte[]";
break;
case "FILETIME":
case "FILETIME*":
response += "long";
break;
case "HWND":
response += "IntPtr";
break;
default:
response += type;
break;
}
response += " " + name;
return HttpUtility.HtmlEncode( response );
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.