Example #1
0
        public static Either <object> ParseGenericSpecification <TFormat>(this IWireSerialization serializer, Either <Type> domainType, Stream data)
        {
            if (domainType.IsFailure)
            {
                return(domainType.Error);
            }
            var genSer   = serializer.GetSerializer <TFormat>();
            var specType = typeof(GenericSpecification <,>).MakeGenericType(domainType.Result, typeof(TFormat));

            try
            {
                var arg = ParseObject(serializer, typeof(Dictionary <string, List <KeyValuePair <int, TFormat> > >), data, true, null);
                if (arg.IsFailure)
                {
                    return(arg.Error);
                }
                return(Activator.CreateInstance(specType, genSer, arg.Result));
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                var specArg = new Dictionary <string, List <KeyValuePair <int, TFormat> > >();
                specArg["URI"] = new List <KeyValuePair <int, TFormat> >(new[] { new KeyValuePair <int, TFormat>(1, genSer.Serialize("1001")) });
                return(@"Error deserializing specification. " + ex.Message + @"
Example: 
" + serializer.SerializeToString(specArg));
            }
        }
Example #2
0
        public static object ParseGenericSpecification <TFormat>(IWireSerialization serializer, Type domainType, Stream data)
        {
            var genSer   = serializer.GetSerializer <TFormat>();
            var specType = typeof(GenericSpecification <,>).MakeGenericType(domainType, typeof(TFormat));

            try
            {
                var arg = Utility.ParseObject(serializer, typeof(Dictionary <string, List <KeyValuePair <int, TFormat> > >), data, true, null);
                return(Activator.CreateInstance(specType, genSer, arg));
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                var specArg = new Dictionary <string, List <KeyValuePair <int, TFormat> > >();
                specArg["URI"] = new List <KeyValuePair <int, TFormat> >(new[] { new KeyValuePair <int, TFormat>(1, genSer.Serialize("1001")) });
                throw new WebFaultException <string>(@"Error deserializing specification. " + ex.Message + @"
Example: 
" + serializer.SerializeToString(specArg), HttpStatusCode.BadRequest);
            }
        }