private EnumMember CalculateValue(EnumType enumType, string name, object value)
        {
            EnumMember enumMember;
             
            if (enumType.UnderlyingType == null)
                {
                    enumMember = new EnumMember(name, Convert.ChangeType(value, typeof(int), CultureInfo.InvariantCulture));
                }
                else
                {
                    enumMember = new EnumMember(name, Convert.ChangeType(value, enumType.UnderlyingType, CultureInfo.InvariantCulture));
                }

            return enumMember;
        }
        private EnumType ConvertToTaupoEnumType(IEdmEnumType edmEnum)
        {
            var taupoEnumType = new EnumType(edmEnum.Namespace, edmEnum.Name);
            if (edmEnum.IsFlags)
            {
                taupoEnumType.IsFlags = true;
            }

            if (edmEnum.UnderlyingType != null)
            {
                taupoEnumType.UnderlyingType = this.ConvertToClrType(edmEnum.UnderlyingType);
            }

            foreach (var edmEnumMember in edmEnum.Members)
            {
                var taupoEnumMember = new EnumMember(edmEnumMember.Name);

                if (edmEnumMember.Value != null)
                {
                    taupoEnumMember.Value = this.ConvertToClrObject(edmEnumMember.Value);
                }

                taupoEnumType.Add(taupoEnumMember);
            }

            return taupoEnumType;
        }
示例#3
0
 private void CompareEnumMember(EnumType expectedEnumType, EnumMember expectedMemeber, EnumType actualEnumType, EnumMember actualMember)
 {
     this.SatisfiesEquals(expectedMemeber.Name, actualMember.Name, "Enum member name not match.");
     this.SatisfiesEquals(this.GetIntegralEnumMemberValue(expectedEnumType, expectedMemeber), this.GetIntegralEnumMemberValue(actualEnumType, actualMember), "Enum member value does not match.");
     this.CompareAnnotations(expectedMemeber.Annotations, actualMember.Annotations);
 }
示例#4
0
        private object GetIntegralEnumMemberValue(EnumType enumType, EnumMember enumMember)
        {
            var targetEnumMember = enumType.Members.Single(n => n == enumMember);

            if (targetEnumMember.Value != null)
            {
                long integralValue = 0;
                if (long.TryParse(targetEnumMember.Value.ToString(), out integralValue))
                {
                    return integralValue;
                }

                return targetEnumMember.Value;
            }

            if (enumType.Members.ElementAt(0) == targetEnumMember)
            {
                return 0L;
            }

            int memberIndex = 0;
            for (int i = 1; i < enumType.Members.Count; ++i)
            {
                if (enumType.Members.ElementAt(i) == targetEnumMember)
                {
                    memberIndex = i;
                    break;
                }
            }

            var previousMember = enumType.Members.ElementAt(memberIndex - 1);
            var previousValue = previousMember.Value;
            if (previousValue == null)
            {
                previousValue = this.GetIntegralEnumMemberValue(enumType, previousMember);
            }

            long previousIntegralValue = 0;
            if (long.TryParse(previousValue.ToString(), out previousIntegralValue))
            {
                return previousIntegralValue + 1;
            }
            else
            {
                return targetEnumMember.Value;
            }
        }
示例#5
0
        private EnumMember ParseEnumMember(XElement memberElement)
        {
            string name = memberElement.GetRequiredAttributeValue("Name");
            string valueString = memberElement.GetOptionalAttributeValue("Value", null);

            var member = new EnumMember(name, valueString);

            this.ParseAnnotations(member, memberElement);
            return member;
        }
示例#6
0
 /// <summary>
 /// Adds a new member to this Enum type
 /// </summary>
 /// <param name="member">The enum member to be added</param>
 public void Add(EnumMember member)
 {
     this.Members.Add(member);
 }
 /// <summary>
 /// Visit Enum member
 /// </summary>
 /// <param name="enumMember">enum member to visit</param>
 protected virtual void VisitEnumMember(EnumMember enumMember)
 {
     this.VisitAnnotatedItem(enumMember);
 }
示例#8
0
 /// <summary>
 /// Adds a new member to this Enum type
 /// </summary>
 /// <param name="member">The enum member to be added</param>
 public void Add(EnumMember member)
 {
     this.Members.Add(member);
 }