Ejemplo n.º 1
0
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(
                _jValue.GetDomPath(_factory),
                _jValue.Value != null && (!(_jValue.Value is string) || (string)_jValue.Value != ""));

            if (_jValue.Type == JTokenType.Null)
            {
                property.InitializeDefaultPropertyDefinitionSet(_ => {});
            }
            else
            {
                property.InitializeDefaultPropertyDefinitionSet(
                    propertyDefinitions =>
                    propertyDefinitions.Append(
                        _factory.GetAllBclClasses()
                        .Select(bclClass =>
                                _factory.CreatePropertyDefinition(bclClass, _name, bclClass.IsLegalObjectValue(_jValue.Value), true, AttributeProxy.DataMember(_name)))));
            }

            return(property);
        }
Ejemplo n.º 2
0
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_jObject.GetDomPath(_factory), _jObject.Properties().Any());

            property.InitializeDefaultPropertyDefinitionSet(
                propertyDefinitions =>
            {
                var userDefinedClassPropertyDefinition = _factory.CreatePropertyDefinition(repository.GetOrAdd(_jObject.GetDomPath(_factory)), _name, true, true, AttributeProxy.DataMember(_name));
                propertyDefinitions.Append(userDefinedClassPropertyDefinition);
            });

            return(property);
        }
Ejemplo n.º 3
0
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_jArray.GetDomPath(_factory), _jArray.Count > 0);

            var bestFitType = GetBestFitType();

            // If JTokenType.None, then there weren't any elements.
            // If JTokenType.Null, then no JTokenType is able to contain the values of all the other elements.
            // Else, we have a JTokenType that can contain all the values of the other elements.

            // The 'else' condition is the happy path. We'll want to create a property custom tailored for
            // bestFitType. When (or if) it gets merged, the merge mechanism will ensure that we end up with
            // the best type for the property. This should be relatively easy to implement.

            // As for the sad paths, which won't be as easy to implement...

            // There's a strong possibility that we'll need to be able to determine whether a property should
            // even be added to its parent class. If there were no elements in the json array, should we
            // do anything with that array? I don't think so. And what about if no single type exists that
            // could hold all the elements? Should we do anything with *that* array? Or throw an exception?
            // Questions to ponder...

            switch (bestFitType)
            {
            case JTokenType.Null:
            case JTokenType.None:
            {
                throw new NotImplementedException();
            }

            case JTokenType.Object:
            {
                property.InitializeDefaultPropertyDefinitionSet(
                    propertyDefinitions =>
                    propertyDefinitions.Append(
                        _factory.CreatePropertyDefinition(
                            ListClass.FromClass(repository.GetOrAdd(_jArray.GetDomPath(_factory))),
                            _name,
                            true,
                            true,
                            AttributeProxy.DataMember(_name))));
                break;
            }

            case JTokenType.Array:
            {
                throw new NotImplementedException();
            }

            case JTokenType.Integer:
            case JTokenType.Float:
            case JTokenType.String:
            case JTokenType.Boolean:
            case JTokenType.Date:
            case JTokenType.Guid:
            case JTokenType.Uri:
            case JTokenType.TimeSpan:
            {
                property.InitializeDefaultPropertyDefinitionSet(propertyDefinitions => {});

                foreach (var item in _jArray.OfType <JValue>())
                {
                    var mergeProperty = _factory.CreateProperty(_jArray.GetDomPath(_factory), _jArray.Count > 0);

                    mergeProperty.InitializeDefaultPropertyDefinitionSet(
                        propertyDefinitions =>
                        propertyDefinitions.Append(
                            _factory.GetAllBclClasses()
                            .Select(
                                bclClass =>
                                _factory.CreatePropertyDefinition(
                                    ListClass.FromClass(bclClass),
                                    _name,
                                    bclClass.IsLegalObjectValue(item.Value),
                                    true,
                                    AttributeProxy.DataMember(_name)))));

                    property.MergeWith(mergeProperty);
                }
                break;
            }

            default:
            {
                throw new InvalidOperationException("Unsupported item in json array: " + bestFitType);
            }
            }

            return(property);
        }