GetFieldReference() public method

public GetFieldReference ( TypeDefinition type ) : FieldReference
type TypeDefinition
return Mono.Cecil.FieldReference
Ejemplo n.º 1
0
    public MethodReference Execute(TypeDefinition type)
    {
        CheckIsFrozenMethod = type.Methods.FirstOrDefault(IsCheckMethod);
        if (CheckIsFrozenMethod != null)
        {
            if (CheckIsFrozenMethod.IsStatic)
            {
                throw new WeavingException("CheckIfFrozen method can no be static");
            }
            if (!CheckIsFrozenMethod.IsFamily)
            {
                throw new WeavingException("CheckIfFrozen method needs to be protected");
            }
            return(moduleDefinition.ImportReference(CheckIsFrozenMethod));
        }
        if (type.Module != moduleDefinition)
        {
            throw new WeavingException($"Could not inject to '{type.FullName}' because it is not in the target assembly.");
        }
        var fieldReference = fieldInjector.GetFieldReference(type);

        CheckIsFrozenMethod = checkIsFrozenBuilder.Build(fieldReference);
        type.Methods.Add(CheckIsFrozenMethod);
        return(CheckIsFrozenMethod);
    }