public InformationServiceQuery(InformationServiceContext context, string query, PropertyBag parameters)
            : base(context, query, parameters)
        {
            object[] attributes = type.GetCustomAttributes(typeof(InformationServiceEntityAttribute), false);

            if (attributes.Length > 0)
            {
                InformationServiceEntityAttribute entityAttribute = attributes[0] as InformationServiceEntityAttribute;
                parser = entityAttribute != null?ChooseResponseParser(entityAttribute.ParserType) : new ResponseParser <T>();
            }
            else
            {
                parser = new ResponseParser <T>();
            }
        }
Exemple #2
0
        private void BeginRootEntity(XmlReader reader)
        {
            // Assumptions:
            // - expecting top level elements to be entities of the type expected by the query
            // - name must match exactly between the XML element and the type name
            // - not handling simple scalar results at this point, only classes/structs with properties
            // - not handling fields
            if (String.CompareOrdinal(rootType.Name, reader.LocalName) != 0)
            {
                bool matchEntityName = false;

                object[] attributes = rootType.GetCustomAttributes(typeof(InformationServiceEntityAttribute), true);
                if (attributes.Length > 0)
                {
                    InformationServiceEntityAttribute entityAttribute = attributes[0] as InformationServiceEntityAttribute;
                    matchEntityName = entityAttribute.EntityType.Equals(entityInfo.EntityType, StringComparison.OrdinalIgnoreCase);
                }

                if (!matchEntityName)
                {
                    throw new InvalidOperationException("Don't know how to handle element " + reader.LocalName);
                }
            }

            StackFrame frame = new StackFrame();

            frame.entity       = this.entityInfo;
            frame.elementName  = reader.LocalName;
            frame.property     = null;
            frame.instance     = Activator.CreateInstance <T>();
            frame.instanceType = rootType;
            frame.state        = this.state;

            stack.Push(frame);

            this.state = ParserState.Entity;
        }