public StateContext(int length, Func <SchemaEntryToken, IEnumerable <TMember> > mapper, Action <string> onError, object data, Collections.INamedCollection <TMember> members)
            {
                _bufferIndex = 0;
                _buffer      = new char[length];
                _current     = null;
                _mapper      = mapper;
                _onError     = onError;
                _token       = new SchemaEntryToken(data);
                _stack       = new Stack <SchemaMemberBase>();

                this.Character = '\0';
                this.State     = State.None;
                this.Flags     = new StateVector();

                _members = members ?? new Collections.NamedCollection <TMember>(item => item.Name, StringComparer.OrdinalIgnoreCase);
            }
예제 #2
0
            private static IEnumerable <SchemaMember> Resolve(SchemaEntryToken token)
            {
                if (string.IsNullOrWhiteSpace(token.Name))
                {
                    throw new InvalidOperationException();
                }

                switch (token.Name)
                {
                case "*":
                    return(new SchemaMember[]
                    {
                        new SchemaMember("a"),
                        new SchemaMember("b"),
                        new SchemaMember("c"),
                        new SchemaMember("d"),
                        new SchemaMember("e"),
                        new SchemaMember("f"),
                    });
                }

                return(new SchemaMember[] { new SchemaMember(token.Name) });
            }
예제 #3
0
        private IEnumerable <SchemaMember> Resolve(SchemaEntryToken token)
        {
            var data    = (SchemaData)token.Data;
            var current = data.Entity;

            if (token.Parent != null)
            {
                var parent = token.Parent;

                if (parent.Token.Property.IsSimplex)
                {
                    throw new DataException($"The specified {parent} schema does not correspond to a complex property, so its child elements cannot be defined.");
                }

                var complex = (IEntityComplexPropertyMetadata)parent.Token.Property;
                data.Entity = complex.Foreign;

                while (complex.ForeignProperty != null && complex.ForeignProperty.IsComplex)
                {
                    complex     = (IEntityComplexPropertyMetadata)complex.ForeignProperty;
                    data.Entity = complex.Foreign;
                }

                if (parent.Token.Member != null)
                {
                    switch (parent.Token.Member.MemberType)
                    {
                    case MemberTypes.Field:
                        data.EntityType = Zongsoft.Common.TypeExtension.GetElementType(((FieldInfo)parent.Token.Member).FieldType) ??
                                          ((FieldInfo)parent.Token.Member).FieldType;
                        break;

                    case MemberTypes.Property:
                        data.EntityType = Zongsoft.Common.TypeExtension.GetElementType(((PropertyInfo)parent.Token.Member).PropertyType) ??
                                          ((PropertyInfo)parent.Token.Member).PropertyType;
                        break;

                    case MemberTypes.Method:
                        data.EntityType = Zongsoft.Common.TypeExtension.GetElementType(((MethodInfo)parent.Token.Member).ReturnType) ??
                                          ((MethodInfo)parent.Token.Member).ReturnType;
                        break;

                    default:
                        throw new DataException($"Invalid kind of '{parent.Token.Member}' member.");
                    }
                }
            }

            if (token.Name == "*")
            {
                //return data.Entity.GetTokens(data.EntityType)
                //				  .Where(p => p.Property.IsSimplex)
                //				  .Select(p => new SchemaMember(p));

                current = data.Entity;
                var members = new List <SchemaMember>();

                while (current != null)
                {
                    members.AddRange(
                        current.GetTokens(data.EntityType)
                        .Where(p => p.Property.IsSimplex)
                        .Select(p => new SchemaMember(p)));

                    current = current.GetBaseEntity();
                }

                return(members);
            }

            current = data.Entity;
            ICollection <IEntityMetadata> ancestors = null;

            while (current != null)
            {
                if (Zongsoft.Common.TypeExtension.IsScalarType(data.EntityType) && current.Properties.TryGet(token.Name, out var property))
                {
                    return new[] { new SchemaMember(property, ancestors) }
                }
                ;

                if (current.GetTokens(data.EntityType).TryGet(token.Name, out var stub))
                {
                    return new [] { new SchemaMember(stub, ancestors) }
                }
                ;

                if (ancestors == null)
                {
                    ancestors = new List <IEntityMetadata>();
                }

                current = current.GetBaseEntity();

                if (current != null)
                {
                    ancestors.Add(current);
                }
            }

            throw new DataException($"The specified '{token.Name}' property does not exist in the '{data.Entity.Name}' entity.");
        }