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

ToByteString() private static method

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

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

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

                return output;
            }
            
            // handle for supported conversions.
            switch (sourceType)
            {
                case BuiltInType.ByteString:
                {
                    return (byte[])value; 
                }

                case BuiltInType.Guid:
                {
                    return ((Guid)value).ToByteArray(); 
                }
            }
            
            // conversion not supported.
            return null;
        }