コード例 #1
0
        protected override JsonObjectContract CreateObjectContract(Type objectType)
        {
            var jsonObjectContract =
                objectType == typeof(LazyStringValue) ||
                objectType == typeof(BlittableJsonReaderObject)
                ? new JsonObjectContract(objectType)
                : base.CreateObjectContract(objectType);

            jsonObjectContract.ExtensionDataValueType = typeof(JToken);
            jsonObjectContract.ExtensionDataSetter   += (o, key, value) =>
            {
                if (jsonObjectContract.Properties.Contains(key))
                {
                    return;
                }
                _currentExtensionSetter?.Invoke(o, key, value);
            };
            jsonObjectContract.ExtensionDataGetter += (o) => _currentExtensionGetter?.Invoke(o);

            var identityProperty = _conventions.Conventions.GetIdentityProperty(objectType);

            if (identityProperty != null)
            {
                var jsonProperty = jsonObjectContract.Properties.GetProperty(identityProperty.Name, StringComparison.Ordinal);
                if (jsonProperty != null)
                {
                    jsonProperty.ShouldSerialize = ShouldSerialize;
                }
            }

            return(jsonObjectContract);
        }
コード例 #2
0
        protected override JsonObjectContract CreateObjectContract(Type objectType)
        {
            var jsonObjectContract = base.CreateObjectContract(objectType);

            jsonObjectContract.ExtensionDataValueType = typeof(JToken);
            jsonObjectContract.ExtensionDataSetter   += (o, key, value) =>
            {
                if (jsonObjectContract.Properties.Contains(key))
                {
                    return;
                }
                _currentExtensionSetter?.Invoke(o, key, value);
            };
            jsonObjectContract.ExtensionDataGetter += (o) => _currentExtensionGetter?.Invoke(o);
            return(jsonObjectContract);
        }