internal string ToCsv() { Type type = GetType(); TypeAccessor accessor = ObjectHydrator.GetAccessor(type); string[] values = type.FilterProperties <SalesforceReadonly, SalesforceIgnore>().Select(x => GetCsvValue(x, accessor)).ToArray(); return(String.Join(",", values)); }
public void WriteXml(XmlWriter writer) { // TODO: Implement more robust serialization Type type = GetType(); TypeAccessor accessor = ObjectHydrator.GetAccessor(type); writer.WriteElementString("type", type.GetName()); IList <string> fieldsToNull = new List <string>(); foreach (PropertyInfo info in from info in type.FilterProperties <SalesforceReadonly>() let ignoreAttribute = info.GetCustomAttribute <SalesforceIgnore>() where ignoreAttribute == null || !ignoreAttribute.IfEmpty select info) { object value = accessor[this, info.Name]; string salesforceName = info.GetName(); if (value == null) { fieldsToNull.Add(salesforceName); continue; } var xmlValue = value is DateTime ? ((DateTime)value).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") // Contributed by: Murillo.Mike - Salesforce requires UTC dates : value.ToString(); //Added additional routine for when value is Byte[] ---bnewbold 22OCT2014 if ((value as byte[]) != null) { //When value is passed in a byte array, as when uploading a filestream file, we need to read the value in rather than cast it to a string. byte[] byteArray = (byte[])value; //Cast value as byte array into temp variable writer.WriteStartElement(info.GetName()); //Not using WriteElementsString so need to preface with the XML Tag writer.WriteBase64(byteArray, 0, byteArray.Length); //Just use base64 XML Writer writer.WriteEndElement(); //Close the xml tag continue; } writer.WriteElementString(salesforceName, SalesforceNamespaces.SObject, xmlValue); } if (OperationType != CrudOperations.Insert) { foreach (string field in fieldsToNull) { writer.WriteElementString("fieldsToNull", SalesforceNamespaces.SObject, field); } } }
public void WriteXml(XmlWriter writer) { // TODO: Implement robust serialization Type type = GetType(); TypeAccessor accessor = ObjectHydrator.GetAccessor(type); writer.WriteAttributeString("type", ZuoraNamespaces.Type, "obj:" + type.GetName()); foreach (PropertyInfo info in type.GetCachedProperties()) { var value = accessor[this, info.Name]; if (value != null) { writer.WriteElementString(info.GetName(), ZuoraNamespaces.ZObject, value.ToString()); } } }
/// <summary> /// Auto-fill "FieldsToNull" attribute on SObject /// </summary> /// <typeparam name="T"></typeparam> /// <param name="item"></param> /// <returns></returns> public static T GenerateFieldsToNull <T>(this T item) where T : SObject { var type = typeof(T); var accessor = ObjectHydrator.GetAccessor(type); var fieldsToNull = new HashSet <string>(); // iterate over all READ-ONLY fields and if the value is null, add it to the list of fields to null foreach (var info in type.GetProperties().Where(info => (info.GetCustomAttribute <SalesforceReadonly>() == null) && (accessor[item, info.Name] == null) && (!fieldsToNull.Contains(info.Name)))) { fieldsToNull.Add(info.Name); } return(item); }
public void AddProperties <T>(T obj) { ObjectHydrator.Into(obj, Properties); }
public T GetProperties <T>() { return(ObjectHydrator.Build <T>(Properties)); }
public void WriteXml(XmlWriter writer) { // TODO: Implement more robust serialization var type = GetType(); var accessor = ObjectHydrator.GetAccessor(type); writer.WriteElementString("type", type.GetName()); IList <string> fieldsToNull = new List <string>(); var isInsert = OperationType == CrudOperations.Insert; foreach (var info in type.FilterProperties(SalesforceFilterOption.IgnoreIfNull | (isInsert ? SalesforceFilterOption.SaveOnInsertOnly : SalesforceFilterOption.None))) { // get filter logic var salesforceFilter = info.GetCustomAttribute <SalesforceFilterAttribute>(); var noFilter = salesforceFilter == null; var ignoreIfEmpty = (!noFilter) && salesforceFilter.Options.HasFlag(SalesforceFilterOption.IgnoreIfNull); var saveOnInsert = (!noFilter) && salesforceFilter.Options.HasFlag(SalesforceFilterOption.SaveOnInsertOnly); var value = accessor[this, info.Name]; var salesforceName = info.GetName(); // Need to be able to dynamically control nullable fields if (value == null) { if ((noFilter || (!ignoreIfEmpty) || (isInsert && saveOnInsert)) && (!fieldsToNull.Contains(salesforceName))) { fieldsToNull.Add(salesforceName); } continue; } var xmlValue = value is DateTime ? ((DateTime)value).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") // Contributed by: Murillo.Mike - Salesforce requires UTC dates : value.ToString(); //Added additional routine for when value is Byte[] ---bnewbold 22OCT2014 if ((value as byte[]) != null) { //When value is passed in a byte array, as when uploading a filestream file, we need to read the value in rather than cast it to a string. var byteArray = (byte[])value; //Cast value as byte array into temp variable writer.WriteStartElement(info.GetName()); //Not using WriteElementsString so need to preface with the XML Tag writer.WriteBase64(byteArray, 0, byteArray.Length); //Just use base64 XML Writer writer.WriteEndElement(); //Close the xml tag continue; } writer.WriteElementString(salesforceName, SalesforceNamespaces.SObject, xmlValue); } if (OperationType == CrudOperations.Insert) { return; } foreach (var field in fieldsToNull) { writer.WriteElementString("fieldsToNull", SalesforceNamespaces.SObject, field); } }