Exemplo n.º 1
0
        public bool CouldBeInlinableBasedOnHeaderAlone(CST.AssemblyDef assemblyDef, CST.TypeDef typeDef, CST.MethodDef methodDef)
        {
            if (methodDef.IsVirtualOrAbstract || typeDef.Style is CST.InterfaceTypeStyle)
                // No virtuals or interface methods
                return false;

            if (typeDef.Style is CST.MultiDimArrayTypeStyle)
                // Implemented by runtime
                return false;

            if (typeDef.IsAttributeType(env.Global, assemblyDef))
                // Don't inline attribute property methods since we invoke them directly when building attributes
                return false;

            var level = default(ReflectionLevel);
            env.AttributeHelper.GetValueFromType
                (assemblyDef,
                 typeDef,
                 env.AttributeHelper.ReflectionAttributeRef,
                 env.AttributeHelper.TheReflectionLevelProperty,
                 true,
                 true,
                 ref level);
            if (level >= ReflectionLevel.Full)
                // No inlining in classes needing full reflection since need to support dynamic invokes
                return false;

            // NOTE: Method may be used in a delegate, in which case it's fine to inline but we'll still
            //       need to emit the definition

            if (assemblyDef.EntryPoint != null &&
                assemblyDef.EntryPoint.QualifiedMemberName.Equals
                    (methodDef.QualifiedMemberName(env.Global, assemblyDef, typeDef)))
                // Entry points are called directly by startup code
                return false;

            return true;
        }