自定义绑定Customizing Bindings

通过编辑控制绑定过程的元数据,可以自定义的 Xamarin.Android 绑定。这些手动修改通常是必需的解决生成错误的定型所获得的 API,这样就与更加一致C#/.NET。这些指南介绍了此元数据的结构、 如何修改的元数据,以及如何使用 JavaDoc 恢复方法参数的名称。You can customize an Xamarin.Android binding by editing the metadata that controls the binding process. These manual modifications are often necessary for resolving build errors and for shaping the resulting API so that it is more consistent with C#/.NET. These guides explain the structure of this metadata, how to modify the metadata, and how to use JavaDoc to recover the names of method parameters.

概述Overview

Xamarin.Android 可自动执行大部分绑定过程中;但是,在某些情况下手动修改被需要解决以下问题:Xamarin.Android automates much of the binding process; however, in some cases manual modification is required to address the following issues:

  • 解决生成错误引起的缺少类型、 经过模糊处理的类型、 重复的名称、 类的可见性问题,以及其他无法解析的情况下由 Xamarin.Android 工具。Resolving build errors caused by missing types, obfuscated types, duplicate names, class visibility issues, and other situations that cannot be resolved by the Xamarin.Android tooling.

  • 更改 Xamarin.Android 使用要绑定到中的不同类型的 Android API 映射C#(例如,许多开发人员更喜欢映射 Javaint常量C#enum常量)。Changing the mapping that Xamarin.Android uses to bind the Android API to different types in C# (for example, many developers prefer to map Java int constants to C# enum constants).

  • 正在删除未使用不需要绑定的类型。Removing unused types that do not need to be bound.

  • 添加基础 Java API 中有任何相对应的类型。Adding types that have no counterpart in the underlying Java API.

可以通过修改控制绑定过程的元数据进行部分或所有这些更改。You can make some or all of these changes by modifying the metadata that controls the binding process.

参考线Guides

以下指南描述了控制绑定过程的元数据,并解释如何修改此元数据来解决这些问题:The following guides describe the metadata that controls the binding process and explain how to modify this metadata to address these issues:

  • Java 绑定元数据提供进入 Java 绑定元数据的概述。Java Bindings Metadata provides an overview of the metadata that goes into a Java binding. 它介绍了完成 Java 绑定库,有时需要的各种手动步骤,并介绍如何来调整一个绑定以更紧密地遵循.NET 设计指南所公开的 API。It describes the various manual steps that are sometimes required to complete a Java binding library, and it explains how to shape an API exposed by a binding to more closely follow .NET design guidelines.

  • 使用 Javadoc 命名参数介绍了如何通过使用从绑定的 Java 项目生成的 Javadoc 恢复 Java 绑定项目中的参数名称。Naming Parameters with Javadoc explains how to recover parameter names in a Java Binding Project by using Javadoc produced from the bound Java project.