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

  • 相关阅读:
    安卓系统浏览器中select下拉按钮无法弹出选择面板奇怪问题解决
    Webkit浏览器点击控件时出现的边框消除
    UML序列图总结
    UML序列图总结
    UML类图几种关系的总结
    UML类图几种关系的总结
    UML用例图总结
    UML用例图总结
    类与类之间的关系
    java核心技术----Object类
  • 原文地址:https://www.cnblogs.com/noigel/p/14029474.html
Copyright © 2011-2022 走看看