protected override bool TryGet()

in sdk/tables/Microsoft.Azure.WebJobs.Extensions.Tables/src/PocoTypeBinder.cs [70:158]


        protected override bool TryGet<T>(BoundMemberInfo memberInfo, TableEntity source, out T value)
        {
            value = default;

            var key = memberInfo.Name switch
            {
                nameof(TableEntity.ETag) => ETagKeyName,
                _ => memberInfo.Name
            };

            if (!source.TryGetValue(key, out var propertyValue))
            {
                return false;
            }

            if (propertyValue == null)
            {
                value = default(T);
                return true;
            }

            if (typeof(T) == typeof(byte[]))
            {
                value = (T)(object)source.GetBinary(key);
            }
            else if (typeof(T) == typeof(BinaryData))
            {
                value = (T)(object)source.GetBinaryData(key);
            }
            else if (typeof(T) == typeof(long) ||
                     typeof(T) == typeof(long?) ||
                     typeof(T) == typeof(double?) ||
                     typeof(T) == typeof(bool) ||
                     typeof(T) == typeof(bool?) ||
                     typeof(T) == typeof(Guid) ||
                     typeof(T) == typeof(Guid?) ||
                     typeof(T) == typeof(DateTimeOffset) ||
                     typeof(T) == typeof(DateTimeOffset?) ||
                     typeof(T) == typeof(string) ||
                     typeof(T) == typeof(int) ||
                     typeof(T) == typeof(int?))
            {
                value = (T)propertyValue;
            }
            else if (typeof(T) == typeof(DateTime))
            {
                value = (T)(object) source.GetDateTime(key);
            }
            else if (typeof(T) == typeof(DateTime?))
            {
                value = (T)(object) source.GetDateTime(key);
            }
            else if (typeof(T) == typeof(double))
            {
                value = (T)Convert.ChangeType(propertyValue, typeof(double), CultureInfo.InvariantCulture);
            }
            // SDK encodes ulongs as longs but T1 and T2 extension use string
            // handle both
            else if (typeof(T) == typeof(ulong) && propertyValue is long l)
            {
                value = (T)(object) (ulong) l;
            }
            else if (typeof(T) == typeof(ulong?) && propertyValue is long l2)
            {
                value = (T)(object) (ulong) l2;
            }
            else if (typeof(T).IsEnum)
            {
                value = (T)Enum.Parse(memberInfo.Type, propertyValue as string );
            }
            else if (typeof(T).IsGenericType &&
                     typeof(T).GetGenericTypeDefinition() == typeof(Nullable<>) &&
                     typeof(T).GetGenericArguments() is { Length: 1 } arguments &&
                     arguments[0].IsEnum)
            {
                value = (T)Enum.Parse(arguments[0], propertyValue as string );
            }
            else if (typeof(T) == typeof(ETag) ||
                     typeof(T) == typeof(ETag?))
            {
                value = (T)(object) new ETag(source.GetString(key));
            }
            else
            {
                value = JsonConvert.DeserializeObject<T>(source.GetString(key));
            }

            return true;
        }