本文整理汇总了C#中IDisposable.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IDisposable.GetType方法的具体用法?C# IDisposable.GetType怎么用?C# IDisposable.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDisposable
的用法示例。
在下文中一共展示了IDisposable.GetType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeterministicFinalizer
public DeterministicFinalizer(IDisposable comObject)
{
var unknown = Marshal.GetIUnknownForObject(comObject);
//TODO: GetIDispatchForObject if any interfaces are ComInterfaceType InterfaceIsDual or InterfaceIsIDispatch.
var interfacePointers = comObject.GetType()
.GetInterfaces()
.Where(Marshal.IsTypeVisibleFromCom)
.Select(@interface => Marshal.GetComInterfaceForObject(comObject, @interface))
.ToList();
var supportErrorInfo = wrappers.Wrap(unknown, new Guid("df0b3d60-548f-101b-8e65-08002b2bd119"), 4);
var provideClassInfo = wrappers.Wrap(unknown, new Guid("B196B283-BAB4-101A-B69C-00AA00341D07"), 4);
var connectionPointContainer = wrappers.Wrap(unknown, new Guid("B196B284-BAB4-101A-B69C-00AA00341D07"), 5);
//TODO: optional (?) IConnectionPoint "B196B286-BAB4-101A-B69C-00AA00341D07" functionCount=8 (3 + 5)
//TODO: optional (if IExpando) IDispatchEx "A6EF9860-C720-11d0-9337-00A0C90DCAA9" functionCount=15 (3 + 4 + 8)
//TODO: optional (if IEnumerable) IEnumVARIANT "00020404-0000-0000-C000-000000000046" functionCount=7 (3 + 4)
hooks.Add(new CcwHook(comObject, unknown, wrappers));
foreach (var interfacePointer in interfacePointers)
hooks.Add(new CcwHook(comObject, interfacePointer, wrappers));
hooks.Add(new CcwHook(comObject, supportErrorInfo, wrappers));
hooks.Add(new CcwHook(comObject, provideClassInfo, wrappers));
hooks.Add(new CcwHook(comObject, connectionPointContainer, wrappers));
Marshal.Release(unknown);
foreach (var interfacePointer in interfacePointers)
Marshal.Release(interfacePointer);
Marshal.Release(supportErrorInfo.Wrapper);
Marshal.Release(provideClassInfo.Wrapper);
Marshal.Release(connectionPointContainer.Wrapper);
}
示例2: getShortcutText
private static string getShortcutText(IDisposable mi)
{
var t = (string)mi.GetType().InvokeMember(
@"GetShortcutText",
BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
null,
mi,
new object[] { });
return t;
}
示例3: DisposeOf
private static void DisposeOf(IDisposable disposable)
{
try
{
disposable.Dispose();
}
catch (ObjectDisposedException ex)
{
// not supposed to happen, but sometimes does
var logger = LoggerFactory.GetCurrentClassLogger();
var msg = string.Format("Object of type {0} raised ObjectDisposedException during disposal",
disposable.GetType());
logger.Warn(msg, ex);
}
catch (Exception ex)
{
var logger = LoggerFactory.GetCurrentClassLogger();
var msg = string.Format("Object of type {0} raised an exception during disposal: {1}",
disposable.GetType(),
ex.Message);
logger.Error(msg, ex);
}
}
示例4: SilentDispose
public static void SilentDispose(IDisposable disposable)
{
if (disposable != null)
{
try
{
disposable.Dispose();
}
catch (Exception e)
{
Trace.TraceWarning("[{0}] Failed to dispose object of type [{1}]. {2}", typeof(DisposeHelper), disposable.GetType(), e);
}
}
}
示例5: Dispose
private static void Dispose(IDisposable disposable, Boolean isDisposing)
{
Debug.Assert(disposable != null);
// Dispose of the fields in each type down to, but excluding, System.Object
Type type = disposable.GetType();
do {
FieldInfo[] instanceFields = type.GetFields(AllInstanceMembers);
if (isDisposing) {
DisposableExtensions.ReleaseManagedResources(disposable, instanceFields);
}
DisposableExtensions.ReleaseUnmanagedResources(disposable, instanceFields);
}
while ((type = type.BaseType) != typeof(Object));
if (isDisposing) {
GC.SuppressFinalize(disposable);
}
}
示例6: Start
public void Start(string bootstrapperName, Dictionary<string, string> properties, MarshalByRefObject remoteListener)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
//var domainSetup = AppDomain.CurrentDomain.SetupInformation;
// TODO -- what the hell here? This is bad bad bad.
//System.Environment.CurrentDirectory = domainSetup.ApplicationBase;
// TODO -- need to handle exceptions gracefully here
EventAggregator.Start((IRemoteListener) remoteListener);
var loader = ApplicationLoaderFinder.FindLoader(bootstrapperName);
_shutdown = loader.Load(properties);
EventAggregator.SendMessage(new LoaderStarted
{
LoaderTypeName = _shutdown.GetType().FullName
});
}
示例7: Start
public void Start(string bootstrapperName, Dictionary<string, string> properties, MarshalByRefObject remoteListener)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
var domainSetup = AppDomain.CurrentDomain.SetupInformation;
System.Environment.CurrentDirectory = domainSetup.ApplicationBase;
// TODO -- need to handle exceptions gracefully here
EventAggregator.Start((IRemoteListener) remoteListener);
properties.Each(x => PackageRegistry.Properties[x.Key] = x.Value);
var loader = BottleServiceApplication.FindLoader(bootstrapperName);
_shutdown = loader.Load();
EventAggregator.SendMessage(new LoaderStarted
{
LoaderTypeName = _shutdown.GetType().FullName
});
}
示例8: Add
public static void Add(IDisposable obj)
{
Debug.WriteLine(string.Format("Adding object `{0}`",
obj.GetType().Name));
var sb = new StringBuilder();
// Shove the first frame and build a stack trace
foreach (StackFrame frame in new StackTrace(true).GetFrames().Skip(1))
{
var method = frame.GetMethod();
sb.Append(string.Format("> [{0}] {1} {2}",
method.DeclaringType != null? method.DeclaringType.FullName : "",
method.ToString(),
frame.GetFileName() == null ?
Environment.NewLine :
frame.ToString()));
}
_dict.Add(RuntimeHelpers.GetHashCode(obj),
new DisposableObject(obj, sb.ToString()));
}
示例9: Remove
public static void Remove(IDisposable obj)
{
Debug.WriteLine(string.Format("Removing object `{0}`",
obj.GetType().Name));
_dict.Remove(RuntimeHelpers.GetHashCode(obj));
}
示例10: GetNotifyIconArea
internal static RECT GetNotifyIconArea(IDisposable notifyicon)
{
var field = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance);
var num = (int)field.GetValue(notifyicon);
var fieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
var window = (NativeWindow)fieldInfo.GetValue(notifyicon);
var notifyiconidentifier2 = new NOTIFYICONIDENTIFIER { hWnd = window.Handle, uID = (uint)num };
notifyiconidentifier2.cbSize = (uint)Marshal.SizeOf(notifyiconidentifier2);
RECT rect;
Shell_NotifyIconGetRect(ref notifyiconidentifier2, out rect);
return rect;
}
示例11: listBox1_SelectedIndexChanged
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
TryCloseForm();
if (listBox1.SelectedItem == null)
return;
Assembly demo = Assembly.Load(listBox1.SelectedItem.ToString());
Type[] types = demo.GetExportedTypes();
foreach (Type type in types)
{
if (type.BaseType.Name.Equals("Game"))
{
game = (IDisposable)type.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
bool librariesOk = (bool)type.InvokeMember("TestLibraries", BindingFlags.InvokeMethod, null, game, null);
if (librariesOk == false)
return;
new Thread(DemoThread).Start();
while (form == null)
{
form = (Form)game.GetType().InvokeMember("Form", BindingFlags.GetProperty, null, game, null);
}
form.HandleCreated += new EventHandler(form_HandleCreated);
break;
}
}
}
示例12: ThrowIfDisposed
public static void ThrowIfDisposed(IDisposable obj)
{
if (obj.IsDisposed) throw new ObjectDisposedException(obj.GetType().FullName);
}
示例13: GetNotifyIconPosition
private static Point GetNotifyIconPosition(IDisposable notifyicon)
{
var field = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance);
var num = (int) field.GetValue(notifyicon);
var fieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
var window = (NativeWindow) fieldInfo.GetValue(notifyicon);
var notifyiconidentifier2 = new NOTIFYICONIDENTIFIER {hWnd = window.Handle, uID = (uint) num};
notifyiconidentifier2.cbSize = (uint) Marshal.SizeOf(notifyiconidentifier2);
RECT rect;
Shell_NotifyIconGetRect(ref notifyiconidentifier2, out rect);
return new Point(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2);
}