types/SPClientFieldIdentityPipeBind.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * SPClientFieldIdentityPipeBind.cs
 *
 * Copyright (c) 2017 karamem0
 *
 * This software is released under the MIT License.
 * https://github.com/karamem0/SPClient/blob/master/LICENSE
 */

namespace SPClient {

    /// <summary>
    /// Represents a parameter that stores a value that identifies field.
    /// </summary>
    public class SPClientFieldIdentityPipeBind {

        /// <summary>
        /// Indicates the value.
        /// </summary>
        private object value;

        /// <summary>
        /// Initializes the new instance of <see cref="SPClient.SPClientFieldIdentityPipeBind"/> class.
        /// </summary>
        /// <param name="fieldId">the column GUID.</param>
        public SPClientFieldIdentityPipeBind(System.Guid fieldId) {
            this.value = fieldId;
        }

        /// <summary>
        /// Initializes the new instance of <see cref="SPClient.SPClientFieldIdentityPipeBind"/> class.
        /// </summary>
        /// <param name="fieldInternalName">the column internal name.</param>
        public SPClientFieldIdentityPipeBind(string fieldInternalName) {
            this.value = fieldInternalName;
        }

        /// <summary>
        /// Initializes the new instance of <see cref="SPClient.SPClientFieldIdentityPipeBind"/> class.
        /// </summary>
        /// <param name="field">the column.</param>
        public SPClientFieldIdentityPipeBind(Microsoft.SharePoint.Client.Field field) {
            this.value = field;
        }

        /// <summary>
        /// Returns the value that identifies a field.
        /// </summary>
        /// <param name="clientContext">the client context.</param>
        public string GetValue(Microsoft.SharePoint.Client.ClientContext clientContext) {
            var value = this.value as Microsoft.SharePoint.Client.Field;
            if (value != null) {
                clientContext.Load(value);
                clientContext.ExecuteQuery();
                return value.InternalName;
            } else {
                return this.value.ToString();
            }
        }

    }

}