Export class type

本文探讨了如何在C#中通过自定义类实现国际化属性更新及类型替换,具体展示了如何通过覆盖属性获取国际化后的文本,并应用于员工和清洁工类中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C# API有这样的功能:

View Code
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace ConsoleApplication5
 7 {
 8     abstract class Person
 9     {
10         private string _name;
11         public string Name
12         {
13             get { return _name; }
14         }
15         
16     }
17     class Empoyee : Person
18     {
19        
20 
21     }
22     class Janitor : Person
23     {
24       
25     }
26     class Program
27     {
28         static void Main(string[] args)
29         {
30             var people = new List<Person>();
31             people.Add(new Empoyee());
32             people.Add(new Janitor());
33             foreach (var item in people)
34             {
35                 Console.WriteLine("Type {0}", item.GetType().Name);
36             }
37             Console.ReadKey();
38         }
39     }
40 }

 

但是我们提倡这样做:The text用来update用户应该来自code本身,而不是来自什么build in framework。为了自由

View Code

比如Localization:

View Code
1 class Janitor : Person
2     {
3      。。。
4         public override string TypeOfData
5         {
6             get {return Internationlization.Translate(string Janitor);}  
7         } 
8      。。。
9     }  

 

 

转载于:https://www.cnblogs.com/shawnzxx/archive/2013/04/24/3040404.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值