473,408 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Serialization and Custom Attributes


1st please forgive me if I posted this to the wrong news group(s), news
group guidance would be appreciated.

Question: I have the following sample class generated from XSD.exe (Vs
2005). I would like to set an attribute
on each field (LastName,FirstName,etc) that indicates if the field is
ReadOnly/ViewOnly/Unrestricted. If I create
the attributes in the Schema and then run the XSD, the output/class is very
cumbersome. My web service is passing this
structure back to the client, and I would like the client to be able to
query the field level security.

I would like to implement something like

[System.Xml.Serialization>XmlElementAttribute(Secur ity="ReadOnly")]
public string LastName {
get {
return this.lastNameField;
}
set {
this.lastNameField = value;
}
}

Is there some way I can assign an XMLAttribute at design time, that I can
set at runtime to indicate the different field level
security priviledges ?

Purpose: To Implement Field Level Security from the Schema

//----------------------------------------------------------------------------------------------------------

[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://tempuri.org/Example.xsd",
IsNullable=false)]
public partial class Person {

private string lastNameField;

private string firstnameField;

private System.DateTime birthdateField;

/// <remarks/>
public string LastName {
get {
return this.lastNameField;
}
set {
this.lastNameField = value;
}
}

/// <remarks/>
public string Firstname {
get {
return this.firstnameField;
}
set {
this.firstnameField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataT ype="date")]
public System.DateTime Birthdate {
get {
return this.birthdateField;
}
set {
this.birthdateField = value;
}
}
May 6 '06 #1
2 1580
You can't set attributes at runtime because they are just declarative.
You have to use a separate field for each.
Maybe you can use something like this:

public enum FieldSecurity
{
ReadOnly,
ViewOnly,
Unrestricted
}
private FieldSecurity lastNameSecurityField;

[System.Xml.Serialization.XmlAttributeAttribute]
public FieldSecurity LastNameSecurity
{
get
{
return lastNameSecurityField;
}
set
{
lastNameSecurityField = value;
}
}

May 7 '06 #2
Actually you can set attributes at runtime if you use a custom type
descriptor http://msdn2.microsoft.com/en-us/library/ms171819.aspx.

Cheers,

Greg Young
MVP - C#
"cancer" <to**********@hotmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
You can't set attributes at runtime because they are just declarative.
You have to use a separate field for each.
Maybe you can use something like this:

public enum FieldSecurity
{
ReadOnly,
ViewOnly,
Unrestricted
}
private FieldSecurity lastNameSecurityField;

[System.Xml.Serialization.XmlAttributeAttribute]
public FieldSecurity LastNameSecurity
{
get
{
return lastNameSecurityField;
}
set
{
lastNameSecurityField = value;
}
}

May 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex | last post by:
It seems that XML Serializatoin automatically puts certain XSD attributs in the root node. How can I control the root node attributes emitted to something more custom so I can preserve my schema...
0
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
5
by: George Ter-Saakov | last post by:
I have 2 classes one is document and another is collection of documents. When i am trying to use XmlSerializer to serialize class which has clsDcoumentIds member variable i am getting an exception...
27
by: Codemonkey | last post by:
Heya All, Sorry, but I think it's about time for a monkey-ramble. I've just had enough of trying to serialize even simple objects with VB. A simple task you may think - stick the...
2
by: Angelos Karantzalis | last post by:
Hi y'all, we're using a bunch of classes in a project, that we wanted to convert to-from xml easily. So, we defined XmlAttribute annotations for our class members and all worked fine. The Xml...
1
by: Rucha | last post by:
We are using ACAServices in our project, and are passing entity classes as parameters to the ACAServiceMethod. We are using a private variable entityState to indicate whether the entity is...
4
by: Val | last post by:
I have a complex object that I need to serialize. Rather than rely on a standard routine, which is called during the serialization/deserialization, I would like to be able to use my own functions...
5
by: raj | last post by:
I know what interfaces are and what they used for etc. Today i am learning about serilization. I know to mark the class "serializable" and implement ISerializable interface, and then implement...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.