Opc.Ua.Com.Server.ComNamespaceMapper.GetLocalValue C# (CSharp) Method

GetLocalValue() public method

Converts a remote variant value to a local variant value.
public GetLocalValue ( Variant remoteValue ) : object
remoteValue Variant The remote value.
return object
        public object GetLocalValue(Variant remoteValue)
        {
            TypeInfo remoteType = remoteValue.TypeInfo;

            if (remoteType == null)
            {
                remoteType = TypeInfo.Construct(remoteValue.Value);
            }

            TypeInfo localType = GetLocalTypeInfo(remoteType);

            // check for array conversions.
            Array remoteArray = remoteValue.Value as Array;

            if (remoteArray != null && remoteType.ValueRank != ValueRanks.Scalar)
            {
                Array localArray = null;

                // convert byte[] arrays to object[] arrays.
                if (remoteType.BuiltInType == BuiltInType.ByteString || remoteType.BuiltInType == BuiltInType.ExtensionObject)
                {
                    localArray = TypeInfo.CastArray(remoteArray, remoteType.BuiltInType, BuiltInType.Null, null);
                    return localArray;
                }

                // convert Variant[] arrays to object[] arrays.
                if (localType.BuiltInType == BuiltInType.Variant)
                {
                    localArray = TypeInfo.CastArray(remoteArray, remoteType.BuiltInType, BuiltInType.Null, ConvertRemoteToLocal);
                    return localArray;
                }

                // convert all other types of arrays.
                localArray = TypeInfo.CastArray(remoteArray, remoteType.BuiltInType, localType.BuiltInType, ConvertRemoteToLocal);
                return localArray;
            }

            object localValue = ConvertRemoteToLocal(remoteValue.Value, remoteType.BuiltInType, localType.BuiltInType);
            return localValue;
        }