Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / WinForms / Managed / System / WinForms / HtmlToClrEventProxy.cs / 1 / HtmlToClrEventProxy.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Drawing; using System.Drawing.Printing; using System.Windows.Forms; using System.Security.Permissions; using System.Security; using System.Runtime.InteropServices; using System.Net; using System.Globalization; using System.Collections; using System.Reflection; namespace System.Windows.Forms { ////// This class is here for IHTML*3.AttachHandler style eventing. /// We need a way of routing requests for DISPID(0) to a particular CLR event without creating /// a public class. In order to accomplish this we implement IReflect and handle InvokeMethod /// to call back on a CLR event handler. /// internal class HtmlToClrEventProxy : IReflect { private EventHandler eventHandler; private IReflect typeIReflectImplementation; private object sender = null; private string eventName; public HtmlToClrEventProxy(object sender, string eventName, EventHandler eventHandler) { this.eventHandler = eventHandler; this.eventName = eventName; Type htmlToClrEventProxyType = typeof(HtmlToClrEventProxy); typeIReflectImplementation = htmlToClrEventProxyType as IReflect; } public string EventName { get { return eventName; } } [DispId(0)] public void OnHtmlEvent() { InvokeClrEvent(); } private void InvokeClrEvent() { if (eventHandler != null) { eventHandler(sender, EventArgs.Empty); } } #region IReflect Type IReflect.UnderlyingSystemType { get { return typeIReflectImplementation.UnderlyingSystemType; } } // Methods System.Reflection.FieldInfo IReflect.GetField(string name, System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetField(name, bindingAttr); } System.Reflection.FieldInfo[] IReflect.GetFields(System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetFields(bindingAttr); } System.Reflection.MemberInfo[] IReflect.GetMember(string name, System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetMember(name, bindingAttr); } System.Reflection.MemberInfo[] IReflect.GetMembers(System.Reflection.BindingFlags bindingAttr){ return typeIReflectImplementation.GetMembers(bindingAttr); } System.Reflection.MethodInfo IReflect.GetMethod(string name, System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetMethod(name, bindingAttr); } System.Reflection.MethodInfo IReflect.GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, Type[] types, System.Reflection.ParameterModifier[] modifiers) { return typeIReflectImplementation.GetMethod(name, bindingAttr, binder, types, modifiers); } System.Reflection.MethodInfo[] IReflect.GetMethods(System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetMethods(bindingAttr); } System.Reflection.PropertyInfo[] IReflect.GetProperties(System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetProperties(bindingAttr); } System.Reflection.PropertyInfo IReflect.GetProperty(string name, System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetProperty(name, bindingAttr); } System.Reflection.PropertyInfo IReflect.GetProperty(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, Type returnType, Type[] types, System.Reflection.ParameterModifier[] modifiers) { return typeIReflectImplementation.GetProperty(name, bindingAttr, binder, returnType, types, modifiers); } // InvokeMember: // If we get a call for DISPID=0, fire the CLR event. // object IReflect.InvokeMember(string name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object target, object[] args, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters) { // if (name == "[DISPID=0]") { // we know we're getting called back to fire the event - translate this now into a CLR event. OnHtmlEvent(); // since there's no return value for void, return null. return null; } else { return typeIReflectImplementation.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters); } } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Drawing; using System.Drawing.Printing; using System.Windows.Forms; using System.Security.Permissions; using System.Security; using System.Runtime.InteropServices; using System.Net; using System.Globalization; using System.Collections; using System.Reflection; namespace System.Windows.Forms { ////// This class is here for IHTML*3.AttachHandler style eventing. /// We need a way of routing requests for DISPID(0) to a particular CLR event without creating /// a public class. In order to accomplish this we implement IReflect and handle InvokeMethod /// to call back on a CLR event handler. /// internal class HtmlToClrEventProxy : IReflect { private EventHandler eventHandler; private IReflect typeIReflectImplementation; private object sender = null; private string eventName; public HtmlToClrEventProxy(object sender, string eventName, EventHandler eventHandler) { this.eventHandler = eventHandler; this.eventName = eventName; Type htmlToClrEventProxyType = typeof(HtmlToClrEventProxy); typeIReflectImplementation = htmlToClrEventProxyType as IReflect; } public string EventName { get { return eventName; } } [DispId(0)] public void OnHtmlEvent() { InvokeClrEvent(); } private void InvokeClrEvent() { if (eventHandler != null) { eventHandler(sender, EventArgs.Empty); } } #region IReflect Type IReflect.UnderlyingSystemType { get { return typeIReflectImplementation.UnderlyingSystemType; } } // Methods System.Reflection.FieldInfo IReflect.GetField(string name, System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetField(name, bindingAttr); } System.Reflection.FieldInfo[] IReflect.GetFields(System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetFields(bindingAttr); } System.Reflection.MemberInfo[] IReflect.GetMember(string name, System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetMember(name, bindingAttr); } System.Reflection.MemberInfo[] IReflect.GetMembers(System.Reflection.BindingFlags bindingAttr){ return typeIReflectImplementation.GetMembers(bindingAttr); } System.Reflection.MethodInfo IReflect.GetMethod(string name, System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetMethod(name, bindingAttr); } System.Reflection.MethodInfo IReflect.GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, Type[] types, System.Reflection.ParameterModifier[] modifiers) { return typeIReflectImplementation.GetMethod(name, bindingAttr, binder, types, modifiers); } System.Reflection.MethodInfo[] IReflect.GetMethods(System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetMethods(bindingAttr); } System.Reflection.PropertyInfo[] IReflect.GetProperties(System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetProperties(bindingAttr); } System.Reflection.PropertyInfo IReflect.GetProperty(string name, System.Reflection.BindingFlags bindingAttr) { return typeIReflectImplementation.GetProperty(name, bindingAttr); } System.Reflection.PropertyInfo IReflect.GetProperty(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, Type returnType, Type[] types, System.Reflection.ParameterModifier[] modifiers) { return typeIReflectImplementation.GetProperty(name, bindingAttr, binder, returnType, types, modifiers); } // InvokeMember: // If we get a call for DISPID=0, fire the CLR event. // object IReflect.InvokeMember(string name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object target, object[] args, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters) { // if (name == "[DISPID=0]") { // we know we're getting called back to fire the event - translate this now into a CLR event. OnHtmlEvent(); // since there's no return value for void, return null. return null; } else { return typeIReflectImplementation.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters); } } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WorkflowServiceBuildProvider.cs
- ProcessExitedException.cs
- SharedStatics.cs
- ToolStripSystemRenderer.cs
- PageAsyncTaskManager.cs
- Int64.cs
- TreeViewImageGenerator.cs
- EventLogEntry.cs
- OperationAbortedException.cs
- NameTable.cs
- OutgoingWebResponseContext.cs
- UriSectionReader.cs
- COMException.cs
- UnmanagedMemoryStream.cs
- XmlNamespaceMappingCollection.cs
- _FtpDataStream.cs
- Filter.cs
- SecurityMessageProperty.cs
- GAC.cs
- DataGridViewRowConverter.cs
- SamlAdvice.cs
- ReturnEventArgs.cs
- ContentValidator.cs
- SoapMessage.cs
- UnauthorizedAccessException.cs
- FontFamilyConverter.cs
- DataGridViewTextBoxCell.cs
- SqlMethodCallConverter.cs
- QueryOutputWriter.cs
- DetailsViewPagerRow.cs
- OracleMonthSpan.cs
- SqlTrackingWorkflowInstance.cs
- HtmlTernaryTree.cs
- RawUIStateInputReport.cs
- FixedSOMPageConstructor.cs
- VariableQuery.cs
- MdImport.cs
- HitTestWithGeometryDrawingContextWalker.cs
- InitializationEventAttribute.cs
- StreamReader.cs
- IndependentlyAnimatedPropertyMetadata.cs
- ParameterCollection.cs
- CharAnimationBase.cs
- XmlCodeExporter.cs
- GlyphCache.cs
- StructuredTypeEmitter.cs
- DataBoundControlAdapter.cs
- IISMapPath.cs
- ConstantExpression.cs
- SecurityPolicySection.cs
- DataGridViewCellCollection.cs
- UIHelper.cs
- XmlSchemaElement.cs
- MtomMessageEncodingElement.cs
- RequestCacheValidator.cs
- DispatcherExceptionEventArgs.cs
- DoubleConverter.cs
- URLMembershipCondition.cs
- CacheRequest.cs
- ValidationPropertyAttribute.cs
- WindowsRebar.cs
- TriggerActionCollection.cs
- DataTableClearEvent.cs
- ScriptingSectionGroup.cs
- TimelineClockCollection.cs
- PowerModeChangedEventArgs.cs
- ClientSettings.cs
- HwndKeyboardInputProvider.cs
- Message.cs
- StringWriter.cs
- PowerModeChangedEventArgs.cs
- MultiTrigger.cs
- DeleteMemberBinder.cs
- DataRowExtensions.cs
- BinaryObjectReader.cs
- DiagnosticTraceSource.cs
- If.cs
- InputReport.cs
- HandleExceptionArgs.cs
- XmlILAnnotation.cs
- Serializer.cs
- RegexCaptureCollection.cs
- CustomAttribute.cs
- SizeF.cs
- Assembly.cs
- FixedPageStructure.cs
- X509ChainElement.cs
- OleDbError.cs
- UnmanagedMemoryStream.cs
- HtmlInputReset.cs
- DataTableReaderListener.cs
- SemanticTag.cs
- ResourceDescriptionAttribute.cs
- ADMembershipProvider.cs
- FileDialog_Vista.cs
- SmuggledIUnknown.cs
- IPAddress.cs
- dbdatarecord.cs
- DesignerActionTextItem.cs
- InterleavedZipPartStream.cs