Re[2]: GetGetMethod не найден...
От: OraStarter  
Дата: 25.06.09 07:46
Оценка:
Попробовал компонентную модель:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ConsoleApplication2
{
    public class MyClass1
    {
        private string _myProp;
        public string MyProp {
            set {
                _myProp = value;
            }
        }
    }

    public class MyClass2
    {
        private string _myProp;
        public string MyProp {
            get {
                return _myProp;
            }
            set {
                _myProp = value;
            }
        }
    }

    class Program
    {
        static void Main(string[] args) {
            MyClass1 myClass1 = new MyClass1();
            myClass1.MyProp = "test";
            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(myClass1, false);
            PropertyDescriptor prop = props["MyProp"];
            if (prop == null) Console.WriteLine("class MyClass1 has not prop MyProp");
            else Console.WriteLine(prop.GetValue(myClass1));
            MyClass2 myClass2 = new MyClass2();
            myClass2.MyProp = "test";
            props = TypeDescriptor.GetProperties(myClass2, false);
            prop = props["MyProp"];
            if (prop == null)
                Console.WriteLine("class MyClass2 has not prop MyProp");
            else
                Console.WriteLine(prop.GetValue(myClass2));
        }
    }
}

TypeDescriptor.GetProperties — не видит write only св-в?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.