Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TokenGroupItem"/> class
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="member">The member.</param>
        /// <param name="valueType">Type of the value.</param>
        public TokenGroupItem(string name, TokenMember member, Type valueType)
            : base(valueType)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            else if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            _name      = name;
            _groupType = valueType ?? member.DataType;
            _member    = member;

            ConstructorInfo ci = _groupType.GetConstructor(Type.EmptyTypes);

            if (ci == null || !ci.IsPublic || _groupType.IsAbstract)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, TokenizerMessages.CantUseTypeXAsTokenGroupBecauseItHasNoPublicParameterlessConstructor, _groupType.FullName), "memberType");
            }

            if (valueType != null && !_member.DataType.IsAssignableFrom(valueType))
            {
                throw new ArgumentException("valueType must be assignable to datatype of member", "valueType");
            }
        }
Example #2
0
        public StaticTokenizerDefinition()
        {
            foreach (MemberInfo mi in typeof(T).GetMembers(BindingFlags.Public | BindingFlags.Instance))
            {
                if ((mi.MemberType != MemberTypes.Field) && (mi.MemberType != MemberTypes.Property))
                {
                    continue;
                }

                if (null == GetFirstAttribute <BaseTokenAttribute>(mi))
                {
                    continue;
                }

                TokenMember token = new TokenMember(mi);
                _tokens.Add(token.Name, token);

                foreach (PositionTokenAttribute pos in mi.GetCustomAttributes(typeof(PositionTokenAttribute), true))
                {
                    if (pos is RestTokenAttribute)
                    {
                        SetRest(pos.CreateToken(token));
                    }
                    else
                    {
                        AddPlaced(pos.Position, pos.CreateToken(token));
                    }
                }
            }

            Validate();
        }
Example #3
0
        /// <summary>
        /// Adds the token.
        /// </summary>
        /// <param name="token">The token.</param>
        protected void AddToken(TokenMember token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            _tokens.Add(token.Name, token);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TokenItem"/> class.
        /// </summary>
        /// <param name="member">The member.</param>
        /// <param name="attr">The attr.</param>
        /// <param name="valueType">Type of the value.</param>
        public TokenItem(TokenMember member, TokenAttribute attr, Type valueType)
            : base(valueType)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            _name    = attr.Name;
            _aliases = attr.Aliases;

            _member        = member;
            _typeConverter = attr.TypeConverter ?? member.DefaultTypeConverter;

            if (valueType != null && !_member.DataType.IsAssignableFrom(valueType))
            {
                throw new ArgumentException("valueType must be assignable to datatype of member", "valueType");
            }
        }
Example #5
0
 /// <summary>
 /// Creates a <see cref="TokenItem"/> instance.
 /// </summary>
 /// <param name="tokenMember">The token member.</param>
 /// <returns></returns>
 public override QQn.TurtleUtils.Tokens.Definitions.TokenItem CreateToken(QQn.TurtleUtils.Tokens.Definitions.TokenMember tokenMember)
 {
     return(new PlusMinToken(tokenMember, this, ValueType));
 }