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);
            }
        }
Example #3
0
        public bool GetValue <T>(MessageContext ctxt, CCI.Node node, CCI.TypeNode attrType, IProperty <T> property, bool inheritable, ref T value)
        {
            var assembly = node as CCI.AssemblyNode;

            if (assembly != null)
            {
                // Assembly has no parent
                return(GetValue
                           (RewriterMsgContext.Assembly(ctxt, assembly), assembly.Attributes, attrType, property, ref value));
            }

            var member = node as CCI.Member;

            if (member == null)
            {
                return(false);
            }

            if (GetValue(RewriterMsgContext.Member(ctxt, member), member.Attributes, attrType, property, ref value))
            {
                return(true);
            }

            if (inheritable)
            {
                var type = node as CCI.TypeNode;
                if (type != null)
                {
                    // Suppress inheritance for compiler-generated types, such as delegate environments
                    if (!HasAttribute(member.Attributes, env.CompilerGeneratedAttributeType))
                    {
                        if (type.DeclaringType != null)
                        {
                            // Parent of nested type is declaring type
                            return(GetValue
                                       (RewriterMsgContext.Type(ctxt, type),
                                       type.DeclaringType,
                                       attrType,
                                       property,
                                       true,
                                       ref value));
                        }
                        else
                        {
                            // Parent of type is assembly
                            return(GetValue
                                       (ctxt, type.DeclaringModule.ContainingAssembly, attrType, property, true, ref value));
                        }
                    }
                }

                var prop = node as CCI.Property;
                if (prop != null)
                {
                    // Parent of property is type
                    return(GetValue(ctxt, prop.DeclaringType, attrType, property, true, ref value));
                }

                var evnt = node as CCI.Event;
                if (evnt != null)
                {
                    // Parent of event is type
                    return(GetValue(ctxt, evnt.DeclaringType, attrType, property, true, ref value));
                }

                var method = node as CCI.Method;
                if (method != null)
                {
                    if (method.DeclaringMember != null)
                    {
                        // Parent of getter/setter/adder/remover is declaring member
                        return(GetValue(ctxt, method.DeclaringMember, attrType, property, true, ref value));
                    }
#if false
                    if (method.IsVirtual && method.OverriddenMethod != null)
                    {
                        var origDefn = method;
                        // Parent of virtual is virtual which introduced slot, unless it is from Object
                        do
                        {
                            origDefn = origDefn.OverriddenMethod;
                        }while (origDefn.IsVirtual && origDefn.OverriddenMethod != null);
                        if (origDefn.DeclaringType != env.ObjectType)
                        {
                            return(GetValue(ctxt, origDefn, attrType, property, true, ref value));
                        }
                    }
#endif
                    // Parent of ordinary method is type
                    return(GetValue(ctxt, method.DeclaringType, attrType, property, true, ref value));
                }
            }

            return(false);
        }