当前位置: 首页 > news >正文

宾县建设局网站网站为何不显示百度商桥对话框

宾县建设局网站,网站为何不显示百度商桥对话框,wordpress商城主题模板,wordpress中调用文章内容在C#中,特性(Attribute)是一种用于向代码元素(如类、方法、属性等)添加元数据的机制。特性本身不会直接影响代码的执行,但它们可以提供额外的信息,这些信息可以在运行时通过反射(Ref…

        在C#中,特性(Attribute)是一种用于向代码元素(如类、方法、属性等)添加元数据的机制。特性本身不会直接影响代码的执行,但它们可以提供额外的信息,这些信息可以在运行时通过反射(Reflection)来读取和使用。

用法:

一、描述

using System;[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class DescriptionAttribute : Attribute
{public string Description { get; set; }public DescriptionAttribute(string description){Description = description;}
}
[DescriptionAttribute("描述特性") ]//Attribute允许省略
public class Test
{}public class Program
{public static void Main(string[] args){Type type= typeof(Test);object[] attributes = type.GetCustomAttributes(typeof(DescriptionAttribute), false);if(attributes.Length > 0){DescriptionAttribute descriptionAttribute= (DescriptionAttribute)attributes[0];Console.WriteLine(descriptionAttribute.Description);//会输出文字:描述特性}Console.Read();}
}

二、标记过时方法

using System;public class Program
{[Obsolete("该方法已过时")]public static void ObsoleteMethod(){}public static void Main(string[] args){ObsoleteMethod();Console.Read();}
}

三、控制序列化

using System;
using System.IO;
using System.Xml.Serialization;[Serializable]
public class Test
{public string field1 = "";[XmlIgnore]public string field2 = "";
}public class Program
{public static void Main(string[] args){Test test;Test testDeserializer;XmlSerializer serializer;StringWriter writer;StringReader reader;test = new Test();test.field1 = "field1";test.field2 = "field2";serializer = new XmlSerializer(typeof(Test));writer = new StringWriter(); serializer.Serialize(writer, test);Console.WriteLine($"XML序列化结果:\n{writer}");reader = new StringReader(writer.ToString());testDeserializer = (Test)serializer.Deserialize(reader);Console.WriteLine($"XML反序列化结果:\nfield1:[{testDeserializer.field1}].field2:[{testDeserializer.field2}]" );Console.Read();}
}

四、自定义验证

using System;
using System.Reflection;[AttributeUsage(AttributeTargets.Property)]
public class RangeAttribute : Attribute
{public int Min { get; }public int Max { get; } public RangeAttribute(int min, int max){Min = min;Max = max;}   
}public class Test
{[Range(114,514)]public int Property1 {  get; set; }public  Test(int property1){Property1 = property1;}public bool ValidateProperty1(){MemberInfo property1 = typeof(Test).GetProperty("Property1");RangeAttribute rangeAttribute = (RangeAttribute)Attribute.GetCustomAttribute(property1, typeof(RangeAttribute));if (rangeAttribute != null){return Property1 >= rangeAttribute.Min && Property1 <= rangeAttribute.Max;}else{return true;}}
}public class Program
{public static void Main(string[] args){Test test1 = new Test(123);Test test2 = new Test(999);Console.WriteLine(test1.ValidateProperty1());Console.WriteLine(test2.ValidateProperty1());Console.Read();}
}

五、条件编译

#define Debug
using System;
using System.Diagnostics;public class Program
{[Conditional("Debug")]public static void Log(string message){Console.WriteLine(message);}public static void Main(string[] args){Log("Debug已定义");Console.Read();}
}

注释掉#define Debug代码,则执行不会输出“Debug已定义”。

http://www.dtcms.com/a/527367.html

相关文章:

  • pycharm 做网站网站开发培训心得
  • 哈尔滨网站域名归那里管如何知道网站是否被k
  • 免费在线做高考试题的网站做首饰网站
  • 网站服务器ipv6网站建设开发哪个好学
  • 寿光住房和城乡建设局网站浙江省工程信息网官网
  • 沈阳做微信和网站的公司新郑做网站
  • 网站接入服务提供商九一人才网赣州招聘官网
  • 状态管理名词解释网站开发织梦iis7搭建网站教程
  • 磁力链接 网站怎么做的公司企业邮箱管理制度
  • 做排行榜的网站网页设计颜色代码表
  • 教育网网站建设规范福田祥菱v3报价及图片
  • 家具网站设计方案舆情报告模板
  • 网站关键字工具做网站公司多少钱
  • 10大开源文档管理系统seo关键字优化技巧
  • 制作网站的步骤和过程网站后台教程
  • 保险网站排名seo 知乎
  • 网站建设备案审核要多久广告网站推荐
  • 无极任务平台网站进入门户网站源码入驻
  • 佛山网站设计网站公司买一个成品网站多少钱
  • 个人承包工程需要什么资质哪有培训seo
  • 北京建设网站公司推荐安徽省建设厅安全协会网站
  • 营销型网站模版wordpress like插件
  • wap网站搭建做食品的采购员常用网站
  • 建网站建设的基本流程门户网站开发工具软件
  • 东莞官方网站建设站长工具seo综合查询怎么用
  • 做网站审批号必须要upupw搭建wordpress
  • 沈阳网站制作企业临淄网站建设公司
  • 深圳网站seo优化排名公司wordpress 实现动画
  • 自己做网站和凡科的区别知知网站推荐
  • 丹阳企业网站wordpress 采集规则