Example #1
0
        private bool GetValue <T>(MessageContext ctxt, CCI.AttributeList attributes, CCI.TypeNode attrType, IProperty <T> property, ref T value)
        {
            var found = 0;

            foreach (var attribute in attributes)
            {
                if (IsAttribute(attribute, attrType))
                {
                    var thisValue = default(T);
                    if (GetValue(ctxt, attribute, attrType, property, ref thisValue))
                    {
                        if (found++ == 0)
                        {
                            value = thisValue;
                        }
                        else
                        {
                            if (!thisValue.Equals(value))
                            {
                                env.Log(new InvalidInteropMessage
                                            (RewriterMsgContext.AttributeProperty(ctxt, attribute, property.Name),
                                            "duplicate inconsistent bindings"));
                                throw new DefinitionException();
                            }
                        }
                    }
                }
            }
            return(found > 0);
        }
Example #2
0
        public bool GetValue <T>(MessageContext ctxt, CCI.AttributeNode attribute, CCI.TypeNode attrType, IProperty <T> property, ref T value)
        {
            var expr = default(CCI.Literal);

            if (property.Position >= 0)
            {
                expr = attribute.GetPositionalArgument(property.Position) as CCI.Literal;
            }
            if (expr == null)
            {
                expr = attribute.GetNamedArgument(CCI.Identifier.For(property.Name)) as CCI.Literal;
            }
            if (expr != null)
            {
                value = property.Value(RewriterMsgContext.AttributeProperty(ctxt, attribute, property.Name), expr.Value);
                return(true);
            }
            else
            {
                return(false);
            }
        }