Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / ComIntegration / EmitterCache.cs / 1 / EmitterCache.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.ComIntegration { using System; using System.Reflection; using System.Reflection.Emit; using System.Collections.Generic; using System.Threading; using System.Runtime.InteropServices; internal class EmitterCache { private static EmitterCache Provider = null; private static object initLock = new object (); internal static EmitterCache TypeEmitter { get { lock (initLock) { if (Provider == null) { EmitterCache localProvider = new EmitterCache(); Thread.MemoryBarrier(); Provider = localProvider; } } if (Provider == null) { DiagnosticUtility.DebugAssert("Provider should not be null"); #pragma warning suppress 56503 // throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(true); } return Provider; } } ModuleBuilder DynamicModule; AssemblyBuilder assemblyBuilder; DictionaryinterfaceToClassMap ; private EmitterCache () { AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = Guid.NewGuid().ToString (); assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); DynamicModule = assemblyBuilder.DefineDynamicModule (Guid.NewGuid().ToString () ); interfaceToClassMap = new Dictionary (); } private Type [] GetParameterTypes (MethodInfo mInfo) { ParameterInfo [] parameters = mInfo.GetParameters (); Type [] typeArray = new Type [parameters.Length ]; int index = 0; for (; index < parameters.Length; index++) { typeArray [index] = parameters [index].ParameterType ; } return typeArray; } internal Type FindOrCreateType (Type interfaceType) { if (!interfaceType.IsInterface) { DiagnosticUtility.DebugAssert("Passed in type should be an Interface"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } Type classType = null; lock(this) { interfaceToClassMap.TryGetValue (interfaceType, out classType); if (classType == null) { TypeBuilder typeBuilder = DynamicModule.DefineType(interfaceType.Name + "MarshalByRefObject", TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Abstract, typeof(MarshalByRefObject), new Type[] { interfaceType }); Type[] ctorParams = new Type[] { typeof(ClassInterfaceType) }; ConstructorInfo classCtorInfo = typeof(ClassInterfaceAttribute).GetConstructor(ctorParams); CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { ClassInterfaceType.None }); typeBuilder.SetCustomAttribute(attributeBuilder); typeBuilder.AddInterfaceImplementation(interfaceType); foreach (MethodInfo mInfo in interfaceType.GetMethods()) { MethodBuilder methodInClass = null; methodInClass = typeBuilder.DefineMethod(mInfo.Name, MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Abstract | MethodAttributes.Abstract | MethodAttributes.HideBySig | MethodAttributes.NewSlot, mInfo.ReturnType, GetParameterTypes(mInfo)); } classType = typeBuilder.CreateType(); interfaceToClassMap[interfaceType] = classType; } } if (classType == null) { DiagnosticUtility.DebugAssert("Class Type should not be null at this point"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false); } return classType; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XslAstAnalyzer.cs
- MethodToken.cs
- FillErrorEventArgs.cs
- SqlCacheDependencyDatabaseCollection.cs
- InvalidCommandTreeException.cs
- FormViewCommandEventArgs.cs
- GridViewUpdateEventArgs.cs
- LocalizableAttribute.cs
- CookielessHelper.cs
- DotAtomReader.cs
- ServiceReference.cs
- FunctionParameter.cs
- KeyedCollection.cs
- PriorityItem.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- DataGridViewColumnStateChangedEventArgs.cs
- listitem.cs
- SqlConnectionString.cs
- NameValueConfigurationElement.cs
- Ipv6Element.cs
- ContentFileHelper.cs
- ErrorInfoXmlDocument.cs
- ListControl.cs
- RuleSetCollection.cs
- QueryExpr.cs
- Condition.cs
- SupportsEventValidationAttribute.cs
- SQLInt16.cs
- EmissiveMaterial.cs
- AnnotationResourceCollection.cs
- ExpressionEditorAttribute.cs
- ToolBarPanel.cs
- ObjectReferenceStack.cs
- DefaultValueAttribute.cs
- CultureInfo.cs
- AssociationType.cs
- DataMemberConverter.cs
- DataGridLinkButton.cs
- CharKeyFrameCollection.cs
- GZipUtils.cs
- SymbolDocumentGenerator.cs
- ChildDocumentBlock.cs
- WorkflowApplicationUnhandledExceptionEventArgs.cs
- HotSpot.cs
- ActiveXHost.cs
- CompressedStack.cs
- DelayedRegex.cs
- Content.cs
- XmlSchemaAny.cs
- SqlProvider.cs
- FormatterServicesNoSerializableCheck.cs
- _SslStream.cs
- AttachedPropertyBrowsableAttribute.cs
- PersistChildrenAttribute.cs
- EdmValidator.cs
- Panel.cs
- TransformerTypeCollection.cs
- XmlSchemaSimpleContentExtension.cs
- CapabilitiesSection.cs
- MsmqTransportElement.cs
- ConvertersCollection.cs
- FileDialog.cs
- ListGeneralPage.cs
- SHA512Managed.cs
- SecurityHelper.cs
- formatter.cs
- SuspendDesigner.cs
- HtmlControl.cs
- FunctionImportElement.cs
- Label.cs
- ScriptManager.cs
- EmptyTextWriter.cs
- Activity.cs
- Positioning.cs
- NamedPipeWorkerProcess.cs
- RequestQueryProcessor.cs
- DataGridColumnDropSeparator.cs
- List.cs
- TextSelectionHighlightLayer.cs
- TextSimpleMarkerProperties.cs
- TTSEngineProxy.cs
- StringConverter.cs
- QilFunction.cs
- FilterException.cs
- RemotingHelper.cs
- ExpanderAutomationPeer.cs
- Dump.cs
- ForwardPositionQuery.cs
- StreamInfo.cs
- ExtendedPropertyInfo.cs
- PackageDigitalSignature.cs
- ValuePatternIdentifiers.cs
- wmiutil.cs
- EnumerableRowCollectionExtensions.cs
- CalendarAutoFormat.cs
- Variable.cs
- CacheChildrenQuery.cs
- TextParagraphCache.cs
- BinaryUtilClasses.cs
- StrongTypingException.cs