public static List <ProfilePropertyContract> SerializeSettingsPropertyCollection(SettingsPropertyCollection oSettingsPropertyCollection) { #region VARIABLES IEnumerable <SettingsProperty> oSettingsPropertyCollectionToRead; List <ProfilePropertyContract> oPropertyList; ProfilePropertyContract oGenProperty; ProfilePropertyAttributeContract oGenAttribute; ICollection oPropertyAttributesValues; ICollection oPropertyAttributesKeys; int iAttributeIndex; #endregion oPropertyList = new List <ProfilePropertyContract>(); if (oSettingsPropertyCollection != null) { oSettingsPropertyCollectionToRead = oSettingsPropertyCollection.Cast <SettingsProperty>(); if (oSettingsPropertyCollectionToRead != null) { foreach (var property in oSettingsPropertyCollectionToRead) { oGenProperty = new ProfilePropertyContract() { Name = (!string.IsNullOrEmpty(property.Name) ? (property.Name) : (string.Empty)), Type = ((property.PropertyType != null) ? (property.PropertyType.ToString()) : (typeof(string).ToString())), IsReadOnly = property.IsReadOnly, DefaultValue = (property.DefaultValue != null) ? (property.DefaultValue.ToString()) : (string.Empty) }; if (property.Attributes != null) { oGenProperty.Attributes = new List <ProfilePropertyAttributeContract>(); oPropertyAttributesValues = property.Attributes.Values; oPropertyAttributesKeys = property.Attributes.Keys; foreach (var oPropertyattributeKey in oPropertyAttributesKeys) { oGenAttribute = new ProfilePropertyAttributeContract() { Key = oPropertyattributeKey.ToString() }; oGenProperty.Attributes.Add(oGenAttribute); } iAttributeIndex = 0; foreach (var oPropertyAttributeValue in oPropertyAttributesValues) { if (oGenProperty.Attributes[iAttributeIndex] != null) { oGenProperty.Attributes[iAttributeIndex].Value = oPropertyAttributeValue.ToString(); } iAttributeIndex++; } } oPropertyList.Add(oGenProperty); } } } return(oPropertyList); }
public static List <ProfilePropertyValueContract> SerializeSettingsPropertyValueCollection(SettingsPropertyValueCollection oSettingsPropertyValueCollection) { #region VARIABLES List <ProfilePropertyValueContract> oSettingsPropertyValueCollectionSerialized; ProfilePropertyAttributeContract oAttributeSerialized; ProfilePropertyValueContract oSettingsPropertyValueSerialized; ProfilePropertyContract oSettingsPropertySerialized; IEnumerable <SettingsPropertyValue> oSettingsCastedOut; ICollection oPropertyAttributesValues; ICollection oPropertyAttributesKeys; int iAttributeIndex; #endregion oSettingsPropertyValueCollectionSerialized = new List <ProfilePropertyValueContract>(); if (oSettingsPropertyValueCollection != null && oSettingsPropertyValueCollection.Count > 0) { oSettingsCastedOut = oSettingsPropertyValueCollection.Cast <SettingsPropertyValue>(); foreach (var oSetting in oSettingsCastedOut) { oSetting.Property.PropertyType = typeof(string); oSettingsPropertySerialized = new ProfilePropertyContract() { Name = (!string.IsNullOrEmpty(oSetting.Name) ? (oSetting.Name) : (string.Empty)), Type = ((oSetting.Property.PropertyType != null) ? (oSetting.Property.PropertyType.ToString()) : (typeof(string).ToString())), IsReadOnly = oSetting.Property.IsReadOnly, DefaultValue = (oSetting.Property.DefaultValue != null) ? (oSetting.Property.DefaultValue.ToString()) : (string.Empty) }; oSettingsPropertyValueSerialized = new ProfilePropertyValueContract() { ProfileProperty = oSettingsPropertySerialized }; if (oSetting.PropertyValue != null) { oSettingsPropertyValueSerialized.Value = oSetting.PropertyValue.ToString(); } if (oSetting.Property.Attributes != null) { oSettingsPropertySerialized.Attributes = new List <ProfilePropertyAttributeContract>(); oPropertyAttributesValues = oSetting.Property.Attributes.Values; oPropertyAttributesKeys = oSetting.Property.Attributes.Keys; foreach (var oPropertyattributeKey in oPropertyAttributesKeys) { oAttributeSerialized = new ProfilePropertyAttributeContract() { Key = oPropertyattributeKey.ToString() }; oSettingsPropertySerialized.Attributes.Add(oAttributeSerialized); } iAttributeIndex = 0; foreach (var oPropertyAttributeValue in oPropertyAttributesValues) { if (oSettingsPropertySerialized.Attributes[iAttributeIndex] != null) { oSettingsPropertySerialized.Attributes[iAttributeIndex].Value = oPropertyAttributeValue.ToString(); } iAttributeIndex++; } } } } return(oSettingsPropertyValueCollectionSerialized); }