protected override JsonConverter ResolveContractConverter(Type objectType)
        {
            if (ErrorConverter.CanConvertStatic(objectType))
            {
                return(new ErrorConverter());
            }

            if (ErrorListConverter.CanConvertStatic(objectType))
            {
                return(new ErrorListConverter());
            }

            if (ResourceObjectConverter.CanConvert(objectType))
            {
                return(ResourceObjectConverter);
            }

            if (_resourceObjectListConverter.CanConvert(objectType))
            {
                return(_resourceObjectListConverter);
            }

            if (LinkConverter.CanConvertStatic(objectType))
            {
                return(new LinkConverter());
            }

            if (DocumentRootConverter.CanConvertStatic(objectType))
            {
                return(new DocumentRootConverter());
            }

            return(base.ResolveContractConverter(objectType));
        }
Exemple #2
0
        protected override JsonConverter ResolveContractConverter(Type objectType)
        {
            //if (ErrorConverter.CanConvertStatic(objectType))
            //    return new ErrorConverter();

            //if (ErrorListConverter.CanConvertStatic(objectType))
            //    return new ErrorListConverter();

            if (ResourceObjectConverter.CanConvert(objectType))
            {
                return(ResourceObjectConverter);
            }

            if (_resourceListConverter.CanConvert(objectType))
            {
                return(_resourceListConverter);
            }

            if (DocumentRootConverter.CanConvertStatic(objectType))
            {
                return(new DocumentRootConverter(_href));
            }

            return(base.ResolveContractConverter(objectType));
        }
Exemple #3
0
        protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            if (_fields != null && _fields.Count() > 0 && Fields.Count() == 0)
            {
                if (!DocumentRootConverter.CanConvertStatic(type))
                {
                    populateFields(type);
                }
            }
            var ret = base.CreateProperties(type, memberSerialization);
            var tp  = type.Name.ToLower();
            var res = ((type.GetCustomAttributes(typeof(ResourceAttribute))).SingleOrDefault() as ResourceAttribute);

            if (!DocumentRootConverter.CanConvertStatic(type) && (res == null || res.IsResource))
            {
                ret = ret.Where(p =>
                                (Fields == null || Fields.Count() == 0 ||
                                 p.PropertyName.ToLower() == PropertyNames.Id || p.PropertyName.ToLower() == PropertyNames.Type ||
                                 Fields.Any(r => r.Name == p.PropertyName.ToLower() && (r.Type == tp || r.SubTypes.Contains(tp))))
                                ).ToList();
            }
            return(ret);
        }