Exemplo n.º 1
0
 private void SetEnumValue(EnumMemberContext node, EnumMemberBuilder builder)
 {
     if (node.enumValue != null)
     {
         var(value, reason) = this.GetEnumValue(node);
         builder.SetValue(value);
         builder.SetInvalidValueReason(reason);
     }
     else if (node.EQUALS_OPERATOR() == null)
     {
         builder.SetValue(this.CalculateAutomaticValue(node));
     }
 }
Exemplo n.º 2
0
        protected EnumMember SetupMember(EnumMemberContext enumMemberNode, Enum containingEnum, string name = null, int?value = null)
        {
            var member = new EnumMemberBuilder()
                         .SetNode(enumMemberNode)
                         .SetName(name)
                         .SetValue(value)
                         .SetRawValue(value?.ToString())
                         .Build();

            this.BinderProvider.GetBinder(enumMemberNode).Returns(this.enumMemberBinder);
            this.enumMemberBinder.Bind <EnumMember>(enumMemberNode, containingEnum).Returns(member);

            return(member);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override EnumMember Bind(EnumMemberContext node, IEnum parent)
        {
            var builder = new EnumMemberBuilder()
                          .SetNode(node)
                          .SetParent(parent)
                          .SetBinderProvider(this.binderProvider)
                          .SetName(node.IDENTIFIER()?.Symbol.Text)
                          .SetRawValue(node.enumValue?.Text)
                          .SetIsValueImplicit(node.EQUALS_OPERATOR() == null && node.enumValue == null);

            this.SetEnumValue(node, builder);

            if (node.EQUALS_OPERATOR() != null && node.enumValue == null)
            {
                builder.SetInvalidValueReason(InvalidEnumValueReason.Missing);
            }

            return(builder.Build());
        }