コード例 #1
0
        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;
        }
コード例 #2
0
        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
ファイル: CsdlParser.cs プロジェクト: larsenjo/odata.net
        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
ファイル: EnumType.cs プロジェクト: zhonli/odata.net
 /// <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);
 }
コード例 #7
0
 /// <summary>
 /// Visit Enum member
 /// </summary>
 /// <param name="enumMember">enum member to visit</param>
 protected virtual void VisitEnumMember(EnumMember enumMember)
 {
     this.VisitAnnotatedItem(enumMember);
 }
コード例 #8
0
ファイル: EnumType.cs プロジェクト: larsenjo/odata.net
 /// <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);
 }