Beispiel #1
0
        /// <summary>
        /// This method contains the core implementation for generating the GeneratedCode
        /// instance.
        /// </summary>
        /// <remarks>
        /// This method decorates every type found in codeNamespace with a CodeTypeMemberExtension.
        /// And then it sends each type through series of ITypeFilters to figure out whether the type
        /// is a service contract, service type, client type, message contract or data contract.
        /// </remarks>
        private void ParseAndFilterCodeNamespace()
        {
            ITypeFilter dataContractTypeFilter    = new DataContractTypeFilter();
            ITypeFilter messageContractTypeFilter = new MessageContractTypeFilter();
            ITypeFilter serviceContractTypeFilter = new ServiceContractTypeFilter();
            ITypeFilter clientTypeTypeFilter      = new ClientTypeTypeFilter();
            ITypeFilter serviceTypeTypeFilter     = new ServiceTypeTypeFilter();

            for (int i = 0; i < codeNamespace.Types.Count; i++)
            {
                // Take a reference to the current CodeTypeDeclaration.
                CodeTypeDeclaration ctd = codeNamespace.Types[i];
                // Create a new instance of CodeTypeMemberExtension to wrap
                // the current CodeTypeDeclaration.
                CodeTypeExtension typeExtension = new CodeTypeExtension(ctd);

                // Also wrap the inner CodeTypeMember(s)
                ExtendTypeMembers(typeExtension);

                // Here we execute the type filters in the highest to lowest probability order.
                if (dataContractTypeFilter.IsMatching(typeExtension))
                {
                    typeExtension.Kind = CodeTypeKind.DataContract;
                    DataContracts.Add(typeExtension);
                    continue;
                }
                if (messageContractTypeFilter.IsMatching(typeExtension))
                {
                    typeExtension.Kind = CodeTypeKind.MessageContract;
                    MessageContracts.Add(typeExtension);
                    continue;
                }
                if (serviceContractTypeFilter.IsMatching(typeExtension))
                {
                    typeExtension.Kind = CodeTypeKind.ServiceContract;
                    ServiceContracts.Add(typeExtension);
                    continue;
                }
                if (clientTypeTypeFilter.IsMatching(typeExtension))
                {
                    typeExtension.Kind = CodeTypeKind.ClientType;
                    ClientTypes.Add(typeExtension);
                    continue;
                }
                if (serviceTypeTypeFilter.IsMatching(typeExtension))
                {
                    typeExtension.Kind = CodeTypeKind.ServiceType;
                    ServiceTypes.Add(typeExtension);
                    continue;
                }
                UnfilteredTypes.Add(typeExtension);
            }
        }