相关疑难解决方法(0)

如何使用反射将Int16值设置为Nullable <Enum>属性?

我需要这样做: -

MyClass.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace set_property__Enum_To_Nullable_Enum
{
    public enum MyEnum : short
    {
        One, 
        Two, 
        Three 
    }

    public class MyClass
    {
        public string MyStringProperty { get; set; }
        public MyEnum? MyEnumProperty { get; set; }

        public void ShowAll(string message)
        {
            Console.WriteLine(message);            
            Console.WriteLine("String   = " + MyStringProperty);
            Console.WriteLine("Enum   = " + MyEnumProperty.Value);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Program.cs中

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace set_property__Enum_To_Nullable_Enum
{
    class Program
    {
        static void Main(string[] args)
        {
            //Names …
Run Code Online (Sandbox Code Playgroud)

c# reflection .net-2.0

4
推荐指数
1
解决办法
3116
查看次数

c#从System.Reflection.FieldInfo转换为用户定义的类型

我有以下类Point和Class2.我的目的是在Class2中检索所有Points实例以将它们存储在List中.

public class Point
    {
        int x;
        int y;
        string col;

        public Point(int abs, int ord, string clr)
        {
            this.x = abs;
            this.y = ord;
            this.col = clr;
        }

        public string toColor()
        {
            return this.col;
        }

        public int Addition()
        {
            return (this.x + this.y);
        }
    }

class Class2
    {
        int test;
        Point pt1;
        Point pt2;
        Point pt3;
        List<Point> listPt = new List<Point>() { };

        public Class2()
        {
            test = 100;
            this.pt1 = new Point(2, 3, "red");
            this.pt2 = new Point(1, …
Run Code Online (Sandbox Code Playgroud)

c# reflection casting

4
推荐指数
1
解决办法
4393
查看次数

标签 统计

c# ×2

reflection ×2

.net-2.0 ×1

casting ×1