Can anybody tell me how to cram an integer (from user input) into an instance of Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags?
I have gotten a couple of different cast permutations to compile, but they throw an invalid cast exception at runtime.
Here is the whole shooting match for context:
using System;
using System.IO;
using System.Text;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using ofdFlags = Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags;
namespace GetFileDialog
{
public class Main
{
[LispFunction("GetFileDialog")]
public static ResultBuffer GetFileDialog(ResultBuffer buff)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
if (buff == null)
{
ed.WriteMessage("\nToo few arguments.");
return null;
}
ResultBufferEnumerator iter = buff.GetEnumerator();
iter.MoveNext();
if (iter.Current.TypeCode != (short)LispDataType.Text)
{
ed.WriteMessage("\nGetFileDialog expects arguments of string string string int.");
return null;
}
string title = (string)iter.Current.Value;
if (iter.MoveNext() == false)
{
ed.WriteMessage("\nToo few arguments.");
return null;
}
if (iter.Current.TypeCode != (short)LispDataType.Text)
{
ed.WriteMessage("\nGetFileDialog expects arguments of string string string int.");
return null;
}
string defaultFileName = (string)iter.Current.Value;
if (iter.MoveNext() == false)
{
ed.WriteMessage("\nToo few arguments.");
return null;
}
if (iter.Current.TypeCode != (short)LispDataType.Text)
{
ed.WriteMessage("\nGetFileDialog expects arguments of string string string int.");
return null;
}
string defaultExtension = (string)iter.Current.Value;
if (iter.MoveNext() == false)
{
ed.WriteMessage("\nToo few arguments.");
return null;
}
if (iter.Current.TypeCode != (short)LispDataType.Int16)
{
ed.WriteMessage(LispDataType.Int16.ToString());
ed.WriteMessage("\nGetFileDialog expects arguments of string string string int.");
return null;
}
int flags = (int)iter.Current.Value;
if (((flags & (int)ofdFlags.DefaultIsFolder) != 0) && Path.HasExtension(defaultFileName))
{
defaultFileName = Path.GetDirectoryName(defaultFileName);
}
OpenFileDialog ofd = new OpenFileDialog(title, defaultFileName, defaultExtension, title, (ofdFlags)flags);
if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return null;
}
ResultBuffer result = new ResultBuffer();
foreach (string file in ofd.GetFilenames())
{
result.Add(new TypedValue((int)LispDataType.Text, file));
}
return result;
}
}
}