ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [C#] Enum 변수를 추가 정의하여 사용하는 방법
    Programming/C# 2021. 7. 6. 23:26

     

    /// <summary>
        /// 상속구조를 통해 정의하는 방법
        /// </summary>
        public record InteractType
        {
            public static readonly InteractType Interact = new InteractType("Interact");
    
            public override string ToString()
            {
                return this.Value;
            }
    
            public InteractType(string value) => this.Value = value;
    
            public string Value { get; private set; }
    
    
        }
    
        public sealed record InteractTypeDerived : InteractType
        {
            public static readonly InteractType Breakable = new InteractType("interact");
    
            public InteractTypeDerived(string value) : base(value) { }
        }

     

    /// <summary>
        /// 해당 클래스 & 구조체를 분할해서 정의하는 방법
        /// </summary>
        internal partial struct InteractType
        {
            public static readonly InteractType Interact = new InteractType("Interact");
    
            public static bool operator ==(InteractType lhs, InteractType rhs) => lhs.Value.Equals(rhs.Value);
            public static bool operator !=(InteractType lhs, InteractType rhs) => !(lhs == rhs);
            public InteractType(in string value) => this.Value = value;
            public string Value { get; private set; }
    
            public override bool Equals(object obj)
            {
                return base.Equals(obj);
            }
            public override int GetHashCode()
            {
                return base.GetHashCode();
            }
            public override string ToString()
            {
                return base.ToString();
            }
        }
    
        internal partial struct InteractType
        {
            public static readonly InteractType Breakable = new InteractType("Breakable");
        }

     

     

    'Programming > C#' 카테고리의 다른 글

    [C#] Array, List, Dictionary 컬렉션 정리 겸 복습  (2) 2021.01.30
    [C#] 확장 메소드(this)  (0) 2020.10.11
    C# 자료형 정리  (0) 2020.02.17
Designed by Tistory.