.NET Framework基础知识(五)(转载)

时间:2023-02-10 11:03:19
、程序集:是 .NET Framework 应用程序的构造块;程序集构成了部署、版本控制、重复使用、激活范围控制和

安全权限的基本单元。
、程序集的优点:版本控制问题、最终解决DLL冲突
、程序集分为两种:强命名程序集和弱命名程序集。
、.NET Framework 为开发全球通用的应用程序提供了广泛的支持。在开发全球通用的应用程序时, 建议将此过程分为三个步骤:全球化、本地化分析和本地化。
()全球化是全球通用应用程序创建过程的第一步。在这一步中将编写应用程序的可执行代码。 一个真正的全球化应用程序应是非特定区域性和非特定语言的。因此,应集中精力创建能够支持适用于所有用户的 本地化用户界面和区域数据的应用程序。注意,尽管全球化应用程序具有这种灵活性,但全球化过程本身并不涉及用户界面的翻译。 相反,应致力于使创建的应用程序具有对来自应用程序所支持的所有区域性和地区的用户均有效的功能。
()在继续进行本地化之前,应执行中间检查以确定应用程序的 本地化分析。如果应用程序可本地化, 说明已正确地将应用程序的可执行代码同其资源分开。如果正确地评估了应用程序的可本地化性,在本地化期间就 不需要修改应用程序的源代码。
()生成全球通用的应用程序的最后一步是 本地化,在这一步中,需要针对特定的区域性或地区自定义应用程序。 如果已正确执行了全球化和本地化分析这两个步骤,则本地化主要包括用户界面的翻译。
、设计和开发全球通用的应用程序有以下几个优点:
()全球范围的收入。
()可以迅速添加对新区域性的支持。
()使用资源的效率更高。
、System.Globalization 命名空间包含定义区域性相关信息的类,这些信息包括语言、国家/地区、 使用的日历、日期、货币和数字的格式模式以及字符串的排序顺序。我们可以使用这些类编写全球化(国际化)应用程序。
、并行编程:许多个人计算机和工作站都有两个或四个内核(即 CPU),使多个线程能够同时执行。 在不久的将来,计算机预期会有更多的内核。 为了利用当今和未来的硬件,您可以对代码进行并行化,以将工作分摊在多个处理器上。 、特性、反射、泛型综合实例 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters.Soap;
using System.IO;
using System.Security.Permissions;
using System.Reflection; namespace RefAtrr
{ [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Property, AllowMultiple = true, Inherited = true)] //Author属性只能用于类和结构,AllowMultiple是否允许多次用属性, Inherited是这个属性是滞延续到子类。
public class SqlTableAttribute : System.Attribute
{
private string name;
public SqlTableAttribute(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
}
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Property, AllowMultiple = true, Inherited = true)] //Author属性只能用于类和结构,AllowMultiple是否允许多次用属性, Inherited是这个属性是滞延续到子类。
public class SqlFieldAttribute : System.Attribute
{
private string name;
Type fieldtype;
bool key; public SqlFieldAttribute(string name, Type fieldtype, bool key)
{
this.name = name;
this.fieldtype = fieldtype;
this.key = key;
}
public Type FieldType
{
get { return fieldtype; }
set { fieldtype = value; }
} public bool Key
{
get { return key; }
set { key = value; }
} public string Name
{
get { return name; }
}
}
interface IEntityTable
{
}
[SqlTable("StuUsers")]
class User : IEntityTable
{
[SqlField("ID", typeof(int), true)]
public int Number
{
get;
set;
}
[SqlField("StuNum", typeof(string), false)]
public string StuNumber
{
get;
set;
}
[SqlField("Passwd", typeof(string), false)]
public string Password
{
get;
set;
}
}
[SqlTable("Announcement")]
class AnnClass : IEntityTable
{
[SqlField("ID", typeof(int), true)]
public int Number
{
get;
set;
}
[SqlField("PubTitle", typeof(string), false)]
public string Title
{
get;
set;
}
[SqlField("PubCon", typeof(string), false)]
public string Conn
{
get;
set;
}
}
enum SqlType
{
Select,
Update,
Insert,
Delete
}
class Program
{
static void Main()
{
AnnClass ac = new AnnClass();
ac.Number = ;
ac.Title = "通知";
ac.Conn = "好好工作,天天上网"; User user = new User();
user.Number = ;
user.StuNumber = "";
user.Password = ""; //用接口实现
EntitHandle Eh = new EntitHandle();
Console.WriteLine(Eh.GreatSQL(user, SqlType.Insert));
Console.WriteLine("--------------------------------------------------");
Console.WriteLine(Eh.GreatSQL(ac, SqlType.Delete));
Console.WriteLine("--------------------------------------------------");
//用泛型实现
EntityHandle<IEntityTable> EhG = new EntityHandle<IEntityTable>();
Console.WriteLine(EhG.GreatSQL(ac, SqlType.Select ));
Console.WriteLine("--------------------------------------------------");
Console.WriteLine(EhG.GreatSQL(user, SqlType.Update ));
Console.WriteLine("--------------------------------------------------");
} } class EntitHandle
{
public string GreatSQL(IEntityTable EntityTable, SqlType sqltype)
{
Type usertype = EntityTable.GetType();
object[] ObjArr = usertype.GetCustomAttributes(true);
string tablename = ((SqlTableAttribute)ObjArr[]).Name;
PropertyInfo[] properties = usertype.GetProperties();
string SQL = "";
switch (sqltype)
{
case SqlType.Select:
SQL = Select(EntityTable, tablename, properties);
break;
case SqlType.Delete:
SQL = Delete(EntityTable, tablename, properties);
break;
case SqlType.Insert:
SQL = Insert(EntityTable, tablename, properties);
break;
case SqlType.Update:
SQL = Update(EntityTable, tablename, properties);
break;
}
return SQL; }
string Insert(IEntityTable EntityTable, string tablename, PropertyInfo[] properties)
{
string value = "";
foreach (PropertyInfo o in properties)
{
value += ((SqlFieldAttribute)o.GetCustomAttributes(true)[]).Name + "='" + o.GetValue(EntityTable, null).ToString() + "',";
}
value = value.TrimEnd(',');
string SQL = string.Format("insert into {0} values({1})", tablename, value);
return SQL;
}
string Update(IEntityTable EntityTable, string tablename, PropertyInfo[] properties)
{
string value = "";
string condition = "";
foreach (PropertyInfo o in properties)
{
SqlFieldAttribute sfa = (SqlFieldAttribute)o.GetCustomAttributes(false)[];
value += sfa.Name + "='" + o.GetValue(EntityTable, null).ToString() + "',";
if (sfa.Key)
{
string keyname = sfa.Name;
string keyvalue = o.GetValue(EntityTable, null).ToString();
condition = string.Format(" where {0}='{1}'", keyname, keyvalue);
}
}
value = value.TrimEnd(',') + condition;
string SQL = string.Format("update {0} set {1} ", tablename, value);
return SQL;
}
string Delete(IEntityTable EntityTable, string tablename, PropertyInfo[] properties)
{
string condition = "";
foreach (PropertyInfo o in properties)
{
SqlFieldAttribute sfa = (SqlFieldAttribute)o.GetCustomAttributes(false)[];
if (sfa.Key)
{
string keyname = sfa.Name;
string keyvalue = o.GetValue(EntityTable, null).ToString();
condition = string.Format(" where {0}='{1}'", keyname, keyvalue);
}
}
string SQL = string.Format("delete {0} where {1}", tablename, condition);
return SQL;
}
string Select(IEntityTable EntityTable, string tablename, PropertyInfo[] properties)
{
string value = "";
foreach (PropertyInfo o in properties)
{
value += ((SqlFieldAttribute)o.GetCustomAttributes(true)[]).Name + ",";
}
value = value.TrimEnd(',');
string SQL = string.Format("select {0} from {1}", value, tablename);
return SQL;
}
} class EntityHandle<T> where T : IEntityTable
{
public string GreatSQL(T EntityTable, SqlType sqltype)
{
Type usertype = EntityTable.GetType();
object[] ObjArr = usertype.GetCustomAttributes(true);
string tablename = ((SqlTableAttribute)ObjArr[]).Name;
PropertyInfo[] properties = usertype.GetProperties();
string SQL = "";
switch (sqltype)
{
case SqlType.Select:
SQL = Select(EntityTable, tablename, properties);
break;
case SqlType.Delete:
SQL = Delete(EntityTable, tablename, properties);
break;
case SqlType.Insert:
SQL = Insert(EntityTable, tablename, properties);
break;
case SqlType.Update:
SQL = Update(EntityTable, tablename, properties);
break;
}
return SQL;
}
string Insert(IEntityTable EntityTable, string tablename, PropertyInfo[] properties)
{
string value = "";
foreach (PropertyInfo o in properties)
{
value += ((SqlFieldAttribute)o.GetCustomAttributes(true)[]).Name + "='" + o.GetValue(EntityTable, null).ToString() + "',";
}
value = value.TrimEnd(',');
string SQL = string.Format("insert into {0} values({1})", tablename, value);
return SQL;
}
string Update(IEntityTable EntityTable, string tablename, PropertyInfo[] properties)
{
string value = "";
string condition = "";
foreach (PropertyInfo o in properties)
{
SqlFieldAttribute sfa = (SqlFieldAttribute)o.GetCustomAttributes(false)[];
value += sfa.Name + "='" + o.GetValue(EntityTable, null).ToString() + "',";
if (sfa.Key)
{
string keyname = sfa.Name;
string keyvalue = o.GetValue(EntityTable, null).ToString();
condition = string.Format(" where {0}='{1}'", keyname, keyvalue);
}
}
value = value.TrimEnd(',') + condition;
string SQL = string.Format("update {0} set {1} ", tablename, value);
return SQL;
}
string Delete(IEntityTable EntityTable, string tablename, PropertyInfo[] properties)
{
string condition = "";
foreach (PropertyInfo o in properties)
{
SqlFieldAttribute sfa = (SqlFieldAttribute)o.GetCustomAttributes(false)[];
if (sfa.Key)
{
string keyname = sfa.Name;
string keyvalue = o.GetValue(EntityTable, null).ToString();
condition = string.Format(" where {0}='{1}'", keyname, keyvalue);
}
}
string SQL = string.Format("delete {0} where {1}", tablename, condition);
return SQL;
}
string Select(IEntityTable EntityTable, string tablename, PropertyInfo[] properties)
{
string value = "";
foreach (PropertyInfo o in properties)
{
value += ((SqlFieldAttribute)o.GetCustomAttributes(true)[]).Name + ",";
}
value = value.TrimEnd(',');
string SQL = string.Format("select {0} from {1}", value, tablename);
return SQL;
}
}
}

本文出自 “大懒丫头” 博客,请务必保留此出处http://lanyatou.blog.51cto.com/3306130/633163

.NET Framework基础知识(五)(转载)的更多相关文章

  1. RabbitMQ基础知识(转载)

    RabbitMQ基础知识(转载) 一.背景 RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现.AMQP 的出现其实也是应了广大人民群众的需 ...

  2. &period;NET Framework基础知识总结

    之前给大家总结了java的面试几次技巧总结,同学们看了觉得还是不错,能够得到大家的认可,感觉还是挺不错的.现在又有同学来想小编索要.NET面试的总结了,好吧.谁让小编这么好呢!以下是.NET面试之框架 ...

  3. Python基础知识&lpar;五&rpar;------字典

    Python基础知识(四)------字典 字典 一丶什么是字典 ​ dict关键字 , 以 {} 表示, 以key:value形式保存数据 ,每个逗号分隔 ​ 键: 必须是可哈希,(不可变的数据类型 ...

  4. &period;NET Framework基础知识(四)&lpar;转载&rpar;

    .反射:是编程的读取与类型相关联的元数据的行为.通过读取元数据,可以了解它是什么类型以及类型的成员. 比如类中的属性,方法,事件等.所属命名空间System.Reflection. 例:using S ...

  5. &period;NET Framework基础知识(三)&lpar;转载&rpar;

    .正则表达式:用一串字符验证是否符合一种规范,这个规范就是正则表达式. .正则表达式中常用的元字符: . 匹配除换行符以外的任意字符 \w 匹配字母或数字或下划线或汉字 \s 匹配空白符 \d 匹配数 ...

  6. &period;NET Framework基础知识(二)&lpar;转载&rpar;

    1.课外:为什么object数组可以赋值给object类型,int数组却不能赋值给int类型? 答:因为不管是什么什么数组都继承自Array,而Array又继承自object. 2.线程:是操作系统分 ...

  7. Android学习之基础知识五—创建自定义控件

    下面是控件和布局的继承关系: 从上面我们看到: 1.所有控件都是直接或间接继承View,所有的布局都是直接或间接继承ViewGroup 2.View是Android中最基本的UI组件,各种组件其实就是 ...

  8. APP开发基础知识(转载)

    来源:https://www.cnblogs.com/wangsea/p/9413672.html 本文针对小白用户对App做一个简单的介绍,首先要了解App都有哪些类型,不同的类型适用于哪些需求,用 ...

  9. MySQL系列&lpar;一&rpar;--基础知识(转载)

    安装就不说了,网上多得是,我的MySQL是8.0版本,可以参考:CentOS7安装MySQL8.0图文教程和MySQL8.0本地访问设置为远程访问权限 我的MySQL安装在阿里云上面,阿里云向外暴露端 ...

随机推荐

  1. Moosefs源代码分析

    一.分析MFS非常有用的资源 本来想写的,但是看到了CSDN上的资料就没这个心情了,非常详细的讲解分享给大家: CSDN中非常详细的文档:http://download.csdn.net/detail ...

  2. Yii源码阅读笔记(三十四)

    Instance类, 表示依赖注入容器或服务定位器中对某一个对象的引用 namespace yii\di; use Yii; use yii\base\InvalidConfigException; ...

  3. &lbrack;转&rsqb;为什么使用 Redis及其产品定位

    原文链接:http://www.infoq.com/cn/articles/tq-why-choose-redis 传统MySQL+ Memcached架构遇到的问题 实际MySQL是适合进行海量数据 ...

  4. python &colon; HTML&plus;CSS &lpar;左侧菜单&rpar;

    左侧菜单 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3 ...

  5. Linux内核之旅 链表实现

    #include "stdio.h" #include "stdlib.h" struct list_head{ struct list_head *prev; ...

  6. win7下80端口被&lpar;Pid&equals;4&rpar;占用的解决方法

    首先介绍一种网上普遍的方法,就是查找占据80端口的进程,然后关闭它就行了. 1.运行cmd,然后输入netstat -a -n -o,回车:2.查看开头几行包含0.0.0.0:80的那一行最后的pid ...

  7. Enumerable&period;SequenceEqual

    Determines whether two sequences are equal by comparing the elements by using the default equality c ...

  8. java中进制之间的转换

    //十进制转其他进制 Integer.toHexString(10); //将10转换为十六进制,返回字符串类型 Integer.toOctalString(10); //将10转为八进制,返回字符串 ...

  9. poj3186 Treats for the Cows

    http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  10. Centos安装php提示virtual memory exhausted&colon; Cannot allocate memory

    由于内存不够,需要在php配置的时候./configure最后添加上 --disable-fileinfo >>./configure --prefix= ...........   -- ...