private void CollectFields(DataTypeDesign dataType, ValueRank valueRank, string basePath, Dictionary <string, Parameter> fields)
        {
            if (dataType.BasicDataType != BasicDataType.UserDefined || valueRank != ValueRank.Scalar)
            {
                return;
            }

            for (var parent = dataType; parent != null; parent = parent.BaseTypeNode as DataTypeDesign)
            {
                if (parent.Fields != null)
                {
                    for (var ii = 0; ii < parent.Fields.Length; ii++)
                    {
                        var parameter = parent.Fields[ii];
                        var fieldPath = parameter.Name;

                        if (!string.IsNullOrEmpty(basePath))
                        {
                            fieldPath = Utils.Format("{0}_{1}", basePath, parameter.Name);
                        }

                        fields[fieldPath] = parameter;
                        CollectFields(parameter.DataTypeNode, parameter.ValueRank, fieldPath, fields);
                    }
                }
            }
        }
 /// <summary>
 /// Set enumerated type fields
 /// </summary>
 /// <param name="design"></param>
 /// <param name="enumeratedType"></param>
 public static void SetDataType(this DataTypeDesign design, EnumeratedType enumeratedType)
 {
     if (enumeratedType == null)
     {
         return;
     }
     if (enumeratedType.IsOptionSet)
     {
         design.IsOptionSet = true;
         if (enumeratedType.BaseType != null)
         {
             design.BaseType = enumeratedType.BaseType.ToDesignBaseDataType();
         }
         else
         {
             design.BaseType = Constants.UInt32;
         }
     }
     else
     {
         design.BaseType = Constants.Enumeration;
     }
     if (enumeratedType.Value != null && enumeratedType.Value.Length > 0)
     {
         design.Fields = enumeratedType.Value.Select(v => v.ToParameter()).ToArray();
     }
 }
 /// <summary>
 /// Import fields
 /// </summary>
 /// <param name="design"></param>
 /// <param name="simpleType"></param>
 public static void SetDataType(this DataTypeDesign design, TypeDeclaration simpleType)
 {
     if (simpleType == null)
     {
         return;
     }
     if (simpleType.SourceType != null)
     {
         design.BaseType = simpleType.SourceType.ToDesignBaseDataType();
     }
 }
        /// <summary>
        /// Import fields
        /// </summary>
        /// <param name="design"></param>
        /// <param name="complexType"></param>
        public static void SetDataType(this DataTypeDesign design, ComplexType complexType)
        {
            if (complexType == null)
            {
                return;
            }
            if (complexType.BaseType != null)
            {
                design.BaseType = complexType.BaseType.ToDesignBaseDataType();
            }
            else
            {
                design.BaseType = Constants.Structure;
            }
            design.IsAbstract = complexType.IsAbstract;

            if (complexType.Field != null && complexType.Field.Length > 0)
            {
                design.Fields = complexType.Field.Select(v => v.ToParameter()).ToArray();
            }
        }
        /// <summary>
        /// Returns the data type to use for the value of a variable or the argument of a method.
        /// </summary>
        private string GetBinaryDataType(DataTypeDesign dataType)
        {
            switch (dataType.BasicDataType)
            {
            case BasicDataType.Boolean: { return("opc:Boolean"); }

            case BasicDataType.SByte: { return("opc:SByte"); }

            case BasicDataType.Byte: { return("opc:Byte"); }

            case BasicDataType.Int16: { return("opc:Int16"); }

            case BasicDataType.UInt16: { return("opc:UInt16"); }

            case BasicDataType.Int32: { return("opc:Int32"); }

            case BasicDataType.UInt32: { return("opc:UInt32"); }

            case BasicDataType.Int64: { return("opc:Int64"); }

            case BasicDataType.UInt64: { return("opc:UInt64"); }

            case BasicDataType.Float: { return("opc:Float"); }

            case BasicDataType.Double: { return("opc:Double"); }

            case BasicDataType.String: { return("opc:String"); }

            case BasicDataType.DateTime: { return("opc:DateTime"); }

            case BasicDataType.Guid: { return("opc:Guid"); }

            case BasicDataType.ByteString: { return("opc:ByteString"); }

            case BasicDataType.XmlElement: { return("ua:XmlElement"); }

            case BasicDataType.NodeId: { return("ua:NodeId"); }

            case BasicDataType.ExpandedNodeId: { return("ua:ExpandedNodeId"); }

            case BasicDataType.StatusCode: { return("ua:StatusCode"); }

            case BasicDataType.DiagnosticInfo: { return("ua:DiagnosticInfo"); }

            case BasicDataType.QualifiedName: { return("ua:QualifiedName"); }

            case BasicDataType.LocalizedText: { return("ua:LocalizedText"); }

            case BasicDataType.DataValue: { return("ua:DataValue"); }

            case BasicDataType.Number: { return("ua:Variant"); }

            case BasicDataType.Integer: { return("ua:Variant"); }

            case BasicDataType.UInteger: { return("ua:Variant"); }

            case BasicDataType.BaseDataType: { return("ua:Variant"); }

            default:
            case BasicDataType.Enumeration:
            case BasicDataType.Structure: {
                if (dataType.SymbolicName == new XmlQualifiedName("Structure", DefaultNamespace))
                {
                    return(string.Format("ua:ExtensionObject"));
                }

                if (dataType.SymbolicName == new XmlQualifiedName("Enumeration", DefaultNamespace))
                {
                    if (dataType.IsOptionSet)
                    {
                        return(GetBinaryDataType((DataTypeDesign)dataType.BaseTypeNode));
                    }

                    return(string.Format("ua:Int32"));
                }

                var prefix = "tns";

                if (dataType.SymbolicName.Namespace != _model.TargetNamespace)
                {
                    if (dataType.SymbolicName.Namespace == DefaultNamespace)
                    {
                        prefix = "ua";
                    }
                    else
                    {
                        //            prefix = GetXmlNamespacePrefix(dataType.SymbolicName.Namespace);
                    }
                }

                return(string.Format("{0}:{1}", prefix, dataType.SymbolicName.Name));
            }
            }
        }