Пример #1
0
        /// <summary>
        /// Retrieves the attribute.
        /// </summary>
        /// <returns>An instance of the attribute.</returns>
        public object GetAttribute()
        {
            // Skip over attribute initialization, if we already initialized the attribute
            if (null != _attribute)
            {
                return(_attribute);
            }

            // Retrieve the attribute type
            _attribute = CustomAttributeParser.Parse(_module, _attributeBlob, _ctorMethod);
            Debug.Assert(null != _attribute, @"Failed to load the attribute.");

            return(_attribute);
        }
Пример #2
0
        public void TestValidValue()
        {
            var          ap            = new CustomAttributeParser();
            const string attIdentifier = "$custom";

            var e = ap.ParsedAttribute(attIdentifier,
                                       null,
                                       new NParsedAttributeAtomic(new ParsedString("test")));

            Assert.IsInstanceOf(typeof(ParsedCustomAttribute), e);
            var pa = (ParsedCustomAttribute)e;

            StringAssert.AreEqualIgnoringCase("$custom", pa.Key);
            StringAssert.AreEqualIgnoringCase("test", pa.Value);
        }
Пример #3
0
        public void TestNotColonValue(NParsedAttributeValue v)
        {
            var          ap            = new CustomAttributeParser();
            const string attIdentifier = "$custom";

            var e = Assert.Catch(() => {
                ap.ParsedAttribute(attIdentifier,
                                   null,
                                   v);
            });

            Assert.IsInstanceOf(typeof(InvalidAttributeValueException), e);
            StringAssert.AreEqualIgnoringCase(
                string.Format(InvalidAttributeValueException.ATOMIC_ONLY, attIdentifier),
                e.Message
                );
        }
Пример #4
0
        public void TestNullParameter()
        {
            var          ap            = new CustomAttributeParser();
            const string attIdentifier = "$custom";

            var e = Assert.Catch(() => {
                ap.ParsedAttribute(attIdentifier,
                                   new NParsedAttributeAtomic(new ParsedFloat()),
                                   new NParsedAttributeAtomic(new IdentifierExpression("software")));
            });

            Assert.IsInstanceOf(typeof(InvalidParameterAttributeException), e);
            StringAssert.AreEqualIgnoringCase(
                string.Format(InvalidParameterAttributeException.NO_PARAM, attIdentifier),
                e.Message
                );
        }
Пример #5
0
        public void TestNotIdentifierValue()
        {
            var          ap            = new CustomAttributeParser();
            const string attIdentifier = "$custom";

            var e = Assert.Catch(() => {
                ap.ParsedAttribute(attIdentifier,
                                   null,
                                   new NParsedAttributeAtomic(new ParsedFloat()));
            });

            Assert.IsInstanceOf(typeof(InvalidAttributeValueException), e);
            StringAssert.AreEqualIgnoringCase(
                string.Format(InvalidAttributeValueException.STRING, attIdentifier),
                e.Message
                );
        }