Opc.Ua.ContentFilter.ToDateTime C# (CSharp) Method

ToDateTime() private static method

Converts a value to a DateTime
private static ToDateTime ( object value, BuiltInType sourceType ) : object
value object
sourceType BuiltInType
return object
        private static object ToDateTime(object value, BuiltInType sourceType)
        {            
            // check for array conversions.
            Array array = value as Array;

            if (array != null)
            {
                DateTime[] output = new DateTime[array.Length];

                for (int ii = 0; ii < array.Length; ii++)
                {
                    output[ii] = (DateTime)Cast(array.GetValue(ii), BuiltInType.DateTime);
                }

                return output;
            }
            
            // handle for supported conversions.
            switch (sourceType)
            {
                case BuiltInType.DateTime:
                {
                    return (DateTime)value; 
                }

                case BuiltInType.String:
                {
                    return XmlConvert.ToDateTimeOffset((string) value); 
                }
            }
            
            // conversion not supported.
            return null;
        }