Summary description for ModuleScope.
        private Type CreateCallableInterfaceFromDelegate(Type delegateType, ModuleScope moduleScope)
        {
            Type type;

            long count = 1;

            AssemblyName aName = new AssemblyName("DynamicAssemblyExample");
            AssemblyBuilder ab =
                AppDomain.CurrentDomain.DefineDynamicAssembly(
                    aName,
                    AssemblyBuilderAccess.Run);

            // Create the module.
            ModuleBuilder mb = ab.DefineDynamicModule(aName.Name);

            TypeBuilder typeBuilder = mb.DefineType(
                String.Format("ProxyDelegate_{0}_{1}", delegateType.Name, count),
                TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.Public);

            MethodInfo invoke = delegateType.GetMethod("Invoke");
            ParameterInfo[] parameters = invoke.GetParameters();

            Type returnType = invoke.ReturnType;
            Type[] parameterTypes = new Type[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                parameterTypes[i] = parameters[i].ParameterType;
            }

            typeBuilder.DefineMethod("Invoke", MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.Public, CallingConventions.HasThis, returnType, parameterTypes);

            type = typeBuilder.CreateType();
            return type;
        }
        public RepositoryForDelegates()
        {
            scope = new ModuleScope();
            dictionary = new Dictionary<Type, Type>();

            counter = 0;
        }
		/// <summary>
		/// Initializes a new instance of the DynamicAdapterBuilder class.
		/// </summary>
		/// <param name="originalObject">The type of object to build an adapter for</param>
		public DynamicAdapterBuilder(Type originalObject, ModuleScope scope)
		{
			OriginalObject = originalObject;
			ModuleScope = scope;

			stagePipeline.Add(new SetupEmitterStage());
			stagePipeline.Add(new CopyReturnTypeStage());
			stagePipeline.Add(new DictionaryParameterToXPathNavigableStage());
			stagePipeline.Add(new AddIDicitionaryConversionLogicStage());
			stagePipeline.Add(new InitMethodInvocationParamsStage());
			stagePipeline.Add(new CorrectIDictionaryMethodInvocationParamsStage());
			stagePipeline.Add(new InvokeMethodStage());
			stagePipeline.Add(new ReturnStage());
		}
		public Type GetAdapter(Type typeToBeAdapted)
		{
			try
			{
				lock (_cacheLock)
				{
					Type adapterType;
					if (!TypeAdapterCache.TryGetValue(typeToBeAdapted, out adapterType))
					{
						DynamicAdapterBuilder builder = new DynamicAdapterBuilder(typeToBeAdapted, _Module);
						adapterType = builder.Build();
						TypeAdapterCache.Add(typeToBeAdapted, adapterType);
					}
					return adapterType;
				}
			}
			catch 
			{
				//On exception, reset module scope
				_Module = new ModuleScope(false);
				throw;
			}
		}
Example #5
0
		/// <summary>
		///   Initializes a new instance of the <see cref = "DefaultProxyBuilder" /> class.
		/// </summary>
		/// <param name = "scope">The module scope for generated proxy types.</param>
		public DefaultProxyBuilder(ModuleScope scope)
		{
			this.scope = scope;
		}
Example #6
0
		public WCFProxyBuilder(ModuleScope scope)
		{
			this.logger = NullLogger.Instance;
			this.scope = scope;
		}
		protected DefaultProxyBuilder(ModuleScope scope)
		{
			this.scope = scope;
		}
 /// <summary>
 ///   Initializes a new instance of the <see cref = "DefaultProxyBuilder" /> class.
 /// </summary>
 /// <param name = "scope">The module scope for generated proxy types.</param>
 public DefaultProxyBuilder(ModuleScope scope)
 {
     this.scope = scope;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceHostInterfaceProxyGenerator"/> class.
 /// </summary>
 /// <param name="scope">The scope of the module being built.</param>
 /// <param name="interface">The interface that will be proxied.</param>
 public ServiceHostInterfaceProxyGenerator(ModuleScope scope, Type @interface)
     : base(scope, @interface)
 {
     _metadataBuddyType = @interface.GetMetadataClassType();
 }
Example #10
0
		/// <summary>
		/// Resets the <see cref="ModuleScope"/> used for deserialization to a given <paramref name="scope"/>.
		/// </summary>
		/// <param name="scope">The scope to be used for deserialization.</param>
		/// <remarks>By default, the deserialization process uses a different scope than the rest of the application, which can lead to multiple proxies
		/// being generated for the same type. By explicitly setting the deserialization scope to the application's scope, this can be avoided.</remarks>
		public static void SetScope (ModuleScope scope)
		{
			if (scope == null)
				throw new ArgumentNullException ("scope");
			_scope = scope;
		}
 public InternalProxyService()
 {
     _moduleScope = new ModuleScope();
     _genericGenerator = new ProxyGenerator(new DefaultProxyBuilder(_moduleScope));
 }
		public WCFInterfaceProxyWithoutTargetGenerator(ModuleScope scope, Type @interface)
			: base(scope, @interface)
		{
		}
Example #13
0
 /// <summary>
 ///   Saves the generated assembly to a physical file. Note that this renders the <see cref = "PersistentProxyBuilder" /> unusable.
 /// </summary>
 /// <returns>The path of the generated assembly file, or null if no assembly has been generated.</returns>
 /// <remarks>
 ///   This method does not support saving multiple files. If both a signed and an unsigned module have been generated, use the
 ///   respective methods of the <see cref = "ModuleScope" />.
 /// </remarks>
 public string SaveAssembly()
 {
     return(ModuleScope.SaveAssembly());
 }
		/// <summary>
		/// Initializes a new instance of the DynamicAdapterStore class.
		/// </summary>
		public DynamicAdapterCachingBuilder()
		{
			_Module = new ModuleScope(false);
		}
 public DocumentProxyGenerator(ModuleScope scope, Type targetType)
     : base(scope, targetType)
 {
 }