开发者

WPF and WCF User Configurable Fields

开发者 https://www.devze.com 2022-12-14 04:04 出处:网络
I have a requirement whereby a user can specify a variable number of user-defined fields, for example in an xml file. These fields have a user-friendly name which is displayed in the GUI, and a code w

I have a requirement whereby a user can specify a variable number of user-defined fields, for example in an xml file. These fields have a user-friendly name which is displayed in the GUI, and a code which is used to persist and retrieve the value of the field to the database.

The problem is that I need both my WCF service to consume the list of user defined fields, so that when I load an object from my database, those fields and their values are loaded, but also I need my WPF Client to know about the fields too so that when the user creates a new type of object, those configurable fields are available as inputs in the form of say, a combo box.

Ive tried a number of ways of doing it and it looks like putting the configurable values into the service is the best way, then getting the client to retrieve the values from the service at startup. But im wondering if there is a 'proper' way to do this sort of t开发者_如何学JAVAhing as it seems like quite an obvious requirement for most enterprise applications.

Sorry if the question is a bit vague but I tried to abstract it away from the intricacies of my individual program.

Thanks Chris


How would you do it if WPF and WCF were not involved? How would it work if it was just one class library calling the other? You'd create a class to encapsulate your user-defined fields, and you'd then pass an instance of that class to the other piece of code.

Do the same thing here.


Well, as for the WCF service - you could always define a property something like:

[DataMember]
List<OptionalProperty> optionalProperties { get; set; }

and then define your "OptionalProperty" type as a data contract, too - quite possibly just a class with a Key and Value as string or something - or whatever you need.

[DataContract]
class OptionalProperty
{
    [DataMember] 
    string Key { get; set; }

    [DataMember]
    string Value { get; set; }
}

Since it's a list of something, you can have zero, one, two, five, fiveteen thousands etc.

Could that work for your scenario??

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号