C#高级语法 Attribute特性详解和类型,方法,变量附加特性讲解

前言

Attribute特性是一种高级的语法,在C#和Java中用的比较多。如果你想要了解特性,就需要先了解反射。

相关资料

【C#进阶】C# 特性

C# 官方文档 创建自定义特性

C# 官方文档 使用反射访问特性

C#基础教程 Attribute 特性与反射案例详解,自动化识别与使用类型!

C#基础教程 Reflection应用,简单使用反射,打破常规!

Attribute特性

Attribute是一个简单的语法,一般来说都是放在类/变量/函数的前面,当然也可以放在参数里面。不过我们这里主要讨论常用的三种情况:

  • 变量
  • 方法

个人原理理解

找到带有Attribute特性的类
Assembly程序集,存放所有的编译信息
所有的Class类名
带有Attribute特性的类
Type
Attribute特性
...等等
MethodInfo方法属性
Attribute
PropertyInfo变量属性

特性的声明与使用

【C#进阶】C# 特性

在这里插入图片描述

简单的特性声明

namespace NetCore.Models
{

    /// <summary>
    /// 特性需要以MyAttributeTestAttribute结尾,这个是约定
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    
    public class MyAttributeTestAttribute:Attribute
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public MyAttributeTestAttribute(string name) {
            Name = name;
        }

        public MyAttributeTestAttribute()
        {


        }
    }
}

在这里插入图片描述

为了方便后面的讲解,我们这里声明三个特性

namespace NetCore.Models
{
    /// <summary>
    /// 类型特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class MyClassAttribute:Attribute
    {
        public string Name { get; set; }
        public MyClassAttribute(string name) {
            Name = name;
        }
        public MyClassAttribute() { }
    }
}


namespace NetCore.Models
{
    /// <summary>
    /// 方法特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class MyMethodAttribute:Attribute
    {
        public string Name { get; set; }

        public MyMethodAttribute(string name) {
            Name = name;
        }
        public MyMethodAttribute() { }
    }
}

namespace NetCore.Models
{
    /// <summary>
    /// 参数特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class MyPropertyAttribute:Attribute
    {
        public string Name { get; set; }
        public MyPropertyAttribute(string name) {
            Name = name;
        }
		public MyPropertyAttribute() { }
    }
}


类型特性

我们声明三个类,去获取这三个类的MyClass特性
其它两个设置差不多

在这里插入图片描述
在这里插入图片描述

  static void Main(string[] args)
 {
     var list = GetAllTypes<MyClassAttribute>();
     for (var i = 0; i < list.Count; i++)
     {
         Console.WriteLine($"ClassName:[{list[i].Name}],Attribute.Name[{GetAttribute<MyClassAttribute>(list[i]).Name}]");
     }
     Console.WriteLine("运行完成!");
     Console.ReadKey();
 }

 /// <summary>
 /// 获取所有有T特性的类型
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static List<Type> GetAllTypes<T>() where T : Attribute
 {
     var res = new List<Type>();
     //Assembly存放所有的程序集
     res = Assembly.GetExecutingAssembly()
         .GetTypes()
         .Where(t => t.GetCustomAttributes(typeof(T), false).Any())//我们找到所有程序集中带有T特性的Type类型
         .ToList();
     return res;
 }
 /// <summary>
 /// 获取
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="model"></param>
 /// <returns></returns>
 public static T GetAttribute<T>(Type model) where T : Attribute, new()
 {
     var res = new T();
     res = model.GetCustomAttribute<T>();
     return res;
 }

运行结果:

在这里插入图片描述

找到类的Attribute属性

如果只是找到带有Attribute的属性,那么意义就不大了,那么目前就只有一个标记的功能。这里我们将对应Attribute属性取到

 static void Main(string[] args)
 {
     var list = GetAllTypes<MyClassAttribute>();
     for (var i = 0; i < list.Count; i++)
     {
         Console.WriteLine($"ClassName:[{list[i].Name}],Attribute.Name[{GetAttribute<MyClassAttribute>(list[i]).Name}]");
     }
     Console.WriteLine("运行完成!");
     Console.ReadKey();
 }

 /// <summary>
 /// 获取所有有T特性的类型
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static List<Type> GetAllTypes<T>() where T : Attribute
 {
     var res = new List<Type>();
     //Assembly存放所有的程序集
     res = Assembly.GetExecutingAssembly()
         .GetTypes()
         .Where(t => t.GetCustomAttributes(typeof(T), false).Any())//我们找到所有程序集中带有T特性的Type类型
         .ToList();
     return res;
 }
 /// <summary>
 /// 获取
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="model"></param>
 /// <returns></returns>
 public static T GetAttribute<T>(Type model) where T : Attribute, new()
 {
     var res = new T();
     res = model.GetCustomAttribute<T>();
     return res;
 }

在这里插入图片描述

方法特性和变量特性

现在会了类型特性,那么方法特性和变量特性也差不多了。我们这里直接将对应的代码封装一下

代码封装

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace NetCore.Utils
{
    public static class MyAttributeHelper
    {

        /// <summary>
        /// 获取该类型下所有的带Attribute的方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <returns></returns>
        public static List<MethodInfo> GetAllMethods<T>(Type type) where T : class, new()
        {
            var res = new List<MethodInfo>();
            res = type.GetMethods().Where(t => t.GetCustomAttributes(typeof(T), false).Any()).ToList();
            return res;
        }

        /// <summary>
        /// 获取该类型下所有的带Attribute的属性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <returns></returns>
        public static List<PropertyInfo> GetAllPropertys<T>(Type type) where T : class, new()
        {
            var res = new List<PropertyInfo>();
            res = type.GetProperties().Where(t => t.GetCustomAttributes(typeof(T), false).Any()).ToList();
            return res;
        }
        /// <summary>
        /// 获取程序集所有有T特性的类型class
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static List<Type> GetAllTypes<T>() where T : Attribute
        {
            var res = new List<Type>();
            //Assembly存放所有的程序集
            res = Assembly.GetExecutingAssembly()
                .GetTypes()
                .Where(t => t.GetCustomAttributes(typeof(T), false).Any())//我们找到所有程序集中带有T特性的Type类型
                .ToList();
            return res;
        }
        /// <summary>
        /// 获取特性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public static T GetAttribute<T>(Type type) where T : Attribute, new()
        {
            var res = new T();
            res = type.GetCustomAttribute<T>();
            return res;
        }

        /// <summary>
        /// 获取特性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public static T GetAttribute<T>(MethodInfo type) where T : Attribute, new()
        {
            var res = new T();
            res = type.GetCustomAttribute<T>();
            return res;
        }

        /// <summary>
        /// 获取特性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public static T GetAttribute<T>(PropertyInfo type) where T : Attribute, new()
        {
            var res = new T();
            res = type.GetCustomAttribute<T>();
            return res;
        }
    }
}

测试类

TestService1

namespace NetCore.Services
{
    [MyClass("TestServiceAttribute1")]
    public class TestService1
    {

        [MyProperty("TestService1的Property")]
        public string Name { get; set; }

        public int Id { get; set; }

        [MyMethod("TestService1的Method")]
        public void Test()
        {

        }

        public void Send()
        {

        }
    }
}
TestService2
using NetCore.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NetCore.Services
{
    [MyClass("TestServiceAttribute2")]
    public class TestService2
    {
    }
}

TestService3
using NetCore.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NetCore.Services
{
    [MyClass("TestServiceAttribute3")]
    public class TestService3
    {
    }
}

测试代码


        static void Main(string[] args)
        {
            //找到所有带MyClassAttribute特性的类
            var list = MyAttributeHelper.GetAllTypes<MyClassAttribute>();
            for (var i = 0; i < list.Count; i++)
            {
                Console.WriteLine($"ClassName:[{list[i].Name}],Attribute.Name[{MyAttributeHelper.GetAttribute<MyClassAttribute>(list[i]).Name}]");
                //找到所有带MyMethodAttribute的方法
                var methods = MyAttributeHelper.GetAllMethods<MyMethodAttribute>(list[i]);
                //找到所有带MyPropertyAttribute的方法
                var propertis = MyAttributeHelper.GetAllPropertys<MyPropertyAttribute>(list[i]);

                //对代码进行打印
                foreach (var item in methods)
                {
                    var att = MyAttributeHelper.GetAttribute<MyMethodAttribute>(item);
                    Console.WriteLine($"ClassName:[{list[i].Name}],Method:[{item.Name}],Attribute.Name[{att.Name}]");
                }
                foreach (var item in propertis)
                {
                    var att = MyAttributeHelper.GetAttribute<MyPropertyAttribute>(item);

                    Console.WriteLine($"ClassName:[{list[i].Name}],Property:[{item.Name}],Attribute.Name[{att.Name}]");
                }
            }
            Console.WriteLine("运行完成!");
            Console.ReadKey();
        }

运行结果

在这里插入图片描述

对封装的代码进行优化

我们获取带有Attribute的类的时候,肯定希望一个函数直接返回两个结果:

  • Type:那个带Attribute的类
  • Attribute:Attribute本身的属性

一个函数返回多个变量有许多种解决方案,我这里觉得使用ValueTuple更加的合适。

C# 元祖,最佳的临时变量。

封装代码

......其它代码
 /// <summary>
 /// 返回带有Attribute的类型元祖列表
 /// </summary>
 /// <typeparam name="Att"></typeparam>
 /// <returns></returns>
 public static List<(Type type, Att att)> GetAll_TypeAndAtt<Att>() where Att : Attribute, new()
 {
     var res = new List<(Type type, Att att)> ();
     var typeLists = GetAllTypes<Att>();
     foreach (var item in typeLists)
     {
         var att = GetAttribute<Att>(item);
         res.Add((item, att));   
     }
     return res;
 }

 /// <summary>
 /// 返回带有Attribute的变量元祖列表
 /// </summary>
 /// <typeparam name="Att"></typeparam>
 /// <param name="type"></param>
 /// <returns></returns>
 public static List<(PropertyInfo property, Att att)> GetAll_PropertyAndAtt<Att>(Type type) where Att : Attribute, new()
 {
     var res = new List<(PropertyInfo type, Att att)>();
     var typeLists = GetAllPropertys<Att>(type);
     foreach (var item in typeLists)
     {
         var att = GetAttribute<Att>(item);
         res.Add((item, att));
     }
     return res;
 }

 /// <summary>
 /// 返回带有Attribute的方法元祖列表
 /// </summary>
 /// <typeparam name="Att"></typeparam>
 /// <param name="type"></param>
 /// <returns></returns>
 public static List<(MethodInfo method, Att att)> GetAll_MethodAndAtt<Att>(Type type) where Att : Attribute, new()
 {
     var res = new List<(MethodInfo type, Att att)>();
     var typeLists = GetAllMethods<Att>(type);
     foreach (var item in typeLists)
     {
         var att = GetAttribute<Att>(item);
         res.Add((item, att));
     }
     return res;
 }

测试代码


            var lists = MyAttributeHelper.GetAll_TypeAndAtt<MyClassAttribute>();
            lists.ForEach(item1 =>
            {
                Console.WriteLine($"ClassName:[{item1.type.Name}],Attribute.Name[{item1.att.Name}]");
                var methods = MyAttributeHelper.GetAll_MethodAndAtt<MyMethodAttribute>(item1.type);
                var properties = MyAttributeHelper.GetAll_PropertyAndAtt<MyPropertyAttribute>(item1.type);
                methods.ForEach(item2 => { Console.WriteLine($"ClassName:[{item1.type.Name}],Method:[{item2.method.Name}],Attribute.Name[{item2.att.Name}]"); });
                properties.ForEach(item2 => { Console.WriteLine($"ClassName:[{item1.type.Name}],Method:[{item2.property.Name}],Attribute.Name[{item2.att.Name}]"); });

            });

运行结果(和上次的一致)

在这里插入图片描述

最后封装好的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace NetCore.Utils
{
    public static class MyAttributeHelper
    {

        /// <summary>
        /// 获取该类型下所有的带Attribute的方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <returns></returns>
        public static List<MethodInfo> GetAllMethods<T>(Type type) where T : class, new()
        {
            var res = new List<MethodInfo>();
            res = type.GetMethods().Where(t => t.GetCustomAttributes(typeof(T), false).Any()).ToList();
            return res;
        }

        /// <summary>
        /// 获取该类型下所有的带Attribute的属性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <returns></returns>
        public static List<PropertyInfo> GetAllPropertys<T>(Type type) where T : class, new()
        {
            var res = new List<PropertyInfo>();
            res = type.GetProperties().Where(t => t.GetCustomAttributes(typeof(T), false).Any()).ToList();
            return res;
        }
        /// <summary>
        /// 获取程序集所有有T特性的类型class
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static List<Type> GetAllTypes<T>() where T : Attribute
        {
            var res = new List<Type>();
            //Assembly存放所有的程序集
            res = Assembly.GetExecutingAssembly()
                .GetTypes()
                .Where(t => t.GetCustomAttributes(typeof(T), false).Any())//我们找到所有程序集中带有T特性的Type类型
                .ToList();
            return res;
        }
        /// <summary>
        /// 获取特性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public static T GetAttribute<T>(Type type) where T : Attribute, new()
        {
            var res = new T();
            res = type.GetCustomAttribute<T>();
            return res;
        }

        /// <summary>
        /// 获取特性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public static T GetAttribute<T>(MethodInfo type) where T : Attribute, new()
        {
            var res = new T();
            res = type.GetCustomAttribute<T>();
            return res;
        }

        /// <summary>
        /// 获取特性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        public static T GetAttribute<T>(PropertyInfo type) where T : Attribute, new()
        {
            var res = new T();
            res = type.GetCustomAttribute<T>();
            return res;
        }

        /// <summary>
        /// 返回带有Attribute的类型元祖列表
        /// </summary>
        /// <typeparam name="Att"></typeparam>
        /// <returns></returns>
        public static List<(Type type, Att att)> GetAll_TypeAndAtt<Att>() where Att : Attribute, new()
        {
            var res = new List<(Type type, Att att)> ();
            var typeLists = GetAllTypes<Att>();
            foreach (var item in typeLists)
            {
                var att = GetAttribute<Att>(item);
                res.Add((item, att));   
            }
            return res;
        }

        /// <summary>
        /// 返回带有Attribute的变量元祖列表
        /// </summary>
        /// <typeparam name="Att"></typeparam>
        /// <param name="type"></param>
        /// <returns></returns>
        public static List<(PropertyInfo property, Att att)> GetAll_PropertyAndAtt<Att>(Type type) where Att : Attribute, new()
        {
            var res = new List<(PropertyInfo type, Att att)>();
            var typeLists = GetAllPropertys<Att>(type);
            foreach (var item in typeLists)
            {
                var att = GetAttribute<Att>(item);
                res.Add((item, att));
            }
            return res;
        }

        /// <summary>
        /// 返回带有Attribute的方法元祖列表
        /// </summary>
        /// <typeparam name="Att"></typeparam>
        /// <param name="type"></param>
        /// <returns></returns>
        public static List<(MethodInfo method, Att att)> GetAll_MethodAndAtt<Att>(Type type) where Att : Attribute, new()
        {
            var res = new List<(MethodInfo type, Att att)>();
            var typeLists = GetAllMethods<Att>(type);
            foreach (var item in typeLists)
            {
                var att = GetAttribute<Att>(item);
                res.Add((item, att));
            }
            return res;
        }
    }
}

总结

Attribute是C# 的高级语法,使用范围很广,可以极大的简化我们需要运行代码。本篇文章只是讲解了如何拿到特性属性,如果我们需要深入解决,那么就需要深入了解反射的使用方法。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/305529.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

C#,入门教程(13)——字符(char)及字符串(string)的基础知识

上一篇&#xff1a; C#&#xff0c;入门教程(12)——数组及数组使用的基础知识https://blog.csdn.net/beijinghorn/article/details/123918227 字符串的使用与操作是必需掌握得滚瓜烂熟的编程技能之一&#xff01;&#xff01;&#xff01;&#xff01;&#xff01; C#语言实…

POSIX API与网络协议栈

本文介绍linux中与tcp网络通信相关的POSIX API&#xff0c;在每次调用的时候&#xff0c;网络协议栈会进行的操作与记录。 POSIX API Posix API&#xff0c;提供了统一的接口&#xff0c;使程序能得以在不同的系统上运行。简单来说不同的操作系统进行同一个活动&#xff0c;比…

浅析ARMv8体系结构:A64指令集

文章目录 A64指令编码格式加载与存储指令寻址模式变基模式前变基模式后变基模式 PC相对地址模式 伪指令加载与存储指令的变种不同位宽的加载与存储指令多字节内存加载和存储指令基地址偏移量模式前变基模式后变基模式 跳转指令返回指令比较并跳转指令 其它指令内存独占访问指令…

资产信息管理系统-前后端开发

题目要求&#xff1a; 资产管理系统 利用H5规范&#xff0c;CSS样式与JS脚本独立于HTML页面&#xff0c;Javascript调用jQuery库&#xff0c;CRUD后端使用FastAPI封装&#xff0c;前端页面在Nginx中运行&#xff0c;调用API模块&#xff0c; 实现CURD的课设总结 基本设计&am…

增强Wi-Fi信号的10种方法,值得去尝试

Wi-Fi信号丢失,无线盲区。在一个对一些人来说,上网和呼吸一样必要的世界里,这些问题中的每一个都令人抓狂。 如果你觉得你的Wi-Fi变得迟钝,有很多工具可以用来测试你的互联网速度。你还可以尝试一些技巧来解决网络问题。然而,如果你能获得良好接收的唯一方法是站在无线路…

nginx部署前端项目自动化脚本

文章目录 配置入口服务器nginx的conf.d使用docker创建一个nginx配置自动化脚本 前言 将项目 通过nginx 部署到 新的服务器 通过nginx反向代理出去 配置入口服务器nginx的conf.d 一般在这个文件夹下 找不到使用 find / -name nginx 2>/dev/null 找到nginx 的位置如果有些没有…

PostGIS教程学习十九:基于索引的聚簇

PostGIS教程学习十九&#xff1a;基于索引的聚簇 数据库只能以从磁盘获取信息的速度检索信息。小型数据库将完全位于于RAM缓存&#xff08;内存&#xff09;&#xff0c;并摆脱物理磁盘访问速度慢的限制。但是对于大型数据库&#xff0c;对物理磁盘的访问将限制数据库的信息检…

正则表达式的语法

如果要想灵活的运用正则表达式&#xff0c;必须了解其中各种元素字符的功能&#xff0c;元字符从功能上大致分为&#xff1a; 限定符 选择匹配符 分组组合和反向引用符 特殊字符 字符匹配符 定位符 我们先说一下元字符的转义号 元字符(Metacharacter)-转义号 \\ \\ 符号…

【Matplotlib】基础设置之图形组合07

figures, subplots, axes 和 ticks 对象 figures, axes 和 ticks 的关系 这些对象的关系可以用下面的图来表示&#xff1a; 示例图像&#xff1a; 具体结构&#xff1a; figure 对象 figure 对象是最外层的绘图单位&#xff0c;默认是以 1 开始编号&#xff08;MATLAB 风格…

Mysql 数据库ERROR 1820 (HY000): You must reset your password using ALTER USER 解决办法

Mysql 5.7数据库原来一直都能正常访问&#xff0c;突然访问不了&#xff0c;查看日志提示数据库需要修改密码&#xff0c; 具体解决办法如下操作&#xff1a; Windows 下&#xff1a; mysql的bin目录下&#xff0c; mysql>use mysql; mysql>mysql -uroot -p密码; 判…

[前车之鉴] SpringBoot原生使用Hikari数据连接池升级到动态多数据源的深坑解决方案 RocketMQ吞掉异常问题排查

文章目录 背景说明蒙蔽双眼口说无凭修补引发的新问题解决配置问题 本地监控佐证万法归元 背景说明 当前业务场景我们使用原生SpringBoot整合Hikari数据源连接池提供服务&#xff0c;但是近期业务迭代需要使用动态多数据源&#xff0c;很自然想到dynamic-source&#xff0c;结果…

windows下全免费手动搭建php8+mysql8开发环境及可视化工具安装

最近PHP项目少了&#xff0c;一直在研究UE5和Golang&#xff0c;但是考虑到政府、国企未来几年国产化的要求&#xff0c;可能又要重拾PHP。于是近日把用了N年的框架重新更新至适合PHP8.2以上的版本&#xff0c;同时也乘着新装机&#xff0c;再次搭建php和mysql开发环境。本文留…

Java18:网络编程

一.对象序列化&#xff1a; 1.对象流&#xff1a; ObjectInputStream 和 ObjectOutputStream 2.作用&#xff1a; ObjectOutputSteam&#xff1a;内存中的对象-->存储中的文件&#xff0c;通过网络传输出去 ObjectInputStream:存储中的文件&#xff0c;通过网络传输出去…

LeetCode-数组-双指针-中等难度

文章目录 双指针1. 删除有序数组中的重复项&#xff08;入门&#xff09;1.1 题目描述1.2 解题思路1.3 代码实现 2. 删除有序数组中的重复项 II&#xff08;简单&#xff09;2.1 题目描述2.2 解题思路2.3 代码实现 3. 移动零&#xff08;简单&#xff09;3.1 题目描述3.2 代码实…

SpringCloud系列篇:核心组件之网关组件

&#x1f973;&#x1f973;Welcome Huihuis Code World ! !&#x1f973;&#x1f973; 接下来看看由辉辉所写的关于SpringCloud的相关操作吧 目录 &#x1f973;&#x1f973;Welcome Huihuis Code World ! !&#x1f973;&#x1f973; 一.网关组件是什么 二. 网关组件的…

The Sandbox 2024 Game Jam 启动|向博姆库斯博士证明你的游戏开发实力!

The Sandbox Game Jam 是面向所有游戏制作爱好者的创作比赛&#xff01;我们诚邀您加入 The Sandbox 的生态系统&#xff0c;这里充满活力&#xff0c;游戏与文化相融&#xff0c;创作者彼此切磋&#xff0c;共同实现梦想。唯一能限制您的只有想象力。The Sandbox 游戏由大家共…

控制台项目和ASP.Net Core 1.项目创建 2.一键启动多个服务 3.引入别的库

感悟&#xff1a; 1.注意选择&#xff1a;.NET/.Net Core下面的控制台或者ASP.NET Core web应用&#xff0c;而且只有.net core的项目是跨平台的&#xff0c;选错的话&#xff0c;是无法发布到linux上的。 2.c#的命名空间和java包的区别&#xff1a; c#中是按照包来的&#x…

使用Django框架自带的Form表单完成简单的用户登录注册

如果不知道怎么配置Django环境以及如何连接数据库请点击我的上一篇博客&#xff1a; 使用pycharm初始化Django框架并连接Sql Server 文章目录 1.Django默认生成的数据表2.用户登录2.1创建登录页面2.2视图处理登录请求2.3配置访问路径 3.用户注册3.1创建用户表单3.2创建注册模版…

linux系统基础知识-基础IO

IO 概念引入位图的概念IO的系统调用函数openwriteread()close简单使用样例&#xff1a; 文件描述符fd默认文件流stdin/stdout/stderr文件描述符的分配规则 重定向的概念输出重定向输入重定向追加重定向dup2()系统调用总结 文件缓冲区深入理解缓冲区的概念输出缓冲区部分代码解释…

jmeter循环控制器

1.循环控制器 简单粗暴 写几次 循环几次 经常结合自定义变量使用 2.foreach控制器 搭配 变量一起使用的循环 一般变量的值是一个集合或者 是2个及2个以上的内容
最新文章