Example #1
0
        public static GenericResolver Merge(GenericResolver resolver1,GenericResolver resolver2)
        {
            if(resolver1 == null)
             {
            return resolver2;
             }
             if(resolver2 == null)
             {
            return resolver1;
             }
             List<Type> types = new List<Type>();
             types.AddRange(resolver1.KnownTypes);
             types.AddRange(resolver2.KnownTypes);

             return new GenericResolver(types.ToArray());
        }
Example #2
0
        public static GenericResolver Merge(GenericResolver resolver1, GenericResolver resolver2)
        {
            if (resolver1 == null)
            {
                return(resolver2);
            }
            if (resolver2 == null)
            {
                return(resolver1);
            }
            List <Type> types = new List <Type>();

            types.AddRange(resolver1.KnownTypes);
            types.AddRange(resolver2.KnownTypes);

            return(new GenericResolver(types.ToArray()));
        }
        static void AddGenericResolver(ServiceEndpoint endpoint, Type[] typesToResolve)
        {
            foreach (OperationDescription operation in endpoint.Contract.Operations)
            {
                DataContractSerializerOperationBehavior behavior = operation.Behaviors.Find <DataContractSerializerOperationBehavior>();
                GenericResolver newResolver;

                if (typesToResolve == null || typesToResolve.Any() == false)
                {
                    newResolver = new GenericResolver();
                }
                else
                {
                    newResolver = new GenericResolver(typesToResolve);
                }

                GenericResolver oldResolver = behavior.DataContractResolver as GenericResolver;
                behavior.DataContractResolver = GenericResolver.Merge(oldResolver, newResolver);
            }
        }