zoukankan      html  css  js  c++  java
  • C# 知识点集锦(一)

    例子一:已知一个类有两个属性,打印属性名的代码如下。要求屏蔽某个属性。

    已知:

        class Program
        {
            static void Main(string[] args)
            {
                PropertyInfo [] info=new Test().GetType().GetProperties();
                foreach(PropertyInfo p in info)
                {
                    Console.WriteLine(p.Name);
                }
                Console.ReadLine();
    
            }
        }
    
        public class Test
        {
            public string One { get; set; }
            public string Two { get; set; }
    
        }
    }
    View Code

     解决方案:

        class Program
        {
            static void Main(string[] args)
            {
                PropertyInfo[] info = new Test().GetType().GetFilteredProperties();
                foreach(PropertyInfo p in info)
                {
                    Console.WriteLine(p.Name);
                }
                Console.ReadLine();
    
            }
        }
    
        public  class SkipPropertyAttribute : Attribute { }
        public static class TypeExtensions
        {
            public static PropertyInfo[] GetFilteredProperties(this Type type)
            {
                return type.GetProperties().Where(pi => pi.GetCustomAttributes(typeof(SkipPropertyAttribute), true).Length == 0).ToArray();
    
            }
        }
    
        public class Test
        {
            
            public string One { get; set; }
            [SkipProperty]
            public string Two { get; set; }
    
        }

     或者

            public static PropertyInfo[] GetFilteredProperties(this Type type)
            {
                return type.GetProperties()
          .Where(pi => !Attribute.IsDefined(pi, typeof(SkipPropertyAttribute)))
          .ToArray();
    
            }

     例子2:在XML中实现IF ELSE WHILE 等

    https://stackoverflow.com/questions/6061470/if-then-else-using-xml

    https://stackoverflow.com/questions/34653740/how-to-use-an-if-else-condition-in-a-sapui5-xml-view

    https://stackoverflow.com/questions/46630446/how-to-implement-while-like-loop-in-xslt

  • 相关阅读:
    jQuery .css("width")和.width()的区别
    用jquery写一个滑动TAB 例子
    D
    4 Values whose Sum is 0
    Hibernate学习之hql 与sql
    BigDecimal进行精确运算
    Date类与SimpleDateFormat类中parse()方法和format()方法
    单例模式下的懒汉和饿汉模式
    Java中Date类型详解
    Spring @Column的注解详解
  • 原文地址:https://www.cnblogs.com/noigel/p/14029474.html
Copyright © 2011-2022 走看看