反射_读取和删除文件

反射_读取和删除文件<15/9/2017>

在桌面创建文本文档,写入执行的类,方法和路径


写入代码实现根据文本文档内容创建文件或删除的功能

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

namespace 作业
{

    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string[] line = File.ReadAllLines(@"C:\Users\Maximilian Liu\Desktop\list.txt", Encoding.GetEncoding("gbk"));
                Type t = Type.GetType(line[0]);
                object o = t.GetConstructors()[0].Invoke(null);
                MethodInfo mm = t.GetMethod(line[1], new Type[] { typeof(string) });
                mm.Invoke(o, new object[] { line[2] });
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

        }
    }

    public class FileOperator
    {

        public void Create(string path)
        {
            File.Create(@path);
        }

        public void Delete(string path)
        {
            File.Delete(@path);
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值