public MapField<string, long> MetricCosts { get; }
Metrics to update when the selected methods are called, and the associated
cost applied to each metric.
The key of the map is the metric name, and the values are the amount
increased for the metric against which the quota limits are defined.
The value must not be negative.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[[["\u003cp\u003e\u003ccode\u003eMetricRule\u003c/code\u003e is a class that binds API methods to metrics, applying configured quota behaviors to method calls.\u003c/p\u003e\n"],["\u003cp\u003eThe class implements several interfaces, including \u003ccode\u003eIMessage\u003c/code\u003e, \u003ccode\u003eIEquatable\u003c/code\u003e, \u003ccode\u003eIDeepCloneable\u003c/code\u003e, and \u003ccode\u003eIBufferMessage\u003c/code\u003e, and inherits from the \u003ccode\u003eobject\u003c/code\u003e class.\u003c/p\u003e\n"],["\u003cp\u003eKey properties include \u003ccode\u003eMetricCosts\u003c/code\u003e, which defines the metrics to update and their associated costs when selected methods are called, and \u003ccode\u003eSelector\u003c/code\u003e, which specifies the methods this rule applies to.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eMetricRule\u003c/code\u003e provides methods such as \u003ccode\u003eClone()\u003c/code\u003e, \u003ccode\u003eEquals()\u003c/code\u003e, \u003ccode\u003eGetHashCode()\u003c/code\u003e, \u003ccode\u003eMergeFrom()\u003c/code\u003e, \u003ccode\u003eCalculateSize()\u003c/code\u003e, \u003ccode\u003eWriteTo()\u003c/code\u003e and \u003ccode\u003eToString()\u003c/code\u003e to manage the object, and provides constructor methods \u003ccode\u003eMetricRule()\u003c/code\u003e and \u003ccode\u003eMetricRule(MetricRule other)\u003c/code\u003e to create new instances.\u003c/p\u003e\n"],["\u003cp\u003eThe class has two constant fields, \u003ccode\u003eMetricCostsFieldNumber\u003c/code\u003e and \u003ccode\u003eSelectorFieldNumber\u003c/code\u003e, that are used as field numbers and are of type \u003ccode\u003eint\u003c/code\u003e, in addition to \u003ccode\u003eDescriptor\u003c/code\u003e and \u003ccode\u003eParser\u003c/code\u003e properties.\u003c/p\u003e\n"]]],[],null,["# Class MetricRule (2.17.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.17.0 (latest)](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MetricRule)\n- [2.15.0](/dotnet/docs/reference/Google.Api.CommonProtos/2.15.0/Google.Api.MetricRule)\n- [2.10.0](/dotnet/docs/reference/Google.Api.CommonProtos/2.10.0/Google.Api.MetricRule)\n- [2.2.0](/dotnet/docs/reference/Google.Api.CommonProtos/2.2.0/Google.Api.MetricRule) \n\n public sealed class MetricRule : IMessage\u003cMetricRule\u003e, IEquatable\u003cMetricRule\u003e, IDeepCloneable\u003cMetricRule\u003e, IBufferMessage, IMessage\n\nBind API methods to metrics. Binding a method to a metric causes that\nmetric's configured quota behaviors to apply to the method call. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e MetricRule \n\nImplements\n----------\n\n[IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1.html)[MetricRule](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MetricRule), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[MetricRule](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MetricRule), [IDeepCloneable](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1.html)[MetricRule](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MetricRule), [IBufferMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IBufferMessage.html), [IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html) \n\nInherited Members\n-----------------\n\n[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals)\n\nNamespace\n---------\n\n[Google.Api](/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api)\n\nAssembly\n--------\n\nGoogle.Api.CommonProtos.dll\n\nConstructors\n------------\n\n### MetricRule()\n\n public MetricRule()\n\n### MetricRule(MetricRule)\n\n public MetricRule(MetricRule other)\n\nFields\n------\n\n### MetricCostsFieldNumber\n\n public const int MetricCostsFieldNumber = 2\n\nField number for the \"metric_costs\" field.\n\n### SelectorFieldNumber\n\n public const int SelectorFieldNumber = 1\n\nField number for the \"selector\" field.\n\nProperties\n----------\n\n### Descriptor\n\n public static MessageDescriptor Descriptor { get; }\n\n### MetricCosts\n\n public MapField\u003cstring, long\u003e MetricCosts { get; }\n\nMetrics to update when the selected methods are called, and the associated\ncost applied to each metric.\n\nThe key of the map is the metric name, and the values are the amount\nincreased for the metric against which the quota limits are defined.\nThe value must not be negative.\n\n### Parser\n\n public static MessageParser\u003cMetricRule\u003e Parser { get; }\n\n### Selector\n\n public string Selector { get; set; }\n\nSelects the methods to which this rule applies.\n\nRefer to \\[selector\\]\\[google.api.DocumentationRule.selector\\] for syntax\ndetails.\n\nMethods\n-------\n\n### CalculateSize()\n\n public int CalculateSize()\n\n### Clone()\n\n public MetricRule Clone()\n\n### Equals(MetricRule)\n\n public bool Equals(MetricRule other)\n\n### Equals(object)\n\n public override bool Equals(object other)\n\n**Overrides** \n[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object))\n\n### GetHashCode()\n\n public override int GetHashCode()\n\n**Overrides** \n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode)\n\n### MergeFrom(MetricRule)\n\n public void MergeFrom(MetricRule other)\n\n### MergeFrom(CodedInputStream)\n\n public void MergeFrom(CodedInputStream input)\n\n### ToString()\n\n public override string ToString()\n\n**Overrides** \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\n### WriteTo(CodedOutputStream)\n\n public void WriteTo(CodedOutputStream output)"]]