zoukankan      html  css  js  c++  java
  • 知识点

     

     

    返回只读集合

            List<PaymentMethod> _paymentMethods;
            public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods.AsReadOnly();

    自定枚举

        public class CardType : SeedWrok.Enumeration
        {
            public static CardType Amex = new CardType(1, "Amex");
            public static CardType Visa = new CardType(2, "Visa");
            public static CardType MasterCard = new CardType(3, "MasterCard");
            public CardType(int id,string name) : base(id, name) { }
        }
    
        public abstract class Enumeration : IComparable
        {
            public string Name { get; private set; }
            public int Id { get; private set; }
            protected Enumeration(int id, string name)
            {
                Id = id;
                Name = name;
            }
            public override int GetHashCode() => Id.GetHashCode();
            public override bool Equals(object obj)
            {
                var temp = obj as Enumeration;
                if (temp == null)
                    return false;
                var typeMatch = GetType().Equals(temp.GetType());
                var valueMatch = temp.Id.Equals(Id);
                return typeMatch && valueMatch;
            }
            public int CompareTo(object obj) => Id.CompareTo(((Enumeration)obj).Id);
            public static IEnumerable<T> GetAll<T>() where T:Enumeration
            {
                var fields = typeof(T).GetFields();
                return fields.Select(s => s.GetValue(null)).Cast<T>();静态字段使用参数null,Cast转为相应强类型
            }
        }
    

      

  • 相关阅读:
    php+ajax文件上传
    安装ruby及sass
    大佬
    ES6--let,解构赋值,promise && ES7--async
    miniapp基础
    8月笔记
    webpack 打包html文件
    webpack压缩打包不成功
    nvm安装成功后,但命令不可用(command not found)
    jq库extend的区别
  • 原文地址:https://www.cnblogs.com/Celebrator/p/11364330.html
Copyright © 2011-2022 走看看