csharp高级练习题:在运行时创建一个简单的类【难度:5级】:
创建一类在运行时
你的方法将作为参数接受包含** 类名**,字典字符串的字符串 - >键入包含** ** 的属性,以及裁判的类** 的** 实际类型已创建后.
你应该检查是否有类在同一程序返回FALSE已经存在如果是的话,你也应该确保创建在同一程序每一个类,姑且称之为"** ** RuntimeAssembly",命名空间是可选的,但是类名称将被传递给你的方法,没有命名空间.
每个类的属性将被访问和修改正常,e.g:
属性=新词典<字符串类型> {{ "ASTRING" 的typeof(字符串)}};
Kata.DefineClass( "SimpleClass",属性,引用的myType);
将myInstance =的CreateInstance(的myType);
myInstance.AString = "您好";
您将通过习题如果没有这些操作抛出一个异常,如果该值实际上改变.
快乐编码
编程目标:
public static class Kata
{
public static bool DefineClass(string className, Dictionary properties, ref Type actualType)
{
return true;
}
}
测试样例:
public class SomeClass
{ /* This class should not conflict with your runtime classes */ }
namespace Solution
{
using NUnit.Framework;
using System;
using System.Collections.Generic;
{
[Test]
public void BasicTest()
{
Random rand = new Random();
Type myType = typeof(object);
Dictionary properties;
最佳答案(多种解法):
更多关联题目:
免责申明
本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/
https://www.codewars.com/kata/create-a-simple-class-at-runtime