Exemplo n.º 1
0
        public T GetValue <T>(MessageContext ctxt, CCI.Node node, CCI.TypeNode attrType, IProperty <T> property, bool inheritable)
        {
            var res = default(T);

            if (!GetValue(ctxt, node, attrType, property, inheritable, ref res))
            {
                res = property.Default;
            }
            return(res);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public bool HasAttribute(CCI.Node nodeDefn, CCI.TypeNode attrType, bool inheritable)
        {
            var assembly = nodeDefn as CCI.AssemblyNode;

            if (assembly != null)
            {
                // Assembly has no parent
                return(HasAttribute(assembly.Attributes, attrType));
            }

            var member = nodeDefn as CCI.Member;

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

            if (HasAttribute(member.Attributes, attrType))
            {
                return(true);
            }

            if (inheritable)
            {
                var typeDefn = nodeDefn as CCI.TypeNode;
                if (typeDefn != null)
                {
                    // Suppress inheritance for compiler-generated types, such as delegate environments
                    if (!HasAttribute(member.Attributes, env.CompilerGeneratedAttributeType))
                    {
                        if (typeDefn.DeclaringType != null)
                        {
                            // Parent of nested type is outer type
                            return(HasAttribute(typeDefn.DeclaringType, attrType, true));
                        }
                        else
                        {
                            // Parent of type is assembly
                            return(HasAttribute(typeDefn.DeclaringModule, attrType, true));
                        }
                    }
                }

                var propDefn = nodeDefn as CCI.Property;
                if (propDefn != null)
                {
                    // Parent of property is type
                    return(HasAttribute(propDefn.DeclaringType, attrType, true));
                }

                var evntDefn = nodeDefn as CCI.Event;
                if (evntDefn != null)
                {
                    // Parent of event is type
                    return(HasAttribute(evntDefn.DeclaringType, attrType, true));
                }

                var methodDefn = nodeDefn as CCI.Method;
                if (methodDefn != null)
                {
                    if (methodDefn.DeclaringMember != null)
                    {
                        // Parent of getter/setter/adder/remover is property/event
                        return(HasAttribute(methodDefn.DeclaringMember, attrType, true));
                    }

#if false
                    if (methodDefn.IsVirtual && methodDefn.OverriddenMethod != null)
                    {
                        var origDefn = methodDefn;
                        // Overridding methods have two parents: the virtual which introduced slot, and declaring type
                        do
                        {
                            origDefn = origDefn.OverriddenMethod;
                        }while (origDefn.IsVirtual && origDefn.OverriddenMethod != null);
                        if (origDefn.DeclaringType != env.ObjectType && HasAttribute(origDefn, attrType, true))
                        {
                            return(true);
                        }
                    }
#endif

                    // Parent of ordinary method is type
                    return(HasAttribute(methodDefn.DeclaringType, attrType, true));
                }
            }

            return(false);
        }
Exemplo n.º 4
0
 public T GetValue <T>(MessageContext ctxt, CCI.Node node, CCI.TypeNode attrType, IProperty <T> property)
 {
     return(GetValue <T>(ctxt, node, attrType, property, true));
 }