<commit_before>// Copyright 2006 <NAME> <<EMAIL>>
// This software is made available under the MIT License
// See COPYING for details

using System;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace NDesk.DBus
{
	public struct Signature
	{
		//TODO: this class needs some work

		public Signature (string value)
		{
			this.Data = System.Text.Encoding.ASCII.GetBytes (value);
		}

		public Signature (params DType[] value)
		{
			this.Data = new byte[value.Length];

			MemoryStream ms = new MemoryStream (this.Data);

			foreach (DType t in value)
				ms.WriteByte ((byte)t);
		}

		public byte[] Data;

		public string Value
		{
			get {
				return System.Text.Encoding.ASCII.GetString (Data);
			} set {
				Data = System.Text.Encoding.ASCII.GetBytes (value);
			}
		}

		public override string ToString ()
		{
			string ret = "";
			StringBuilder sb = new StringBuilder ();

			foreach (DType t in Data) {
				sb.Append (t);
				sb.Append (" ");
			}

			return sb.ToString ();
		}

		public static DType TypeCodeToDType (TypeCode typeCode)
		{
			switch (typeCode)
			{
				case TypeCode.Empty:
					return DType.Invalid;
				case TypeCode.Object:
					return DType.Invalid;
				case TypeCode.DBNull:
					return DType.Invalid;
				case TypeCode.Boolean:
					return DType.Boolean;
				case TypeCode.Char:
					return DType.UInt16;
				case TypeCode.SByte:
					return DType.Byte;
				case TypeCode.Byte:
					return DType.Byte;
				case TypeCode.Int16:
					return DType.Int16;
				case TypeCode.UInt16:
					return DType.UInt16;
				case TypeCode.Int32:
					return DType.Int32;
				case TypeCode.UInt32:
					return DType.UInt32;
				case TypeCode.Int64:
					return DType.Int64;
				case TypeCode.UInt64:
					return DType.UInt64;
				case TypeCode.Single:
					return DType.Float;
				case TypeCode.Double:
					return DType.Double;
				case TypeCode.Decimal:
					return DType.Invalid;
				case TypeCode.DateTime:
					return DType.Invalid;
				case TypeCode.String:
					return DType.String;
				default:
					return DType.Invalid;
			}
		}

		public static DType TypeToDType (Type type)
		{
			//System.Console.WriteLine (type);
			//System.Console.WriteLine (Type.GetTypeCode (type));
			if (type.IsPrimitive)
				return TypeCodeToDType (Type.GetTypeCode (type));

			if (type.IsEnum)
				TypeToDType (type.GetElementType ());

			if (type == typeof (string))
				return DType.String;

			if (type == typeof (ObjectPath))
				return DType.ObjectPath;

			if (type == typeof (Signature))
				return DType.Signature;

			//if (type.UnderlyingSystemType != null)
			//	return TypeToDType (type.UnderlyingSystemType);

			return DType.Invalid;
		}

		/*
		public static DType TypeToDType (Type type)
		{
			if (type == null)
				return DType.Invalid;
			else if (type == typeof (byte))
				return DType.Byte;
			else if (type == typeof (bool))
				return DType.Boolean;<commit_msg>Forgot 'return'<commit_after>// Copyright 2006 <NAME> <<EMAIL>>
// This software is made available under the MIT License
// See COPYING for details

using System;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace NDesk.DBus
{
	public struct Signature
	{
		//TODO: this class needs some work

		public Signature (string value)
		{
			this.Data = System.Text.Encoding.ASCII.GetBytes (value);
		}

		public Signature (params DType[] value)
		{
			this.Data = new byte[value.Length];

			MemoryStream ms = new MemoryStream (this.Data);

			foreach (DType t in value)
				ms.WriteByte ((byte)t);
		}

		public byte[] Data;

		public string Value
		{
			get {
				return System.Text.Encoding.ASCII.GetString (Data);
			} set {
				Data = System.Text.Encoding.ASCII.GetBytes (value);
			}
		}

		public override string ToString ()
		{
			string ret = "";
			StringBuilder sb = new StringBuilder ();

			foreach (DType t in Data) {
				sb.Append (t);
				sb.Append (" ");
			}

			return sb.ToString ();
		}

		public static DType TypeCodeToDType (TypeCode typeCode)
		{
			switch (typeCode)
			{
				case TypeCode.Empty:
					return DType.Invalid;
				case TypeCode.Object:
					return DType.Invalid;
				case TypeCode.DBNull:
					return DType.Invalid;
				case TypeCode.Boolean:
					return DType.Boolean;
				case TypeCode.Char:
					return DType.UInt16;
				case TypeCode.SByte:
					return DType.Byte;
				case TypeCode.Byte:
					return DType.Byte;
				case TypeCode.Int16:
					return DType.Int16;
				case TypeCode.UInt16:
					return DType.UInt16;
				case TypeCode.Int32:
					return DType.Int32;
				case TypeCode.UInt32:
					return DType.UInt32;
				case TypeCode.Int64:
					return DType.Int64;
				case TypeCode.UInt64:
					return DType.UInt64;
				case TypeCode.Single:
					return DType.Float;
				case TypeCode.Double:
					return DType.Double;
				case TypeCode.Decimal:
					return DType.Invalid;
				case TypeCode.DateTime:
					return DType.Invalid;
				case TypeCode.String:
					return DType.String;
				default:
					return DType.Invalid;
			}
		}

		public static DType TypeToDType (Type type)
		{
			//System.Console.WriteLine (type);
			//System.Console.WriteLine (Type.GetTypeCode (type));
			if (type.IsPrimitive)
				return TypeCodeToDType (Type.GetTypeCode (type));

			if (type.IsEnum)
				return TypeToDType (type.GetElementType ());

			if (type == typeof (string))
				return DType.String;

			if (type == typeof (ObjectPath))
				return DType.ObjectPath;

			if (type == typeof (Signature))
				return DType.Signature;

			//if (type.UnderlyingSystemType != null)
			//	return TypeToDType (type.UnderlyingSystemType);

			return DType.Invalid;
		}

		/*
		public static DType TypeToDType (Type type)
		{
			if (type == null)
				return DType.Invalid;
			else if (type == typeof (byte))
				return DType.Byte;
			else if (type == typeof (bool))
				return DType.Boolean;
{'fraction_non_alphanumeric': 0.10578399590513564, 'fraction_numerical': 0.010237160894045385, 'mean_word_length': 2.7941747572815534, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5584278', 'n_tokens_mistral': 2461, 'n_tokens_neox': 1884, 'n_words': 507}