SipSharp.Messages.Headers.HeaderFactory.AddDefaultParsers C# (CSharp) Method

AddDefaultParsers() public method

Add all default parsers in the library.
public AddDefaultParsers ( ) : void
return void
        public void AddDefaultParsers()
        {
            string ns = GetType().Namespace + ".Parsers";
            Type parserInterface = typeof (IHeaderParser);

            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.Namespace != ns)
                    continue;
                if (!parserInterface.IsAssignableFrom(type))
                    continue;
                if (type.IsInterface || type.IsAbstract)
                    continue;

                var parser = (IHeaderParser) Activator.CreateInstance(type);
                foreach (object attr in type.GetCustomAttributes(false))
                {
                    // Generic parser should not be added automatically.
                    if (attr is GenericParserAttribute)
                        break;

                    var attribute = attr as ParserForAttribute;
                    if (attribute != null)
                        AddParser(parser, attribute.Name, attribute.CompactName);
                }
            }
        }

Usage Example

コード例 #1
0
        public MessageFactoryTest()
        {
            LogFactory.Assign(new ConsoleLogFactory(null));

            _headerFactory = new HeaderFactory();
            _headerFactory.AddDefaultParsers();
            _factory = new MessageFactory(_headerFactory);
            _factory.RequestReceived += OnRequest;
            _factory.ResponseReceived += OnResponse;
        }
All Usage Examples Of SipSharp.Messages.Headers.HeaderFactory::AddDefaultParsers