ServiceContractGenerationOptions GetGenerationOption()
        {
            ServiceContractGenerationOptions go =
                ServiceContractGenerationOptions.ClientClass;

            if (co.GenerateAsync)
            {
                go |= ServiceContractGenerationOptions.AsynchronousMethods;
            }
            if (co.ChannelInterface)
            {
                go |= ServiceContractGenerationOptions.ChannelInterface;
            }
            if (co.GenerateTypesAsInternal)
            {
                go |= ServiceContractGenerationOptions.InternalTypes;
            }
            if (co.GenerateProxy)
            {
                go |= ServiceContractGenerationOptions.ClientClass;
            }
            if (co.GenerateTypedMessages)
            {
                go |= ServiceContractGenerationOptions.TypedMessages;
            }
            if ((co.TargetClientVersion35 && co.GenerateAsync) || co.GenerateMoonlightProxy)
            {
                go |= ServiceContractGenerationOptions.EventBasedAsynchronousMethods;
            }

            return(go);
        }
        /// <summary>
        /// Builds a new instance.
        /// </summary>
        /// <param name="codeGeneratorOptions">The code generator options.</param>
        /// <returns>
        /// A new <see cref="ServiceContractGenerationOptions"/> instance.
        /// </returns>
        public ServiceContractGenerationOptions Build(CodeGeneratorOptions codeGeneratorOptions)
        {
            ServiceContractGenerationOptions serviceContractGenerationOptions = new ServiceContractGenerationOptions();

            if (codeGeneratorOptions.AsyncMethods)
            {
                serviceContractGenerationOptions |= ServiceContractGenerationOptions.AsynchronousMethods;
                if (codeGeneratorOptions.TargetFrameworkVersion == TargetFrameworkVersion.Version35)
                {
                    serviceContractGenerationOptions |= ServiceContractGenerationOptions.EventBasedAsynchronousMethods;
                }
            }

            if (codeGeneratorOptions.CodeGeneratorMode == CodeGeneratorMode.Client)
            {
                serviceContractGenerationOptions |= (ServiceContractGenerationOptions.ClientClass | ServiceContractGenerationOptions.ChannelInterface);
            }

            if (codeGeneratorOptions.InternalTypes)
            {
                serviceContractGenerationOptions |= ServiceContractGenerationOptions.InternalTypes;
            }

            if (codeGeneratorOptions.TypedMessages)
            {
                serviceContractGenerationOptions |= ServiceContractGenerationOptions.TypedMessages;
            }

            return(serviceContractGenerationOptions);
        }
        public void Build_CodeGenerationOptions_DefaultsToNone()
        {
            IServiceContractGenerationOptionsBuilder builder         = new ServiceContractGenerationOptionsBuilder();
            ServiceContractGenerationOptions         contractOptions = builder.Build(new CodeGeneratorOptions());

            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.None));
        }
		/// <summary>
		/// Builds a new instance.
		/// </summary>
		/// <param name="codeGeneratorOptions">The code generator options.</param>
		/// <returns>
		/// A new <see cref="ServiceContractGenerationOptions"/> instance.
		/// </returns>
		public ServiceContractGenerationOptions Build(CodeGeneratorOptions codeGeneratorOptions)
		{
			ServiceContractGenerationOptions serviceContractGenerationOptions = new ServiceContractGenerationOptions();

			if (codeGeneratorOptions.AsyncMethods)
			{
				serviceContractGenerationOptions |= ServiceContractGenerationOptions.AsynchronousMethods;
				if (codeGeneratorOptions.TargetFrameworkVersion == TargetFrameworkVersion.Version35)
				{
					serviceContractGenerationOptions |= ServiceContractGenerationOptions.EventBasedAsynchronousMethods;
				}
			}

			if (codeGeneratorOptions.CodeGeneratorMode == CodeGeneratorMode.Client)
			{
				serviceContractGenerationOptions |= (ServiceContractGenerationOptions.ClientClass | ServiceContractGenerationOptions.ChannelInterface);
			}

			if (codeGeneratorOptions.InternalTypes)
			{
				serviceContractGenerationOptions |= ServiceContractGenerationOptions.InternalTypes;
			}

			if (codeGeneratorOptions.TypedMessages)
			{
				serviceContractGenerationOptions |= ServiceContractGenerationOptions.TypedMessages;
			}

			return serviceContractGenerationOptions;
		}
Пример #5
0
        ServiceContractGenerationOptions GetGenerationOption()
        {
            ServiceContractGenerationOptions go =
                ServiceContractGenerationOptions.ClientClass;

            if (co.GenerateAsync)
            {
                go |= ServiceContractGenerationOptions.AsynchronousMethods;
            }
            if (co.ChannelInterface)
            {
                go |= ServiceContractGenerationOptions.ChannelInterface;
            }
            if (co.GenerateTypesAsInternal)
            {
                go |= ServiceContractGenerationOptions.InternalTypes;
            }
            if (co.GenerateProxy)
            {
                go |= ServiceContractGenerationOptions.ClientClass;
            }
            if (co.GenerateTypedMessages)
            {
                go |= ServiceContractGenerationOptions.TypedMessages;
            }
            return(go);
        }
Пример #6
0
        private static ServiceContractGenerator CreateServiceContractGenerator(CodeCompileUnit codeCompileUnit,
                                                                               IDictionary <string, string> namespaceMappings,
                                                                               ServiceContractGenerationOptions serviceContractGenerationOptions)
        {
            var gen = new ServiceContractGenerator(codeCompileUnit)
            {
                Options = serviceContractGenerationOptions
            };

            foreach (var namespaceMapping in namespaceMappings)
            {
                gen.NamespaceMappings.Add(namespaceMapping.Key, namespaceMapping.Value);
            }

            return(gen);
        }
        public void Build_Options_CreatedByOptionsBuilder()
        {
            ICodeGeneratorContext codeGeneratorContext = new CodeGeneratorContext(metadataSet, new CodeGeneratorOptions());
            const ServiceContractGenerationOptions serviceContractGenerationOptions = new ServiceContractGenerationOptions();

            Mock <IServiceContractGenerationOptionsBuilder> generationOptionsBuilder = new Mock <IServiceContractGenerationOptionsBuilder>();

            generationOptionsBuilder.Setup(mock => mock.Build(codeGeneratorContext.CodeGeneratorOptions)).Returns(serviceContractGenerationOptions);

            IServiceContractGeneratorFactory factory           = new ServiceContractGeneratorFactory(generationOptionsBuilder.Object);
            ServiceContractGenerator         contractGenerator = factory.GetServiceContractGenerator(codeGeneratorContext);

            Assert.That(contractGenerator.Options, Is.EqualTo(serviceContractGenerationOptions));

            generationOptionsBuilder.Verify();
        }
        public void Build_CodeGeneratorOptions_TypedMessages()
        {
            IServiceContractGenerationOptionsBuilder builder = new ServiceContractGenerationOptionsBuilder();

            CodeGeneratorOptions options = new CodeGeneratorOptions {
                TypedMessages = true
            };
            ServiceContractGenerationOptions contractOptions = builder.Build(options);

            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.TypedMessages));

            options = new CodeGeneratorOptions {
                TypedMessages = false
            };
            contractOptions = builder.Build(options);
            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.None));
        }
        public void Build_CodeGeneratorOptions_CodeGeneratorMode()
        {
            IServiceContractGenerationOptionsBuilder builder = new ServiceContractGenerationOptionsBuilder();

            CodeGeneratorOptions options = new CodeGeneratorOptions {
                CodeGeneratorMode = CodeGeneratorMode.Client
            };
            ServiceContractGenerationOptions contractOptions = builder.Build(options);

            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.ClientClass | ServiceContractGenerationOptions.ChannelInterface));

            options = new CodeGeneratorOptions {
                CodeGeneratorMode = CodeGeneratorMode.Service
            };
            contractOptions = builder.Build(options);
            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.None));
        }
        public void Build_CodeGeneratorOptions_AsyncMethods()
        {
            IServiceContractGenerationOptionsBuilder builder = new ServiceContractGenerationOptionsBuilder();

            CodeGeneratorOptions options = new CodeGeneratorOptions {
                AsyncMethods = true
            };
            ServiceContractGenerationOptions contractOptions = builder.Build(options);

            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.AsynchronousMethods));

            options = new CodeGeneratorOptions {
                AsyncMethods = false
            };
            contractOptions = builder.Build(options);
            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.None));
        }
        public void Build_CodeGeneratorOptions_AsyncMethodsWithTargetClientVersion()
        {
            IServiceContractGenerationOptionsBuilder builder = new ServiceContractGenerationOptionsBuilder();

            CodeGeneratorOptions options = new CodeGeneratorOptions
            {
                AsyncMethods = true, TargetFrameworkVersion = TargetFrameworkVersion.Version35
            };
            ServiceContractGenerationOptions contractOptions = builder.Build(options);

            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.AsynchronousMethods | ServiceContractGenerationOptions.EventBasedAsynchronousMethods));

            options = new CodeGeneratorOptions
            {
                AsyncMethods           = true,
                TargetFrameworkVersion = TargetFrameworkVersion.Version30
            };
            contractOptions = builder.Build(options);
            Assert.That(contractOptions, Is.EqualTo(ServiceContractGenerationOptions.AsynchronousMethods));
        }
Пример #12
0
            public bool IsSet(ServiceContractGenerationOptions option)
            {
                Fx.Assert(IsSingleBit((int)option), "");

                return((this.Options & option) != ServiceContractGenerationOptions.None);
            }
Пример #13
0
 public OptionsHelper(ServiceContractGenerationOptions options)
 {
     this.Options = options;
 }
Пример #14
0
 public bool IsSet(ServiceContractGenerationOptions option)
 {
     return((this.Options & option) != ServiceContractGenerationOptions.None);
 }
 public bool IsSet(ServiceContractGenerationOptions option)
 {
     return ((this.Options & option) != ServiceContractGenerationOptions.None);
 }
 public OptionsHelper(ServiceContractGenerationOptions options)
 {
     this.Options = options;
 }