Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / BCL / System / Runtime / InteropServices / TCEAdapterGen / TCEAdapterGenerator.cs / 1 / TCEAdapterGenerator.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Runtime.InteropServices.TCEAdapterGen { using System.Runtime.InteropServices; using System; using System.Reflection; using System.Reflection.Emit; using System.Collections; using System.Threading; internal class TCEAdapterGenerator { public void Process(ModuleBuilder ModBldr, ArrayList EventItfList) { // Store the input/output module. m_Module = ModBldr; // Generate the TCE adapters for all the event sources. int NumEvItfs = EventItfList.Count; for ( int cEventItfs = 0; cEventItfs < NumEvItfs; cEventItfs++ ) { // Retrieve the event interface info. EventItfInfo CurrEventItf = (EventItfInfo)EventItfList[cEventItfs]; // Retrieve the information from the event interface info. Type EventItfType = CurrEventItf.GetEventItfType(); Type SrcItfType = CurrEventItf.GetSrcItfType(); String EventProviderName = CurrEventItf.GetEventProviderName(); // Generate the sink interface helper. Type SinkHelperType = new EventSinkHelperWriter( m_Module, SrcItfType, EventItfType ).Perform(); // Generate the event provider. new EventProviderWriter( m_Module, EventProviderName, EventItfType, SrcItfType, SinkHelperType ).Perform(); } } internal static void SetClassInterfaceTypeToNone(TypeBuilder tb) { // Create the ClassInterface(ClassInterfaceType.None) CA builder if we haven't created it yet. if (s_NoClassItfCABuilder == null) { Type []aConsParams = new Type[1]; aConsParams[0] = typeof(ClassInterfaceType); ConstructorInfo Cons = typeof(ClassInterfaceAttribute).GetConstructor(aConsParams); Object[] aArgs = new Object[1]; aArgs[0] = ClassInterfaceType.None; s_NoClassItfCABuilder = new CustomAttributeBuilder(Cons, aArgs); } // Set the class interface type to none. tb.SetCustomAttribute(s_NoClassItfCABuilder); } internal static TypeBuilder DefineUniqueType(String strInitFullName, TypeAttributes attrs, Type BaseType, Type[] aInterfaceTypes, ModuleBuilder mb) { String strFullName = strInitFullName; int PostFix = 2; // Find the first unique name for the type. for (; mb.GetType(strFullName) != null; strFullName = strInitFullName + "_" + PostFix, PostFix++); // Define a type with the determined unique name. return mb.DefineType(strFullName, attrs, BaseType, aInterfaceTypes); } internal static void SetHiddenAttribute(TypeBuilder tb) { if (s_HiddenCABuilder == null) { // Hide the type from Object Browsers Type []aConsParams = new Type[1]; aConsParams[0] = typeof(TypeLibTypeFlags); ConstructorInfo Cons = typeof(TypeLibTypeAttribute).GetConstructor(aConsParams); Object []aArgs = new Object[1]; aArgs[0] = TypeLibTypeFlags.FHidden; s_HiddenCABuilder = new CustomAttributeBuilder(Cons, aArgs); } tb.SetCustomAttribute(s_HiddenCABuilder); } internal static MethodInfo[] GetNonPropertyMethods(Type type) { MethodInfo[] aMethods = type.GetMethods(); ArrayList methods = new ArrayList(aMethods); PropertyInfo[] props = type.GetProperties(); foreach(PropertyInfo prop in props) { MethodInfo[] accessors = prop.GetAccessors(); foreach (MethodInfo accessor in accessors) { for (int i=0; i < methods.Count; i++) { if ((MethodInfo)methods[i] == accessor) methods.RemoveAt(i); } } } MethodInfo[] retMethods = new MethodInfo[methods.Count]; methods.CopyTo(retMethods); return retMethods; } internal static MethodInfo[] GetPropertyMethods(Type type) { MethodInfo[] aMethods = type.GetMethods(); ArrayList methods = new ArrayList(); PropertyInfo[] props = type.GetProperties(); foreach(PropertyInfo prop in props) { MethodInfo[] accessors = prop.GetAccessors(); foreach (MethodInfo accessor in accessors) { methods.Add(accessor); } } MethodInfo[] retMethods = new MethodInfo[methods.Count]; methods.CopyTo(retMethods); return retMethods; } private ModuleBuilder m_Module = null; private Hashtable m_SrcItfToSrcItfInfoMap = new Hashtable(); private static CustomAttributeBuilder s_NoClassItfCABuilder = null; private static CustomAttributeBuilder s_HiddenCABuilder = null; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Runtime.InteropServices.TCEAdapterGen { using System.Runtime.InteropServices; using System; using System.Reflection; using System.Reflection.Emit; using System.Collections; using System.Threading; internal class TCEAdapterGenerator { public void Process(ModuleBuilder ModBldr, ArrayList EventItfList) { // Store the input/output module. m_Module = ModBldr; // Generate the TCE adapters for all the event sources. int NumEvItfs = EventItfList.Count; for ( int cEventItfs = 0; cEventItfs < NumEvItfs; cEventItfs++ ) { // Retrieve the event interface info. EventItfInfo CurrEventItf = (EventItfInfo)EventItfList[cEventItfs]; // Retrieve the information from the event interface info. Type EventItfType = CurrEventItf.GetEventItfType(); Type SrcItfType = CurrEventItf.GetSrcItfType(); String EventProviderName = CurrEventItf.GetEventProviderName(); // Generate the sink interface helper. Type SinkHelperType = new EventSinkHelperWriter( m_Module, SrcItfType, EventItfType ).Perform(); // Generate the event provider. new EventProviderWriter( m_Module, EventProviderName, EventItfType, SrcItfType, SinkHelperType ).Perform(); } } internal static void SetClassInterfaceTypeToNone(TypeBuilder tb) { // Create the ClassInterface(ClassInterfaceType.None) CA builder if we haven't created it yet. if (s_NoClassItfCABuilder == null) { Type []aConsParams = new Type[1]; aConsParams[0] = typeof(ClassInterfaceType); ConstructorInfo Cons = typeof(ClassInterfaceAttribute).GetConstructor(aConsParams); Object[] aArgs = new Object[1]; aArgs[0] = ClassInterfaceType.None; s_NoClassItfCABuilder = new CustomAttributeBuilder(Cons, aArgs); } // Set the class interface type to none. tb.SetCustomAttribute(s_NoClassItfCABuilder); } internal static TypeBuilder DefineUniqueType(String strInitFullName, TypeAttributes attrs, Type BaseType, Type[] aInterfaceTypes, ModuleBuilder mb) { String strFullName = strInitFullName; int PostFix = 2; // Find the first unique name for the type. for (; mb.GetType(strFullName) != null; strFullName = strInitFullName + "_" + PostFix, PostFix++); // Define a type with the determined unique name. return mb.DefineType(strFullName, attrs, BaseType, aInterfaceTypes); } internal static void SetHiddenAttribute(TypeBuilder tb) { if (s_HiddenCABuilder == null) { // Hide the type from Object Browsers Type []aConsParams = new Type[1]; aConsParams[0] = typeof(TypeLibTypeFlags); ConstructorInfo Cons = typeof(TypeLibTypeAttribute).GetConstructor(aConsParams); Object []aArgs = new Object[1]; aArgs[0] = TypeLibTypeFlags.FHidden; s_HiddenCABuilder = new CustomAttributeBuilder(Cons, aArgs); } tb.SetCustomAttribute(s_HiddenCABuilder); } internal static MethodInfo[] GetNonPropertyMethods(Type type) { MethodInfo[] aMethods = type.GetMethods(); ArrayList methods = new ArrayList(aMethods); PropertyInfo[] props = type.GetProperties(); foreach(PropertyInfo prop in props) { MethodInfo[] accessors = prop.GetAccessors(); foreach (MethodInfo accessor in accessors) { for (int i=0; i < methods.Count; i++) { if ((MethodInfo)methods[i] == accessor) methods.RemoveAt(i); } } } MethodInfo[] retMethods = new MethodInfo[methods.Count]; methods.CopyTo(retMethods); return retMethods; } internal static MethodInfo[] GetPropertyMethods(Type type) { MethodInfo[] aMethods = type.GetMethods(); ArrayList methods = new ArrayList(); PropertyInfo[] props = type.GetProperties(); foreach(PropertyInfo prop in props) { MethodInfo[] accessors = prop.GetAccessors(); foreach (MethodInfo accessor in accessors) { methods.Add(accessor); } } MethodInfo[] retMethods = new MethodInfo[methods.Count]; methods.CopyTo(retMethods); return retMethods; } private ModuleBuilder m_Module = null; private Hashtable m_SrcItfToSrcItfInfoMap = new Hashtable(); private static CustomAttributeBuilder s_NoClassItfCABuilder = null; private static CustomAttributeBuilder s_HiddenCABuilder = null; } } // 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
- DisableDpiAwarenessAttribute.cs
- XmlAttributeOverrides.cs
- MouseGesture.cs
- DataSourceBooleanViewSchemaConverter.cs
- ConfigurationSettings.cs
- ConfigXmlReader.cs
- FlagsAttribute.cs
- MaskedTextBoxTextEditorDropDown.cs
- GeneralTransform3D.cs
- AspCompat.cs
- Int32RectValueSerializer.cs
- HyperLinkDataBindingHandler.cs
- BitmapEffectDrawingContextWalker.cs
- PerspectiveCamera.cs
- UITypeEditors.cs
- BitmapCacheBrush.cs
- PKCS1MaskGenerationMethod.cs
- UInt64.cs
- SqlNotificationRequest.cs
- GroupBox.cs
- ObjectDataSourceMethodEventArgs.cs
- ThreadStaticAttribute.cs
- RoleManagerEventArgs.cs
- MouseGesture.cs
- METAHEADER.cs
- GenericsInstances.cs
- StringArrayConverter.cs
- Dictionary.cs
- WindowVisualStateTracker.cs
- MonitoringDescriptionAttribute.cs
- EmbossBitmapEffect.cs
- SystemKeyConverter.cs
- ListViewDataItem.cs
- ToolStripPanelRow.cs
- CreateParams.cs
- MDIWindowDialog.cs
- Logging.cs
- StringCollection.cs
- FixedTextPointer.cs
- SafeEventLogReadHandle.cs
- MatrixCamera.cs
- ToolStripItemClickedEventArgs.cs
- GeometryModel3D.cs
- SQLMembershipProvider.cs
- LoginName.cs
- PageThemeCodeDomTreeGenerator.cs
- BindingExpressionUncommonField.cs
- ProbeDuplexCD1AsyncResult.cs
- DeferredBinaryDeserializerExtension.cs
- ImageButton.cs
- ComplexTypeEmitter.cs
- SizeFConverter.cs
- TdsParser.cs
- SecUtil.cs
- CompilerGlobalScopeAttribute.cs
- RelationshipDetailsRow.cs
- SQLByte.cs
- SR.cs
- ImageListUtils.cs
- XmlWrappingWriter.cs
- SQLMoneyStorage.cs
- SoapHeaderAttribute.cs
- FixedSOMElement.cs
- ObjectResult.cs
- UpdateExpressionVisitor.cs
- GifBitmapEncoder.cs
- WindowsScrollBar.cs
- NonClientArea.cs
- WebPartAuthorizationEventArgs.cs
- DynamicExpression.cs
- CustomAttribute.cs
- XmlSchemaIdentityConstraint.cs
- PassportAuthentication.cs
- Hex.cs
- CodeTypeReference.cs
- UnmanagedMarshal.cs
- CertificateManager.cs
- SignedXmlDebugLog.cs
- TypedElement.cs
- SoapInteropTypes.cs
- StyleBamlTreeBuilder.cs
- Int64KeyFrameCollection.cs
- ServiceHttpModule.cs
- ImageCreator.cs
- BaseAddressElement.cs
- RecordManager.cs
- DataGridTablesFactory.cs
- KnownColorTable.cs
- GridViewHeaderRowPresenter.cs
- ExceptionValidationRule.cs
- InvalidEnumArgumentException.cs
- Logging.cs
- Viewport3DVisual.cs
- HtmlSelect.cs
- NonSerializedAttribute.cs
- CustomAssemblyResolver.cs
- ButtonField.cs
- SingleKeyFrameCollection.cs
- DispatcherEventArgs.cs
- FlowDocumentReaderAutomationPeer.cs