void Initialize(ContractTypeNameCollection contractTypeNames, Uri scopeMatchBy)
 {
     this.contractTypeNames = contractTypeNames;
     this.scopeMatchBy      = scopeMatchBy;
     this.maxResults        = int.MaxValue;
     this.duration          = DiscoveryDefaults.DiscoveryOperationDuration;
 }
        public FindCriteria(Type contractType)
        {
            if (contractType == null)
            {
                throw FxTrace.Exception.ArgumentNull("contractType");
            }

            ContractTypeNameCollection contractTypeNamesArg = new ContractTypeNameCollection();

            contractTypeNamesArg.Add(GetContractTypeName(contractType));

            Initialize(contractTypeNamesArg, DiscoveryDefaults.ScopeMatchBy);
        }
        internal void ReadFrom(DiscoveryVersion discoveryVersion, XmlReader reader)
        {
            if (discoveryVersion == null)
            {
                throw FxTrace.Exception.ArgumentNull("discoveryVersion");
            }
            if (reader == null)
            {
                throw FxTrace.Exception.ArgumentNull("reader");
            }

            this.contractTypeNames = null;
            this.scopes            = null;
            this.scopeMatchBy      = DiscoveryDefaults.ScopeMatchBy;
            this.extensions        = null;
            this.duration          = TimeSpan.MaxValue;
            this.maxResults        = int.MaxValue;

            reader.MoveToContent();
            if (reader.IsEmptyElement)
            {
                reader.Read();
                return;
            }

            int startDepth = reader.Depth;

            reader.ReadStartElement();

            if (reader.IsStartElement(ProtocolStrings.SchemaNames.TypesElement, discoveryVersion.Namespace))
            {
                this.contractTypeNames = new ContractTypeNameCollection();
                SerializationUtility.ReadContractTypeNames(this.contractTypeNames, reader);
            }

            if (reader.IsStartElement(ProtocolStrings.SchemaNames.ScopesElement, discoveryVersion.Namespace))
            {
                this.scopes = new ScopeCollection();
                Uri scopeMatchBy = SerializationUtility.ReadScopes(this.scopes, reader);
                if (scopeMatchBy != null)
                {
                    this.scopeMatchBy = discoveryVersion.Implementation.ToVersionIndependentScopeMatchBy(scopeMatchBy);
                }
            }

            while (true)
            {
                reader.MoveToContent();

                if ((reader.NodeType == XmlNodeType.EndElement) && (reader.Depth == startDepth))
                {
                    break;
                }
                else if (reader.IsStartElement(ProtocolStrings.SchemaNames.MaxResultsElement, ProtocolStrings.VersionInternal.Namespace))
                {
                    this.maxResults = SerializationUtility.ReadMaxResults(reader);
                }
                else if (reader.IsStartElement(ProtocolStrings.SchemaNames.DurationElement, ProtocolStrings.VersionInternal.Namespace))
                {
                    this.duration = SerializationUtility.ReadDuration(reader);
                }
                else if (reader.IsStartElement())
                {
                    XElement xElement = XElement.ReadFrom(reader) as XElement;
                    Extensions.Add(xElement);
                }
                else
                {
                    reader.Read();
                }
            }

            reader.ReadEndElement();
        }