当前位置: 首页>>代码示例>>C#>>正文


C# Variant.ToString方法代码示例

本文整理汇总了C#中Variant.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Variant.ToString方法的具体用法?C# Variant.ToString怎么用?C# Variant.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Variant的用法示例。


在下文中一共展示了Variant.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShowDialog

        public Variant? ShowDialog(Variant value, BuiltInType builtInType)
        {
            if (value != Variant.Null)
            {
                ValueTB.Text = value.ToString();
            }
            
            if (ShowDialog() != DialogResult.OK)
            {
                return null;
            }

            if (String.IsNullOrEmpty(ValueTB.Text))
            {
                return Variant.Null;
            }

            return new Variant(TypeInfo.Cast(ValueTB.Text, builtInType));
        }
开发者ID:OPCFoundation,项目名称:UA-.NET,代码行数:19,代码来源:SetValueDlg.cs

示例2: GetAttributeDisplayText

        /// <summary>
        /// Gets the display text for the specified attribute.
        /// </summary>
        /// <param name="session">The currently active session.</param>
        /// <param name="attributeId">The id of the attribute.</param>
        /// <param name="value">The value of the attribute.</param>
        /// <returns>The attribute formatted as a string.</returns>
        public static string GetAttributeDisplayText(Session session, uint attributeId, Variant value)
        {
            if (value == Variant.Null)
            {
                return String.Empty;
            }

            switch (attributeId)
            {
                case Attributes.AccessLevel:
                case Attributes.UserAccessLevel:
                {
                    byte? field = value.Value as byte?;
                    
                    if (field != null)
                    {
                        return GetAccessLevelDisplayText(field.Value);
                    }

                    break;
                }

                case Attributes.EventNotifier:
                {
                    byte? field = value.Value as byte?;

                    if (field != null)
                    {
                        return GetEventNotifierDisplayText(field.Value);
                    }

                    break;
                }

                case Attributes.DataType:
                {
                    return session.NodeCache.GetDisplayText(value.Value as NodeId);
                }

                case Attributes.ValueRank:
                {
                    int? field = value.Value as int?;

                    if (field != null)
                    {
                        return GetValueRankDisplayText(field.Value);
                    }

                    break;
                }

                case Attributes.NodeClass:
                {
                    int? field = value.Value as int?;

                    if (field != null)
                    {
                        return ((NodeClass)field.Value).ToString();
                    }

                    break;
                }

                case Attributes.NodeId:
                {
                    NodeId field = value.Value as NodeId;

                    if (!NodeId.IsNull(field))
                    {
                        return field.ToString();
                    }

                    return "Null";
                }
            }

            // check for byte strings.
            if (value.Value is byte[])
            {
                return Utils.ToHexString(value.Value as byte[]);
            }

            // use default format.
            return value.ToString();            
        }
开发者ID:OPCFoundation,项目名称:UA-.NETStandardLibrary,代码行数:92,代码来源:ClientUtils.cs

示例3: SetValue

        /// <summary>
        /// Sets the value shown in the control.
        /// </summary>
        private void SetValue(Variant value)
        {
            BuiltInType targetType = BuiltInType.Null;
            int valueRank = ValueRanks.Scalar;

            if (value.TypeInfo != null && value.TypeInfo.BuiltInType != BuiltInType.Null)
            {
                targetType = value.TypeInfo.BuiltInType;
                valueRank = value.TypeInfo.ValueRank;
            }

            DataTypeCB.SelectedItem = targetType;
            ValueRankCB.SelectedItem = (ValueRankOptions)valueRank;

            if (value.Value == null)
            {
                ValueTB.Text = String.Empty;
                return;
            }

            // check for arrays.
            if (valueRank != ValueRanks.Scalar)
            {
                ValueTB.Text = value.ToString();
                ValueTB.ReadOnly = true;
                return;
            }

            // cast the value to the requested data type.
            ValueTB.Text = (string)TypeInfo.Cast(value.Value, value.TypeInfo, BuiltInType.String);
            ValueTB.ReadOnly = false;
        }
开发者ID:OPCFoundation,项目名称:UA-.NET,代码行数:35,代码来源:EditDataValueCtrl.cs

示例4: OkBTN_Click

        private void OkBTN_Click(object sender, EventArgs e)
        {
            try
            {
                #region Task #B4 - Call a Method
                List<object> inputArguments = new List<object>();

                TutorialModel.CalibrationDataType d = new TutorialModel.CalibrationDataType();
                d.Period = 10;
                d.Offset = 20;
                inputArguments.Add(new Variant(new ExtensionObject(d)));
             
                /*
             byte[] buffer1 = BitConverter.GetBytes((double)1);
             byte[] buffer2 = BitConverter.GetBytes((double)2);

             ExtensionObject ex = new ExtensionObject();
             ex.TypeId = new ExpandedNodeId(238, "http://somecompany.com/TutorialModel");
             ex.Body = Utils.Append(buffer1, buffer2);

             inputArguments.Add(new Variant(ex));
             
             for (int ii = 0; ii < m_firstOutputArgument; ii++)
             {
                 Variant value = (Variant)ArgumentsLV.Items[ii].Tag;
                 inputArguments.Add(value.Value);
             }
             */

                IList<object> outputArguments = m_session.Call(m_objectId, m_methodId, inputArguments.ToArray());

                for (int ii = m_firstOutputArgument; ii-m_firstOutputArgument < outputArguments.Count && ii < ArgumentsLV.Items.Count; ii++)
                {
                    Variant value = new Variant(outputArguments[ii-m_firstOutputArgument]);
                    ArgumentsLV.Items[ii].SubItems[2].Text = value.ToString();
                }

                MessageBox.Show("Call succeeded.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                #endregion
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:45,代码来源:CallMethodDlg.cs

示例5: UpdateList

        /// <summary>
        /// Updates the list control.
        /// </summary>
        private void UpdateList(Session session, Argument[] arguments, string browseName)
        {
            for (int ii = 0; ii < arguments.Length; ii++)
            {
                Argument argument = arguments[ii];
                Variant defaultValue = new Variant(TypeInfo.GetDefaultValue(argument.DataType, argument.ValueRank));

                ListViewItem item = new ListViewItem(arguments[ii].Name);

                if (browseName == BrowseNames.InputArguments)
                {
                    item.SubItems.Add("IN");
                    m_firstOutputArgument++;
                }
                else
                {
                    item.SubItems.Add("OUT");
                }

                string dataType = session.NodeCache.GetDisplayText(arguments[ii].DataType);

                if (arguments[ii].ValueRank >= 0)
                {
                    dataType += "[]";
                }

                item.SubItems.Add(defaultValue.ToString());
                item.SubItems.Add(dataType);
                item.SubItems.Add(Utils.Format("{0}", arguments[ii].Description));
                item.Tag = defaultValue;

                ArgumentsLV.Items.Add(item);
            }
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:37,代码来源:CallMethodDlg.cs


注:本文中的Variant.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。