Exemple #1
0
        public TTargetModel Bind(string topic)
        {
            if (RegisteredVariables.Count == 0)
            {
                return(TargetFactory());
            }

            var match = RegexPattern.Match(topic);

            if (!match.Success)
            {
                throw new ArgumentException("The supplied topic did not match the configured pattern");
            }

            var target = TargetFactory.Invoke();

            foreach (var registeredVariable in RegisteredVariables)
            {
                var value  = match.Groups[registeredVariable].Value;
                var setter = PropertySetters[registeredVariable];

                setter.Invoke(target, value);
            }

            return(target);
        }