# DictionaryDisplayForTypeAttribute

> Configures how the Inspector presents a serialized Dictionary identified by type, for dictionaries that have no field to decorate.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule
* **Inherits from:** [DictionaryDisplayAttribute](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute.md)

```csharp
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
public sealed class DictionaryDisplayForTypeAttribute : DictionaryDisplayAttribute
```

## Remarks

`DictionaryDisplayForType` is the assembly-level form of [DictionaryDisplayAttribute](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute.md). It has the same presentation settings: [layout](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/layout.md), [keyLabel](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/keylabel.md), [valueLabel](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/valuelabel.md), and [keyColumnFraction](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/keycolumnfraction.md). The difference is that you name the dictionary to configure with a `typeof` argument instead of attaching the attribute to a field.

This attribute targets assemblies, so you apply it with an assembly-level attribute declaration. Use it to:

* Configure a dictionary that has no field to attach a field attribute to, such as the inner dictionary of a `Dictionary<int, Dictionary<string, StatModifier>>`.
* Apply one presentation to every field of the same dictionary type from a single declaration, instead of repeating [DictionaryDisplayAttribute](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute.md) on each field.

The [targetType](/engine/6000.7/script-reference/unityengine/dictionarydisplayfortypeattribute/targettype.md) must be a fully specified `Dictionary<TKey, TValue>`, such as `Dictionary<string, StatModifier>`. The attribute applies to every dictionary of that exact type, wherever it appears, and sets the layout, labels, and key-column fraction. Unity ignores a target that isn't a fully specified dictionary type.

You can only declare a rule for a dictionary when the attribute's assembly defines the dictionary's key type, its value type, or a type nested inside either. For example, an assembly that defines `StatModifier` can target `Dictionary<string, StatModifier>`, `Dictionary<int, StatModifier[]>`, or `Dictionary<int, List<StatModifier>>`. This prevents a rule in one assembly from changing a dictionary built only from types it doesn't define, such as `Dictionary<int, int>`. If the target uses no type from the attribute's assembly, Unity ignores the rule and logs a warning in the console.

When more than one source can set a dictionary's presentation, Unity uses the first source that applies, from highest precedence to lowest:

1. The user's own choices: the layout from the header context menu and the column width from dragging the divider. These choices persist and override every attribute until the user selects **Reset to Defaults**.
2. A field-level [DictionaryDisplayAttribute](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute.md) on the dictionary field sets the layout, labels, and width.
3. An assembly-level `DictionaryDisplayForType` on the exact `Dictionary<TKey, TValue>` sets the layout, labels, and width.
4. The built-in defaults: [DictionaryLayout.TwoColumns](/engine/6000.7/script-reference/unityengine/dictionarylayout/twocolumns.md) layout, **Key** and **Value** labels, and a 0.5 key-column fraction.

## Examples

```csharp
using System.Collections.Generic;
using UnityEngine;

// One declaration configures every Dictionary<string, StatModifier> in the assembly: the nested
// dictionary in Equipment and the field in Buff, without repeating [DictionaryDisplay]. This
// assembly defines StatModifier, so the attribute is allowed to target this dictionary.
[assembly: DictionaryDisplayForType(typeof(Dictionary<string, StatModifier>),
    layout = DictionaryLayout.OneColumnWithValueVisible,
    keyLabel = "Stat", valueLabel = "Modifier", keyColumnFraction = 0.4f)]

[System.Serializable]
public struct StatModifier
{
    public float amount;
    public bool isPercentage;
}

public class Equipment : MonoBehaviour
{
    // Nested inner dictionary: a value, so it has no field to decorate.
    [SerializeField]
    private Dictionary<int, Dictionary<string, StatModifier>> modifiersPerSlot = new();
}

public class Buff : MonoBehaviour
{
    // A direct field of the same type, styled by the same declaration.
    [SerializeField]
    private Dictionary<string, StatModifier> statModifiers = new();
}
```

## Constructors

| Constructor                                                                                                                             | Description                                                                          |
| --------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| [DictionaryDisplayForTypeAttribute(System.Type)](/engine/6000.7/script-reference/unityengine/dictionarydisplayfortypeattribute/ctor.md) | Creates an attribute that configures the dictionary type identified by `targetType`. |

## Properties

| Property                                                                                                  | Description                                                                                                                                          |
| --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| [targetType](/engine/6000.7/script-reference/unityengine/dictionarydisplayfortypeattribute/targettype.md) | The dictionary type this attribute configures. Must be a fully specified `Dictionary<TKey, TValue>`, for example `Dictionary<string, StatModifier>`. |

## Inheritance

**Inherited Members:**

* [DictionaryDisplayAttribute.layout](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/layout.md)
* [DictionaryDisplayAttribute.keyLabel](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/keylabel.md)
* [DictionaryDisplayAttribute.valueLabel](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/valuelabel.md)
* [DictionaryDisplayAttribute.keyColumnFraction](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/keycolumnfraction.md)
* [Attribute.GetCustomAttributes(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-type\))
* [Attribute.GetCustomAttributes(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(MemberInfo)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo\))
* [Attribute.GetCustomAttributes(MemberInfo, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-boolean\))
* [Attribute.IsDefined(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-memberinfo-system-type\))
* [Attribute.IsDefined(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-memberinfo-system-type\))
* [Attribute.GetCustomAttribute(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(ParameterInfo)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo\))
* [Attribute.GetCustomAttributes(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-type\))
* [Attribute.GetCustomAttributes(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(ParameterInfo, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-boolean\))
* [Attribute.IsDefined(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-parameterinfo-system-type\))
* [Attribute.IsDefined(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-parameterinfo-system-type\))
* [Attribute.GetCustomAttribute(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-type\))
* [Attribute.GetCustomAttributes(Module)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module\))
* [Attribute.GetCustomAttributes(Module, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-boolean\))
* [Attribute.GetCustomAttributes(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-type-system-boolean\))
* [Attribute.IsDefined(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-module-system-type\))
* [Attribute.IsDefined(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-module-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-module-system-type\))
* [Attribute.GetCustomAttribute(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-module-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-type\))
* [Attribute.GetCustomAttributes(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Assembly)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly\))
* [Attribute.GetCustomAttributes(Assembly, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-boolean\))
* [Attribute.IsDefined(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-assembly-system-type\))
* [Attribute.IsDefined(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-assembly-system-type\))
* [Attribute.GetCustomAttribute(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.Equals(Object)](https://learn.microsoft.com/dotnet/api/system.attribute.equals)
* [Attribute.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.attribute.gethashcode)
* [Attribute.Match(Object)](https://learn.microsoft.com/dotnet/api/system.attribute.match)
* [Attribute.IsDefaultAttribute()](https://learn.microsoft.com/dotnet/api/system.attribute.isdefaultattribute)
* [Attribute.TypeId()](https://learn.microsoft.com/dotnet/api/system.attribute.typeid)
