public void Initialize(Type t)
        {
            //cdt = new AConditionRuntime();
            cdt = Activator.CreateInstance(t) as AConditionRuntime;
            cdt.SetCurrentType(SelectedOutput.Split(' ')[0]);

            //<# foreach (var item in EnumNames)
            //{#>
            //	cdt.RegisterEnum(typeof(<#=ClassName#>.<#=item#>).AssemblyQualifiedName);
            //<# } #>
        }
예제 #2
0
        /// <summary>
        /// Selecteds the output changed.
        /// </summary>
        private void SelectedOutputChanged()
        {
            string[] outputParts = SelectedOutput.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            if (outputParts.Any(outputPart => outputPart.Trim().Length > 2) || outputParts.Any(outputPart => string.IsNullOrEmpty(outputPart) || outputPart == " "))
            {
                return;
            }

            List <byte> selectedBytes = outputParts.Select(outputPart => byte.Parse(outputPart, NumberStyles.HexNumber)).ToList();

            string byteValue   = string.Empty;
            string shortValue  = string.Empty;
            string uShortValue = string.Empty;
            string int24Value  = string.Empty;
            string uInt24Value = string.Empty;
            string intValue    = string.Empty;
            string uIntValue   = string.Empty;
            string floatValue  = string.Empty;
            string stringValue = string.Empty;

            if (selectedBytes.Count == 1)
            {
                byteValue = string.Format("Byte Value: '{0}' - ", selectedBytes[0]);
            }

            if (selectedBytes.Count == 2)
            {
                shortValue = string.Format("Short Value: '{0}' - ", (SwapBytes) ? BitConverter.ToInt16(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToInt16(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count == 2)
            {
                uShortValue = string.Format("UShort Value: '{0}' - ", (SwapBytes) ? BitConverter.ToUInt16(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToUInt16(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count == 3)
            {
                int24Value = string.Format("Int24 Value: '{0}' - ", (SwapBytes) ? new Int24(BitConverter.ToInt32(new byte[] { selectedBytes[2], selectedBytes[1], selectedBytes[0], 0 }, 0)).Value : new Int24(BitConverter.ToInt32(new byte[] { selectedBytes[0], selectedBytes[1], selectedBytes[2], 0 }, 0)).Value);
            }

            if (selectedBytes.Count == 3)
            {
                uInt24Value = string.Format("UInt24 Value: '{0}' - ", (SwapBytes) ? BitConverter.ToUInt32(new byte[] { selectedBytes[0], selectedBytes[1], selectedBytes[2], 0 }, 0) : BitConverter.ToUInt32(new byte[] { selectedBytes[2], selectedBytes[1], selectedBytes[0], 0 }, 0));
            }

            if (selectedBytes.Count == 4)
            {
                intValue = string.Format("Int32 Value: '{0}' - ", (SwapBytes) ? BitConverter.ToInt32(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToInt32(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count == 4)
            {
                uIntValue = string.Format("UInt32 Value: '{0}' - ", (SwapBytes) ? BitConverter.ToUInt32(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToUInt32(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count == 4)
            {
                floatValue = string.Format("Float Value: '{0}' - ", (SwapBytes) ? BitConverter.ToSingle(selectedBytes.ToArray().Reverse().ToArray(), 0) : BitConverter.ToSingle(selectedBytes.ToArray(), 0));
            }

            if (selectedBytes.Count > 0)
            {
                stringValue = string.Format("String Value: '{0}'", Encoding.ASCII.GetString(selectedBytes.ToArray()));
            }

            Value = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}", (!string.IsNullOrEmpty(byteValue)) ? byteValue : "",
                                  (!string.IsNullOrEmpty(shortValue)) ? shortValue : "",
                                  (!string.IsNullOrEmpty(uShortValue)) ? uShortValue : "",
                                  (!string.IsNullOrEmpty(int24Value)) ? int24Value : "",
                                  (!string.IsNullOrEmpty(uInt24Value)) ? uInt24Value : "",
                                  (!string.IsNullOrEmpty(intValue)) ? intValue : "",
                                  (!string.IsNullOrEmpty(uIntValue)) ? uIntValue : "",
                                  (!string.IsNullOrEmpty(floatValue)) ? floatValue : "",
                                  (!string.IsNullOrEmpty(stringValue)) ? stringValue : "");
        }