How to serialize attached properties

I am writing a .NET3.5 WPF application using the Composite Application Library. The application is divided into several modules.

In the infrastructure module, I defined a NetworkNode object. The network module manages the NetworkNodes collection and uses the XmlSerializer to store / load this collection. So far, everything is working.

But I have other modules, for example NodeModule. If NetworkNode was selected in the network module, the event is published to other modules using the EventAggregator. These modules can connect various information to NetworkNode using the connected properties.

The problem is that NetworkModule is not aware of other modules, so these properties are not serialized. Can I somehow enumerate and serialize all the properties attached to an object? Or do I need to change the concept and use something else besides attached properties?

Hello

+3
source share
3 answers

You can list all the dependency properties (attached or missing) defined on the object using DependencyObject.GetLocalValueEnumerator:

    LocalValueEnumerator propEnumerator = foo.GetLocalValueEnumerator();
    while (propEnumerator.MoveNext())
    {
        Console.WriteLine ("{0} = {1}",
                           propEnumerator.Current.Property.Name,
                           propEnumerator.Current.Value);
    }

XML ( IXmlSerializable, ...). , XamlWriter ( , , XamlSerializer...)

+3

CLR, XmlSerializer . XamlSerializer, "" CLR, DependencyObjects.

+3

.Net 4.0 ( , .Net 3.5)

IAttachedPropertyStore AttachablePropertyServices

# 1: http://blogs.msdn.com/b/bursteg/archive/2009/05/18/xaml-in-net-4-0-attached-properties-iattachedpropertystore-and-attachablepropertyservices.aspx

, , :

  • ( ) - (.. ), T.
  • AttachableMemberIdentifier (T, "MyProperty" )
  • T, "SetMyProperty" "GetMyProperty", "MyProperty" AttachableMemberIdentifier. ( "Foo" AttachableMemberIdentifier "SetBar" "GetBar", Xaml .) AttachablePropertyServices .

Reference example No. 2: http://blogs.msdn.com/b/mwinkle/archive/2009/12/07/attachedproperty-part-2-putting-it-together.aspx

+1
source

Source: https://habr.com/ru/post/1720899/


All Articles