The arguments for a SharePoint conversion.
Inheritance: ConversionArguments
 /// <summary>
 /// Converts the specified value back.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="arguments">The arguments.</param>
 /// <returns>
 /// The converted value.
 /// </returns>
 public override object ConvertBack(object value, SharePointListItemConversionArguments arguments)
 {
     var principal = value as UserValue;
     return principal != null
         ? string.Format(CultureInfo.InvariantCulture, "{0};#{1}", principal.Id, (principal.DisplayName ?? string.Empty).Replace(";", ";;"))
         : null;
 }
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, SharePointListItemConversionArguments arguments)
        {
            UserValue userValue = null;
            var sharepointUserValue = new SPFieldUserValue(arguments.ListItem.Web, value as string);
            var principal = sharepointUserValue.User;
            userValue = principal != null ? new UserValue(principal) : null;

            return userValue;
        }
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, SharePointListItemConversionArguments arguments)
        {
            TaxonomyValueCollection convertedValues = null;

            var taxonomyFieldValueCollection = value as TaxonomyFieldValueCollection;
            if (taxonomyFieldValueCollection == null)
            {
                var stringValue = value as string;
                if (!string.IsNullOrEmpty(stringValue))
                {
                    taxonomyFieldValueCollection = new TaxonomyFieldValueCollection(stringValue);
                }
            }

            if (taxonomyFieldValueCollection != null)
            {
                if (SPContext.Current != null)
                {
                    // Resolve the Term from the term store, because we want all Labels and we want to
                    // create the TaxonomyValue object with a label in the correct LCID (we want one with
                    // LCID = CurrentUICUlture.LCID
                    var underLyingTerms = new List<Term>();
                    foreach (TaxonomyFieldValue taxonomyFieldValue in taxonomyFieldValueCollection)
                    {
                        if (!string.IsNullOrEmpty(taxonomyFieldValue.TermGuid))
                        {
                            var foundTerm = this.taxonomyService.GetTermForId(SPContext.Current.Site, new Guid(taxonomyFieldValue.TermGuid));

                            if (foundTerm != null)
                            {
                                underLyingTerms.Add(foundTerm);
                            }
                        }
                    }

                    convertedValues = new TaxonomyValueCollection(underLyingTerms);
                }
                else
                {
                    // We don't have access to a SPContext (needed to use the TaxonomyService), so we need to
                    // fall back on the non-UICulture-respecting TaxonomyValueCollection constructor
                    convertedValues = new TaxonomyValueCollection(taxonomyFieldValueCollection);
                }
            }

            return convertedValues;
        }
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, SharePointListItemConversionArguments arguments)
        {
            UserValue userValue = null;

            try
            {
                var sharepointUserValue = new SPFieldUserValue(arguments.ListItem.Web, value as string);
                var principal = sharepointUserValue.User;
                userValue = principal != null ? new UserValue(principal) : null;
            }
            catch (ArgumentException)
            {
                // failed to read SPUser value, will return null
            }

            return userValue;
        }
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, SharePointListItemConversionArguments arguments)
        {
            TaxonomyValue convertedValue = null;

            if (value == DBNull.Value)
            {
                return null;
            }

            var taxonomyFieldValue = value as TaxonomyFieldValue;

            if (taxonomyFieldValue == null)
            {
                var stringValue = value as string;
                if (!string.IsNullOrEmpty(stringValue))
                {
                    taxonomyFieldValue = new TaxonomyFieldValue(stringValue);
                }
            }

            if (taxonomyFieldValue != null && !string.IsNullOrEmpty(taxonomyFieldValue.TermGuid))
            {
                if (SPContext.Current != null)
                {
                    // Resolve the Term from the term store, because we want all Labels and we want to
                    // create the TaxonomyValue object with a label in the correct LCID (we want one with
                    // LCID = CurrentUICUlture.LCID
                    Term underlyingTerm = this.taxonomyService.GetTermForId(SPContext.Current.Site, new Guid(taxonomyFieldValue.TermGuid));

                    if (underlyingTerm != null)
                    {
                        convertedValue = new TaxonomyValue(underlyingTerm);
                    }
                }
                else
                {
                    // We don't have access to a SPContext (needed to use the TaxonomyService), so we need to
                    // fall back on the non-UICulture-respecting TaxonomyValue constructor
                    convertedValue = new TaxonomyValue(taxonomyFieldValue);
                }
            }

            return convertedValue;
        }
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, SharePointListItemConversionArguments arguments)
        {
            var lookupValue = value as SPFieldLookupValue;
            if (lookupValue == null)
            {
                var stringValue = value as string;
                if (!string.IsNullOrEmpty(stringValue))
                {
                    lookupValue = new SPFieldLookupValue(stringValue);
                }
            }

            if (lookupValue != null)
            {
                var lookupField = arguments.ListItem.Fields.GetFieldByInternalName(arguments.ValueKey) as SPFieldLookup;
                if (lookupField != null)
                {
                    if (lookupField.LookupWebId == Guid.Empty || lookupField.LookupWebId == arguments.ListItem.Web.ID)
                    {
                        return GetLookupFieldValue(arguments.ListItem.Web, lookupField.LookupList, this._projectedFieldName, lookupValue.LookupId);
                    }
                    else
                    {
                        using (var web = arguments.ListItem.Web.Site.OpenWeb(lookupField.LookupWebId))
                        {
                            return GetLookupFieldValue(web, lookupField.LookupList, this._projectedFieldName, lookupValue.LookupId);
                        }
                    }
                }
                else
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No lookup field with Internal Name '{0}' could be found.", arguments.ValueKey));
                }
            }

            return null;
        }
        /// <summary>
        /// Converts the specified value back.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object ConvertBack(object value, SharePointListItemConversionArguments arguments)
        {
            var term = value as TaxonomyValue;
            TaxonomyFieldValue newTaxonomyFieldValue = null;

            TaxonomyField taxonomyField = (TaxonomyField)arguments.ListItem.Fields.GetField(arguments.ValueKey);
            newTaxonomyFieldValue = new TaxonomyFieldValue(taxonomyField);

            var noteField = arguments.ListItem.Fields[taxonomyField.TextField];

            if (term != null)
            {
                string labelGuidPair = term.Label + "|" + term.Id;

                // PopulateFromLabelGuidPair takes care of looking up the WssId value and creating a new item in the TaxonomyHiddenList if needed.
                // Main taxonomy field value format: WssID;#Label
                // TODO - Make sure we support sub-level terms with format: WssID;#Label|RootTermGuid|...|ParentTermGuid|TermGuid
                // Reference: http://msdn.microsoft.com/en-us/library/ee567833.aspx
                newTaxonomyFieldValue.PopulateFromLabelGuidPair(labelGuidPair);

                // Must write associated note field as well as the main taxonomy field.
                // Note field value format: Label|Guid
                // Reference: http://nickhobbs.wordpress.com/2012/02/21/sharepoint-2010-how-to-set-taxonomy-field-values-programmatically/
                arguments.FieldValues[noteField.InternalName] = labelGuidPair;
            }
            else
            {
                // No taxonomy value, make sure to empty the note field as well
                arguments.FieldValues[noteField.InternalName] = null;
            }

            return newTaxonomyFieldValue;
        }
        /// <summary>
        /// Converts the specified value back.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object ConvertBack(object value, SharePointListItemConversionArguments arguments)
        {
            var terms = value as TaxonomyValueCollection;
            TaxonomyFieldValueCollection newTaxonomyFieldValueCollection = null;

            TaxonomyField taxonomyField = (TaxonomyField)arguments.ListItem.Fields.GetField(arguments.ValueKey);
            newTaxonomyFieldValueCollection = new TaxonomyFieldValueCollection(taxonomyField);

            var noteField = arguments.ListItem.Fields[taxonomyField.TextField];

            if (terms != null && terms.Count > 0)
            {
                string labelGuidPairs = string.Join(";", terms.Select(term => term.Label + "|" + term.Id).ToArray());

                // PopulateFromLabelGuidPairs takes care of looking up the WssId values and creating new items in the TaxonomyHiddenList if needed.
                // Main taxonomy field value format: WssID;#Label;WssID;#Label;WssID;#Label...
                // TODO - Make sure we support sub-level terms with format: WssID;#Label|RootTermGuid|...|ParentTermGuid|TermGuid
                // Reference: http://msdn.microsoft.com/en-us/library/ee577520.aspx
                newTaxonomyFieldValueCollection.PopulateFromLabelGuidPairs(labelGuidPairs);

                // Must write associated note field as well as the main taxonomy field.
                // Note field value format: Label|Guid;Label|Guid;Label|Guid...
                // Reference: http://nickhobbs.wordpress.com/2012/02/21/sharepoint-2010-how-to-set-taxonomy-field-values-programmatically/
                arguments.FieldValues[noteField.InternalName] = labelGuidPairs;
            }
            else
            {
                // No taxonomy value, make sure to empty the note field as well
                arguments.FieldValues[noteField.InternalName] = null;
            }

            return newTaxonomyFieldValueCollection;
        }
 /// <summary>
 /// Converts the specified value back.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="arguments">The arguments.</param>
 /// <returns>
 /// The converted value.
 /// </returns>
 public abstract object ConvertBack(object value, SharePointListItemConversionArguments arguments);
 /// <summary>
 /// Converts the specified value back.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="arguments">The arguments.</param>
 /// <returns>
 /// The converted value.
 /// </returns>
 public override object ConvertBack(object value, SharePointListItemConversionArguments arguments)
 {
     throw new NotSupportedException();
 }