本文整理汇总了C#中MObjc.NSObject.isMemberOfClass方法的典型用法代码示例。如果您正苦于以下问题:C# NSObject.isMemberOfClass方法的具体用法?C# NSObject.isMemberOfClass怎么用?C# NSObject.isMemberOfClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MObjc.NSObject
的用法示例。
在下文中一共展示了NSObject.isMemberOfClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Raise
/// <summary>Converts an <c>NSException</c> into a managed exception and throws it.</summary>
/// <param name = "instance">The <a href ="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsexception_Class/Reference/Reference.html">NSException</a>
/// pointer.</param>
/// <remarks>If the <c>NSException</c> wraps a managed exception then
/// <c>TargetInvocationException</c> is thrown instead with the inner exception
/// set to the original exception.</remarks>
public static void Raise(IntPtr instance)
{
NSObject obj = new NSObject(instance);
if (obj.isMemberOfClass(new Class("NSException")))
{
// See if the userInfo contains a .NET exception.
NSObject userInfo = (NSObject) obj.Call("userInfo");
if (userInfo != null && (IntPtr) userInfo != IntPtr.Zero)
{
IntPtr keyBuffer = Marshal.StringToHGlobalAuto(".NET exception");
NSObject key = (NSObject) new Class("NSString").Call("alloc").Call("initWithUTF8String:", keyBuffer);
key.autorelease();
Marshal.FreeHGlobal(keyBuffer);
NSObject data = (NSObject) userInfo.Call("objectForKey:", key);
if (data != null && !data.IsNil())
{
// If it does then get the serialized exception bytes,
IntPtr ptr = (IntPtr) data.Call("bytes");
uint bytes = (uint) data.Call("length");
// copy them into a managed buffer,
byte[] buffer = new byte[bytes];
Marshal.Copy(ptr, buffer, 0, (int) bytes);
// and raise the original exception.
using (MemoryStream stream = new MemoryStream(buffer))
{
BinaryFormatter formatter = new BinaryFormatter();
Exception e = (Exception) formatter.Deserialize(stream);
throw new TargetInvocationException("Exception has been thrown by the (managed) target of an Objective-C method call.", e); // yes TargetInvocationException sucks, but it preserves the original stack crawl...
}
}
}
}
throw new CocoaException(obj);
}
示例2: DoGetMessage
private static string DoGetMessage(NSObject instance)
{
string text;
if (instance.isMemberOfClass(new Class("NSException")))
{
text = Marshal.PtrToStringAuto((IntPtr) instance.Call("name").Call("UTF8String"));
text += ". ";
text += Marshal.PtrToStringAuto((IntPtr) instance.Call("reason").Call("UTF8String"));
}
else
text = Marshal.PtrToStringAuto((IntPtr) instance.Call("description").Call("UTF8String"));
return text;
}
示例3: validateUserInterfaceItem
public bool validateUserInterfaceItem(NSObject sender)
{
bool enabled = false;
Selector sel = (Selector) sender.Call("action");
if (sel.Name == "dirHandler:")
{
int tag = (int) sender.Call("tag");
var handler = m_boss.Get<IMenuHandler>();
MenuState state = handler.GetState(tag);
enabled = (state & MenuState.Enabled) == MenuState.Enabled;
if (sender.respondsToSelector("setState:"))
sender.Call("setState:", (state & MenuState.Checked) == MenuState.Checked ? 1 : 0);
if (enabled && tag == 50 && sender.isMemberOfClass(NSMenuItem.Class))
{
Unused.Value = sender.Call("setTitle:", NSString.Create("Build " + m_name));
}
else if (enabled && tag == 1000 && sender.isMemberOfClass(NSMenuItem.Class))
{
Unused.Value = sender.Call("setTitle:", NSString.Create(m_name + " Preferences"));
}
}
else if (sel.Name == "targetChanged:")
{
enabled = m_builder != null && m_builder.CanBuild;
}
else if (sel.Name == "renameItem:")
{
NSIndexSet selections = m_table.selectedRowIndexes();
enabled = selections.count() == 1;
}
else if (sel.Name == "duplicate:")
{
NSIndexSet selections = m_table.selectedRowIndexes();
enabled = selections.count() > 0 && m_table.editedRow() < 0; // cocoa crashes if we do a duplicate while editing...
}
else if (respondsToSelector(sel))
{
enabled = true;
}
else if (SuperCall(NSWindowController.Class, "respondsToSelector:", new Selector("validateUserInterfaceItem:")).To<bool>())
{
enabled = SuperCall(NSWindowController.Class, "validateUserInterfaceItem:", sender).To<bool>();
}
return enabled;
}