ProjectDDD/Assets/_DDD/_Scripts/GameUi/New/Utils/BindToAttribute.cs
2025-08-20 15:22:08 +09:00

114 lines
4.1 KiB
C#

using System;
namespace DDD.MVVM
{
/// <summary>
/// UI 요소를 ViewModel 속성에 바인딩하기 위한 Attribute
/// Inspector에서 바인딩 정보를 시각적으로 확인할 수 있도록 지원
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field)]
public class BindToAttribute : System.Attribute
{
/// <summary>
/// 바인딩할 ViewModel 속성의 경로 (nameof 사용 권장)
/// </summary>
public string PropertyPath { get; }
/// <summary>
/// 값 변환기 타입 (선택사항)
/// </summary>
public System.Type ConverterType { get; }
/// <summary>
/// 바인딩 Attribute 생성자
/// </summary>
/// <param name="propertyPath">바인딩할 속성 경로 (nameof 사용 권장)</param>
/// <param name="converterType">값 변환기 타입 (선택사항)</param>
public BindToAttribute(string propertyPath, System.Type converterType = null)
{
PropertyPath = propertyPath;
ConverterType = converterType;
}
}
// /// <summary>
// /// 타입 안전한 바인딩 Attribute (제네릭 버전)
// /// 특정 ViewModel 타입에 대한 바인딩을 명시적으로 지정
// /// </summary>
// /// <typeparam name="TViewModel">바인딩할 ViewModel 타입</typeparam>
// [System.AttributeUsage(System.AttributeTargets.Field)]
// public class BindToAttribute<TViewModel> : System.Attribute where TViewModel : class
// {
// /// <summary>
// /// 바인딩할 ViewModel 속성의 경로
// /// </summary>
// public string PropertyPath { get; }
//
// /// <summary>
// /// 값 변환기 타입 (선택사항)
// /// </summary>
// public System.Type ConverterType { get; }
//
// /// <summary>
// /// 타입 안전한 바인딩 Attribute 생성자
// /// </summary>
// /// <param name="propertyPath">바인딩할 속성 경로</param>
// /// <param name="converterType">값 변환기 타입 (선택사항)</param>
// public BindToAttribute(string propertyPath, System.Type converterType = null)
// {
// PropertyPath = propertyPath;
// ConverterType = converterType;
// }
// }
/// <summary>
/// 컬렉션 바인딩을 위한 Attribute
/// 동적으로 생성되는 UI 요소들을 컬렉션에 바인딩
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field)]
public class BindCollectionAttribute : System.Attribute
{
/// <summary>
/// 바인딩할 컬렉션 속성의 경로
/// </summary>
public string PropertyPath { get; }
/// <summary>
/// 아이템 프리팹의 필드명 또는 속성명
/// </summary>
public string ItemPrefabReference { get; }
/// <summary>
/// 컬렉션 바인딩 Attribute 생성자
/// </summary>
/// <param name="propertyPath">바인딩할 컬렉션 속성 경로</param>
/// <param name="itemPrefabReference">아이템 프리팹 참조</param>
public BindCollectionAttribute(string propertyPath, string itemPrefabReference = null)
{
PropertyPath = propertyPath;
ItemPrefabReference = itemPrefabReference;
}
}
/// <summary>
/// 커맨드 바인딩을 위한 Attribute
/// 버튼 클릭 등의 이벤트를 ViewModel 메서드에 바인딩
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field)]
public class BindCommandAttribute : System.Attribute
{
/// <summary>
/// 바인딩할 ViewModel 메서드 이름
/// </summary>
public string MethodName { get; }
/// <summary>
/// 커맨드 바인딩 Attribute 생성자
/// </summary>
/// <param name="methodName">바인딩할 메서드 이름</param>
public BindCommandAttribute(string methodName)
{
MethodName = methodName;
}
}
}