Ejemplo n.º 1
0
        private void CheckInstructionReferencesBroker(Instruction instruction)
        {
            if (instruction.OpCode == OpCodes.Ldtoken ||
                instruction.OpCode == OpCodes.Isinst ||
                instruction.OpCode == OpCodes.Castclass ||
                instruction.OpCode == OpCodes.Box ||
                instruction.OpCode == OpCodes.Newarr)
            {
                TypeReference type = instruction.Operand as TypeReference;
                if (type != null)
                {
                    if (type.BelongsToAssembly(BrokerKeyToken) ||
                        IsGenericInstanceArgumentsReferenceBroker(type as GenericInstanceType))
                    {
                        _log.LogError(CompilationMessage.From("Types from AspectInjector.Broker can't be referenced", instruction));
                    }
                }
            }

            if (instruction.OpCode == OpCodes.Ldtoken ||
                instruction.OpCode == OpCodes.Call ||
                instruction.OpCode == OpCodes.Callvirt ||
                instruction.OpCode == OpCodes.Newobj)
            {
                MethodReference method = instruction.Operand as MethodReference;
                if (method != null)
                {
                    if (method.DeclaringType.BelongsToAssembly(BrokerKeyToken) ||
                        IsGenericInstanceArgumentsReferenceBroker(method as GenericInstanceMethod))
                    {
                        _log.LogError(CompilationMessage.From("Types from AspectInjector.Broker can't be referenced", instruction));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private bool IsInstructionReferencesBroker(Instruction instruction)
        {
            if (instruction.OpCode == OpCodes.Ldtoken ||
                instruction.OpCode == OpCodes.Isinst ||
                instruction.OpCode == OpCodes.Castclass ||
                instruction.OpCode == OpCodes.Newarr)
            {
                TypeReference type = instruction.Operand as TypeReference;
                if (type != null)
                {
                    return(type.BelongsToAssembly(BrokerAssemblyPublicKeyToken) ||
                           IsGenericInstanceArgumentsReferenceBroker(type as GenericInstanceType));
                }
            }

            if (instruction.OpCode == OpCodes.Ldtoken ||
                instruction.OpCode == OpCodes.Call ||
                instruction.OpCode == OpCodes.Callvirt ||
                instruction.OpCode == OpCodes.Newobj)
            {
                MethodReference method = instruction.Operand as MethodReference;
                if (method != null)
                {
                    return(method.DeclaringType.BelongsToAssembly(BrokerAssemblyPublicKeyToken) ||
                           IsGenericInstanceArgumentsReferenceBroker(method as GenericInstanceMethod));
                }
            }

            return(false);
        }