@WinnerIT
Программист и фотограф-любитель

Как получить доступ к дочерним классам?

Доброго времени суток всем!

Разрабатываю WPF клиент для RIA сервиса, ранее написаного для Silverlight приложения.

На стороне сервиса есть класс:
public partial class PracticeContent 
{
 [Association("PracticeContent_slaveImageContent", "Id", "ParentId")]
        [Composition]
        [DataMember]
        public ImgContent SlaveImageContent
        {
            get;
            set;
        }

        [Association("PracticeContent_slaveMultiplePracticeContent", "Id", "ParentId")]
        [Composition]
        [DataMember]
        public MultipleChoicePracticeContent SlaveMultiplePracticeContent
        {
            get;
            set;
        }
.......
}


Моя проблема: я не могу получить доступ к SlaveImageContent и SlavePracticeContent в клиенте.
Подскажите, пож-ста, в какую сторону копать.
  • Вопрос задан
  • 295 просмотров
Пригласить эксперта
Ответы на вопрос 1
@jurabek
Use reflection for that.
public class ChildAttribute : Attribute
{ }
public class Parent
{
    public string AnotherProperty { get; set; }
    [Child]
    public ChildClass Child { get; set; }
}
public class ChildClass
{
    public string Name { get; set; }
}

 static void Main(string[] args)
 {
     var parent = new Parent();
     foreach (PropertyInfo propertyInfo in parent.GetType().GetProperties())
     {
          var childAttribute = propertyInfo.GetCustomAttribute<ChildAttribute>();
          if (childAttribute != null)
          {
              //Get value of child property
              var childPropertyValue = propertyInfo.GetValue(parent);
               propertyInfo.SetValue(parent, new ChildClass { Name = "Child class created from reflection" });
          }
     }
     bool result = parent.Child.Name == "Child class created from reflection";
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы