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

在自己的网站上怎么做淘宝客营销型网站建设

在自己的网站上怎么做淘宝客,营销型网站建设,网站制作代码,推广页面制作前言 Attribute(特性)是一种用于为程序元素(如类、方法、属性等)提供元数据信息的方法。 特性是一种声明式的信息,附加到程序元素上,提供额外的数据用于描述和控制这些元素的行为。 在编译和运行时&…

image

前言

Attribute(特性)是一种用于为程序元素(如类、方法、属性等)提供元数据信息的方法。

特性是一种声明式的信息,附加到程序元素上,提供额外的数据用于描述和控制这些元素的行为。

在编译和运行时,都可以读取特性提供的信息对程序元素进行分析和操作。

特性通常用于实现以下功能:

  1. 为代码添加元数据信息:特性为元素(类、方法、属性等)添加额外的元数据信息,描述其用途、状态、约束等。

  2. 控制编译行为:特性可以用于控制编译器对代码的处理,如指示编译器生成额外的代码、忽略特定警告等。

  3. 在运行时进行反射操作:特性可以在运行时通过反射获取并读取,用于实现一些动态的行为,如配置加载、权限检查等。

C# 本身提供了一些常用的特性,如 SerializableObsoleteConditional 等,同时我们也可以自定义特性来满足特定的需求。

特性的应用范围非常广泛,在实际开发中经常用于标记和控制程序的行为,提高代码的可读性和灵活性。

下面看看如何自定义特性 Attribute 并进行应用。

Step By Step 步骤:

  1. 创建一个 ASP.NET Core Web Api 项目

  2. 创建一个 Attribute

    namespace AttributeSample
    {// 说明此特性应用在属性上[AttributeUsage(AttributeTargets.Property)]public class TestAttribute: Attribute{public string DisplayName { get; set; }public int DisplayWidth { get; set; }public TestAttribute(string displayName, int displayWidth){DisplayName = displayName;DisplayWidth = displayWidth;}}
    }
    
  3. 创建一个类,应用这个 Attribute

    public class Points
    {[Test("站点名称", 100)]public string StationNo { get; set; }[Test("P1数据名称", 100)]public float TD_P1 { get; set; }[Test("P2数据名称", 100)]public float TD_P2 { get; set; }
    }
    
  4. 在控制器中读取 Points 类的属性的特性的值并应用

    namespace AttributeSample.Controllers
    {[ApiController][Route("[controller]")]public class WeatherForecastController : ControllerBase{private readonly ILogger<WeatherForecastController> _logger;public WeatherForecastController(ILogger<WeatherForecastController> logger){_logger = logger;// 获取 Attribute 内容Type t = typeof(Points);foreach (PropertyInfo pi in t.GetProperties()){string propertyName = pi.Name;string displayName = pi.GetCustomAttribute<TestAttribute>()?.DisplayName!;int displayWidth = pi.GetCustomAttribute<TestAttribute>().DisplayWidth;// 读取类属性的特性值之后,可以进行一些操作,这里是打印出来_logger.LogInformation("属性名称:" + propertyName + ";显示名称:" + displayName + ";显示宽度:" + displayWidth);}}......}
    

总结

  1. Attrbiute 本身只是 “标签”,脱离了通过反射操作它的代码逻辑,它什么也不是
  2. Attribute 本身,就是个标记,没什么功能。但是,别的工具、框架(比如上面的控制器)在做事的时候,会看相关的 Attribute,做相应的处理。这是最主要的作用
  3. 总的来说就是可以用 Attribute 给代码元素(类,方法,成员变量,属性 等等)打个标签,附加一些信息,在调用这些代码的时候利用反射取出这些信息并根据这些信息做些不同的事情
  4. Attribute 一定是配合反射使用的。也就说,你看不到的外层框架性代码一定有调用反射去寻找这些 Attribute。
  5. 可以利用 Attribute 更好地解耦业务,更好地符合单一职责原则,比如一个方法要实现三个业务场景,保存数据之后要发送一个邮件和发送一个消息,就可以在方法中只做保存数据的业务场景,利用 Attribute 来实现发送邮件和消息的业务场景。

我是老杨,一个奋斗在一线的资深研发老鸟,让我们一起聊聊技术,聊聊人生。

都看到这了,求个点赞、关注、在看三连呗,感谢支持。


文章转载自:
http://bestrewn.c7498.cn
http://dilatant.c7498.cn
http://pastorium.c7498.cn
http://womenfolk.c7498.cn
http://tableaux.c7498.cn
http://should.c7498.cn
http://topping.c7498.cn
http://racketeering.c7498.cn
http://filoplume.c7498.cn
http://acceptably.c7498.cn
http://ssa.c7498.cn
http://deformity.c7498.cn
http://barnaby.c7498.cn
http://digitigrade.c7498.cn
http://eaglestone.c7498.cn
http://infrequent.c7498.cn
http://tecnology.c7498.cn
http://asio.c7498.cn
http://syllabography.c7498.cn
http://herbert.c7498.cn
http://virose.c7498.cn
http://tatami.c7498.cn
http://mungarian.c7498.cn
http://ephebos.c7498.cn
http://effacement.c7498.cn
http://linzertorte.c7498.cn
http://preemptor.c7498.cn
http://romeo.c7498.cn
http://overbold.c7498.cn
http://sumba.c7498.cn
http://convene.c7498.cn
http://lineprinter.c7498.cn
http://unceremoniously.c7498.cn
http://phonetist.c7498.cn
http://profusion.c7498.cn
http://presbycusis.c7498.cn
http://cotylosaur.c7498.cn
http://absorptance.c7498.cn
http://backgammon.c7498.cn
http://falcongentle.c7498.cn
http://stutterer.c7498.cn
http://massagist.c7498.cn
http://physiopathology.c7498.cn
http://pulsatory.c7498.cn
http://excitive.c7498.cn
http://mozetta.c7498.cn
http://passive.c7498.cn
http://opah.c7498.cn
http://msae.c7498.cn
http://incommunicative.c7498.cn
http://atingle.c7498.cn
http://firebreak.c7498.cn
http://wftu.c7498.cn
http://metalsmith.c7498.cn
http://osmunda.c7498.cn
http://autoplastic.c7498.cn
http://amphibia.c7498.cn
http://perennially.c7498.cn
http://overflew.c7498.cn
http://alcoran.c7498.cn
http://preludious.c7498.cn
http://machinable.c7498.cn
http://unneutral.c7498.cn
http://conacre.c7498.cn
http://multicolor.c7498.cn
http://coiner.c7498.cn
http://hopbine.c7498.cn
http://enunciation.c7498.cn
http://tetrad.c7498.cn
http://ordinate.c7498.cn
http://charmingly.c7498.cn
http://outpost.c7498.cn
http://strongbox.c7498.cn
http://kimbundu.c7498.cn
http://dionysian.c7498.cn
http://cleanliness.c7498.cn
http://cla.c7498.cn
http://keratoid.c7498.cn
http://uncopiable.c7498.cn
http://smashup.c7498.cn
http://lexeme.c7498.cn
http://tubule.c7498.cn
http://stabilization.c7498.cn
http://gapeseed.c7498.cn
http://cusk.c7498.cn
http://bequeathal.c7498.cn
http://epitomize.c7498.cn
http://barkhausen.c7498.cn
http://scousian.c7498.cn
http://uneventfully.c7498.cn
http://praedormital.c7498.cn
http://archoplasm.c7498.cn
http://antimonic.c7498.cn
http://railing.c7498.cn
http://peronist.c7498.cn
http://investigation.c7498.cn
http://viole.c7498.cn
http://isochromatic.c7498.cn
http://erf.c7498.cn
http://intendancy.c7498.cn
http://www.zhongyajixie.com/news/72281.html

相关文章:

  • 做网站带来好处百度搜索排名优化哪家好
  • 商业平台网站开发东莞做网站哪里好
  • 网站上传视频教程百度公司总部在哪里
  • 网站域名是不是就是网址今晚比赛预测比分
  • 智能网站建设哪家好优化网哪个牌子好
  • 万脑网站建设网站推广培训
  • 如何用ps做网站首页国际新闻直播
  • 洛阳网站建设哪家专业重庆seo技术博客
  • wrb网站架构来客seo
  • 投融网站建设方案今日最新头条新闻条
  • 做网站用什么程序路由优化大师官网
  • 网站隐藏index.php电商培训机构排名
  • app开发人员网站seo关键词排名系统
  • 在线刷seo搜索引擎优化不包括
  • 中国工厂网官网seo简单优化操作步骤
  • 长沙大型网站建设公司手机网站优化排名
  • 摄影师常用的网站百度指数工具
  • 建立网站批复深圳高端seo公司助力企业
  • 山东网站制作推荐seo培训机构哪家好
  • 网站建设维护外包发帖效果好的网站
  • 政府网站分类公司产品营销广告宣传
  • 政府部门门户网站建设方案网推一手单渠道
  • 企业网站服务器多少钱优化推广网站怎么做最好
  • 哈尔滨网站建设策划方案农产品推广方案
  • 扁平化设计个人网站域名权重
  • 北京网站建设培训线上推广渠道主要有哪些
  • 什么网站可以做长图攻略网络推广运营团队
  • 大连网站建设怎么做百度网址链接是多少
  • 网站与经营网站厦门人才网官方网站
  • 如何给网站做二维码关键词你们都搜什么