Пример #1
0
        internal RtfAttributeInfo(MemberInfo memberInfo)
        {
            _memberInfo = memberInfo;

            object[] attributes = MemberInfo.GetCustomAttributes(false);

            hasAttributes = attributes.Length > 0;

            if (!hasAttributes)
            {
                return;
            }

            controlWordAttribute  = GetAttribute(attributes, typeof(RtfControlWordAttribute)) as RtfControlWordAttribute;
            controlGroupAttribute = GetAttribute(attributes, typeof(RtfControlGroupAttribute)) as RtfControlGroupAttribute;

            controlWordDenotingEndAttribute = GetAttribute(attributes, typeof(RtfControlWordDenotingEndAttribute)) as RtfControlWordDenotingEndAttribute;
            enclosingBracesAttribute        = GetAttribute(attributes, typeof(RtfEnclosingBracesAttribute)) as RtfEnclosingBracesAttribute;

            ignoreAttribute  = GetAttribute(attributes, typeof(RtfIgnoreAttribute)) as RtfIgnoreAttribute;
            includeAttribute = GetAttribute(attributes, typeof(RtfIncludeAttribute)) as RtfIncludeAttribute;

            indexAttribute = GetAttribute(attributes, typeof(RtfIndexAttribute)) as RtfIndexAttribute;

            enumAsControlWordAttribute = GetAttribute(attributes, typeof(RtfEnumAsControlWordAttribute)) as RtfEnumAsControlWordAttribute;

            textDataAttribute = GetAttribute(attributes, typeof(RtfTextDataAttribute)) as RtfTextDataAttribute;

            object[] neededAttributes = new object[] {
                controlWordAttribute,
                controlGroupAttribute,
                controlWordDenotingEndAttribute,
                enclosingBracesAttribute,
                ignoreAttribute,
                includeAttribute,
                indexAttribute,
                enumAsControlWordAttribute,
                textDataAttribute,
            };

            hasAttributes = false;

            for (int i = 0; !hasAttributes && i < neededAttributes.Length; i++)
            {
                hasAttributes |= neededAttributes != null;
            }
        }
Пример #2
0
        private bool GetCondition(object instance, RtfIncludeAttribute includeAttribute)
        {
            if (String.IsNullOrEmpty(includeAttribute.ConditionMember))
            {
                return(true);
            }

            Type type = instance.GetType();

            MemberInfo[] memberInfo = type.GetMember(includeAttribute.ConditionMember);

            if (memberInfo.Length == 1)
            {
                MemberInfo member = memberInfo[0];

                if (member.MemberType == MemberTypes.Property || member.MemberType == MemberTypes.Field)
                {
                    return((GetMemberType(member) == typeof(bool)) && (includeAttribute.Value == (bool)GetMemberValue(member, instance)));
                }
            }

            return(false);
        }