Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Serializable]
- public class StorageObject {
- public string Name { get; set; }
- public string Birthday { get; set; }
- public List<NameValuePairs> OtherInfo { get; set; }
- }
- [Serializable]
- public class NameValuePairs {
- public string Name { get; set; }
- public string Value { get; set; }
- }
- [WebMethod]
- public List<StorageObject> GetStorageObjects() {
- List<StorageObject> o = new List<StorageObject>() {
- new StorageObject() {
- Name = "Matthew",
- Birthday = "Jan 1st, 2008",
- OtherInfo = new List<NameValuePairs>() {
- new NameValuePairs() { Name = "Hobbies", Value = "Programming" },
- new NameValuePairs() { Name = "Website", Value = "Stackoverflow.com" }
- }
- },
- new StorageObject() {
- Name = "Joe",
- Birthday = "Jan 10th, 2008",
- OtherInfo = new List<NameValuePairs>() {
- new NameValuePairs() { Name = "Hobbies", Value = "Programming" },
- new NameValuePairs() { Name = "Website", Value = "Stackoverflow.com" }
- }
- }
- };
- return o;
- }
- <StorageObject>
- <Name>Matthew</Name>
- <Birthday>Jan 1st, 2008</Birthday>
- <OtherInfo>
- <NameValuePairs>
- <Name>Hobbies</Name>
- <Value>Programming</Value>
- </NameValuePairs>
- <NameValuePairs>
- <Name>Website</Name>
- <Value>Stackoverflow.com</Value>
- </NameValuePairs>
- </OtherInfo>
- </StorageObject>
- <OtherInfo>
- <Hobbies>Programming</Hobbies>
- <Website>Stackoverflow.com</Website>
- </OtherInfo>
- In PHP => "$Result["StorageObject"]["OtherInfo"]["Hobbies"]".
- In C# => var m = ServiceResult[0].OtherInfo["Hobbies"];
- public class OtherInfo {
- public string Hobbies { get; set; }
- public string FavoriteWebsite { get; set; }
- }
- public class StorageObject {
- public string Name { get; set; }
- public string Birthday { get; set; }
- public List<string> OtherInfo { get; set; }
- }
- OtherInfo = {"Hobbies|Programming", "Website|Stackoverflow.com"}
- <StorageObject>
- <Name>Matthew</Name>
- <Birthday>Jan 1st, 2008</Birthday>
- <OtherInfo>
- <string>Hobbies|Programming</string>
- <string>Website|Stackoverflow.com</string>
- </OtherInfo>
- </StorageObject>
- public class StorageObject {
- public string Name { get; set; }
- public string Birthday { get; set; }
- public XElement OtherInfo { get; set; } // XmlElement for dot net 2
- }
- XElement OtherInfo = new XElement("OtherInfo");
- OtherInfo.Add( ..Hobbies xelement & text value..);
- OtherInfo.Add( ..WebSite xelement & text value..);
- <OtherInfo>
- <Hobbies>Programming</Hobbies>
- <Website>Stackoverflow.com</Website>
- </OtherInfo>
- XElement OtherInfo = new XElement("OtherInfo");
- OtherInfo.Add( ..nvp xattribute Hobbies & value..);
- OtherInfo.Add( ..nvp xattribute WebSite & value..);
- <OtherInfo>
- <nvp n="Hobbies" v="Programming" />
- <nvp n="Website" v="Stackoverflow.com" />
- </OtherInfo>
- public class StorageObject {
- public string Name { get; set; }
- public string Birthday { get; set; }
- [XmlAnyElement("Info")] // this prevents double-nodes in the XML
- public XElement OtherInfo { get; set; }
- }
- StorageObject o = new StorageObject();
- o.OtherInfo.Add(new XElement("Hobbies","Programming");
- o.OtherInfo.Add(new XElement("Website","Stackoverflow.com");
- <Info>
- <Hobbies>Programming</Hobbies>
- <Website>Stackoverflow.com</Website>
- </Info>
- [Serializable]
- public class StorageObject {
- public string Name { get; set; }
- public string Birthday { get; set; }
- [Nonserializable]
- public Dictionary<string,List<string>> OtherInfo { get; set; }
- }
- [WebMethod]
- public List<StorageObject> GetStorageObjects() {
- // returns list of storage objects from persistent storage or cache
- }
- [WebMethod]
- public List<string> GetStorageObjectAttributes( string name )
- {
- // find storage object, sObj
- return sObj.Keys.ToList();
- }
- [WebMethod]
- public List<string> GetStorageObjectAtributeValues( sting name, string attribute )
- {
- // find storage object, sObj
- return sObj[attribute];
- }
- List<string> hobbies = storageObject.OtherInfo["Hobbies"];
Add Comment
Please, Sign In to add comment