/*----------Functions----------*/
        //PRIVATE

        /// <summary>
        /// Check to see if the supplied type can be processed
        /// </summary>
        /// <param name="type">The type of object that is being tested</param>
        /// <returns>Returns true if the type can be processed</returns>
        private static bool CanProcessTypeValue(Type type)
        {
            //If the type is stored in the basic types lookup, its good
            if (BASIC_TYPE_LOOKUP.Contains(type))
            {
                return(true);
            }

            //Check the other basic types
            if (type == CHAR)
            {
                return(true);
            }
            if (UOBJ.IsAssignableFrom(type))
            {
                return(true);
            }
            if (ENUM.IsAssignableFrom(type))
            {
                return(true);
            }

            //Can't process a generic object only
            if (type == OBJ)
            {
                return(false);
            }

            //Otherwise check it is a value or has a default constructor
            return(type.IsValueType || type.GetConstructor(Type.EmptyTypes) != null);
        }
Example #2
0
        public void ToEnumStringWhenFlagsTest()
        {
            const AvoidWay ENUM = AvoidWay.Highways | AvoidWay.Tolls;

            var result = ENUM.ToEnumString('|');

            Assert.AreEqual("tolls|highways", result);
        }
Example #3
0
        public void ToEnumStringTest()
        {
            const AddressComponentType ENUM = AddressComponentType.Postal_Code;

            var result = ENUM.ToEnumString('|');

            Assert.AreEqual("postal_code", result);
        }
        public void ToEnumMemberStringTest()
        {
            const StyleFeature ENUM = StyleFeature.Transit;

            var result = ENUM.ToEnumMemberString();

            Assert.AreEqual("transit", result);
        }
Example #5
0
 public void GetDamage(float damage, ENUM.DAMAGETYPE damageType)
 {
     switch (damageType)
         {
             case ENUM.DAMAGETYPE.Normal:
                 break;
             case ENUM.DAMAGETYPE.Poisen:
                 break;
             case ENUM.DAMAGETYPE.Fire:
                 break;
             case ENUM.DAMAGETYPE.Electro:
                 break;
             case ENUM.DAMAGETYPE.Ice:
                 break;
         }
 }
        /// <summary>
        /// Retrieve the serialised value for a single object
        /// </summary>
        /// <param name="obj">The object that is to be serialsied</param>
        /// <param name="type">The type of object that is being serialised</param>
        /// <returns>Returns the value as a serialised string</returns>
        private static string SerialiseValue(object obj, Type type)
        {
            //If the object is a basic type, just to string it
            if (BASIC_TYPE_LOOKUP.Contains(type))
            {
                return(obj != null ? obj.ToString() : string.Empty);
            }

            //If this is a char, use the integral value
            if (type == CHAR)
            {
                return(((short)(char)obj).ToString());
            }

            //If a Unity object, serialise an object container
            if (UOBJ.IsAssignableFrom(type))
            {
                return(JsonUtility.ToJson(new SerialUnityObjectContainer {
                    obj = obj as UnityEngine.Object
                }));
            }

            //If the object is an enum
            if (ENUM.IsAssignableFrom(type))
            {
                return(JsonUtility.ToJson(new SerialCollectionContainer {
                    vals = new string[] {
                        MinifyTypeAssemblyName(type),
                        Convert.ToInt64(obj).ToString()
                    }
                }));
            }

            //At this point, use JsonUtility to manage other types
            return(JsonUtility.ToJson(obj));
        }
 public static extern BOOL EnumDisplaySettingsW(string lpszDeviceName, ENUM iModeNum, ref DEVMODEW lpDevMode);
 public ScreenStateExpression([NotNull] ScreenStateMachine <ENUM> parent,
                              ENUM stateName)
 {
     _parent    = parent;
     _stateName = stateName;
 }
        /// <summary>
        /// Parse the supplied text to an object of the specified type
        /// </summary>
        /// <param name="serial">The serialised data that is to be parsed to re-create the object definition</param>
        /// <param name="type">The type of the object that is to be returned by this operation</param>
        /// <returns>Returns a generic object of the specified type</returns>
        private static object ParseValue(string serial, Type type)
        {
            //Check if the object is one of the default types
            if (type == SBYTE)
            {
                sbyte val;    sbyte.TryParse(serial, out val);    return(val);
            }
            if (type == SHORT)
            {
                short val;    short.TryParse(serial, out val);    return(val);
            }
            if (type == INT)
            {
                int val;      int.TryParse(serial, out val);      return(val);
            }
            if (type == LONG)
            {
                long val;     long.TryParse(serial, out val);     return(val);
            }
            if (type == BYTE)
            {
                byte val;     byte.TryParse(serial, out val);     return(val);
            }
            if (type == USHORT)
            {
                ushort val;   ushort.TryParse(serial, out val);   return(val);
            }
            if (type == UINT)
            {
                uint val;     uint.TryParse(serial, out val);     return(val);
            }
            if (type == ULONG)
            {
                ulong val;    ulong.TryParse(serial, out val);    return(val);
            }
            if (type == FLOAT)
            {
                float val;    float.TryParse(serial, out val);    return(val);
            }
            if (type == DOUBLE)
            {
                double val;   double.TryParse(serial, out val);   return(val);
            }
            if (type == DECIMAL)
            {
                decimal val;  decimal.TryParse(serial, out val);  return(val);
            }
            if (type == BOOL)
            {
                bool val;     bool.TryParse(serial, out val);     return(val);
            }
            if (type == STRING)
            {
                return(serial);
            }
            if (type == CHAR)
            {
                short val;    short.TryParse(serial, out val);    return((char)val);
            }

            //If this is a Unity Engine object, deserialise the usual way
            if (UOBJ.IsAssignableFrom(type))
            {
                //Deserialise the object container
                SerialUnityObjectContainer objectContainer = JsonUtility.FromJson <SerialUnityObjectContainer>(serial);

                //Return the object reference value
                return(objectContainer.obj);
            }

            //If the object is an enumeration
            if (ENUM.IsAssignableFrom(type))
            {
                //Deserialise a container object
                SerialCollectionContainer container = JsonUtility.FromJson <SerialCollectionContainer>(serial);

                //There should be two values in the container
                if (container.vals.Length != 2)
                {
                    throw new ArgumentException("Serialised enumeration data has two values for processing. Received " + container.vals.Length);
                }

                //Determine the type that is being used
                Type enumType = Type.GetType(container.vals[0]);

                //Get the integral value to use
                long val = Convert.ToInt64(container.vals[1]);

                //Return the final value converted to the enumeration
                return(Enum.ToObject(enumType, val));
            }

            //At this point, use JsonUtility to manage other types
            return(JsonUtility.FromJson(serial, type));
        }
Example #10
0
        public override string ToString()
        {
            StringBuilder __sb    = new StringBuilder("LogicalType(");
            bool          __first = true;

            if (STRING != null && __isset.@STRING)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("STRING: ");
                __sb.Append(STRING == null ? "<null>" : STRING.ToString());
            }
            if (MAP != null && __isset.MAP)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("MAP: ");
                __sb.Append(MAP == null ? "<null>" : MAP.ToString());
            }
            if (LIST != null && __isset.LIST)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("LIST: ");
                __sb.Append(LIST == null ? "<null>" : LIST.ToString());
            }
            if (ENUM != null && __isset.@ENUM)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("ENUM: ");
                __sb.Append(ENUM == null ? "<null>" : ENUM.ToString());
            }
            if (DECIMAL != null && __isset.@DECIMAL)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("DECIMAL: ");
                __sb.Append(DECIMAL == null ? "<null>" : DECIMAL.ToString());
            }
            if (DATE != null && __isset.DATE)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("DATE: ");
                __sb.Append(DATE == null ? "<null>" : DATE.ToString());
            }
            if (TIME != null && __isset.TIME)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("TIME: ");
                __sb.Append(TIME == null ? "<null>" : TIME.ToString());
            }
            if (TIMESTAMP != null && __isset.TIMESTAMP)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("TIMESTAMP: ");
                __sb.Append(TIMESTAMP == null ? "<null>" : TIMESTAMP.ToString());
            }
            if (INTEGER != null && __isset.INTEGER)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("INTEGER: ");
                __sb.Append(INTEGER == null ? "<null>" : INTEGER.ToString());
            }
            if (UNKNOWN != null && __isset.UNKNOWN)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("UNKNOWN: ");
                __sb.Append(UNKNOWN == null ? "<null>" : UNKNOWN.ToString());
            }
            if (JSON != null && __isset.JSON)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("JSON: ");
                __sb.Append(JSON == null ? "<null>" : JSON.ToString());
            }
            if (BSON != null && __isset.BSON)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("BSON: ");
                __sb.Append(BSON == null ? "<null>" : BSON.ToString());
            }
            if (UUID != null && __isset.UUID)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("UUID: ");
                __sb.Append(UUID == null ? "<null>" : UUID.ToString());
            }
            __sb.Append(")");
            return(__sb.ToString());
        }
Example #11
0
 public void Write(TProtocol oprot)
 {
     oprot.IncrementRecursionDepth();
     try
     {
         TStruct struc = new TStruct("LogicalType");
         oprot.WriteStructBegin(struc);
         TField field = new TField();
         if (STRING != null && __isset.@STRING)
         {
             field.Name = "STRING";
             field.Type = TType.Struct;
             field.ID   = 1;
             oprot.WriteFieldBegin(field);
             STRING.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (MAP != null && __isset.MAP)
         {
             field.Name = "MAP";
             field.Type = TType.Struct;
             field.ID   = 2;
             oprot.WriteFieldBegin(field);
             MAP.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (LIST != null && __isset.LIST)
         {
             field.Name = "LIST";
             field.Type = TType.Struct;
             field.ID   = 3;
             oprot.WriteFieldBegin(field);
             LIST.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (ENUM != null && __isset.@ENUM)
         {
             field.Name = "ENUM";
             field.Type = TType.Struct;
             field.ID   = 4;
             oprot.WriteFieldBegin(field);
             ENUM.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (DECIMAL != null && __isset.@DECIMAL)
         {
             field.Name = "DECIMAL";
             field.Type = TType.Struct;
             field.ID   = 5;
             oprot.WriteFieldBegin(field);
             DECIMAL.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (DATE != null && __isset.DATE)
         {
             field.Name = "DATE";
             field.Type = TType.Struct;
             field.ID   = 6;
             oprot.WriteFieldBegin(field);
             DATE.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (TIME != null && __isset.TIME)
         {
             field.Name = "TIME";
             field.Type = TType.Struct;
             field.ID   = 7;
             oprot.WriteFieldBegin(field);
             TIME.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (TIMESTAMP != null && __isset.TIMESTAMP)
         {
             field.Name = "TIMESTAMP";
             field.Type = TType.Struct;
             field.ID   = 8;
             oprot.WriteFieldBegin(field);
             TIMESTAMP.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (INTEGER != null && __isset.INTEGER)
         {
             field.Name = "INTEGER";
             field.Type = TType.Struct;
             field.ID   = 10;
             oprot.WriteFieldBegin(field);
             INTEGER.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (UNKNOWN != null && __isset.UNKNOWN)
         {
             field.Name = "UNKNOWN";
             field.Type = TType.Struct;
             field.ID   = 11;
             oprot.WriteFieldBegin(field);
             UNKNOWN.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (JSON != null && __isset.JSON)
         {
             field.Name = "JSON";
             field.Type = TType.Struct;
             field.ID   = 12;
             oprot.WriteFieldBegin(field);
             JSON.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (BSON != null && __isset.BSON)
         {
             field.Name = "BSON";
             field.Type = TType.Struct;
             field.ID   = 13;
             oprot.WriteFieldBegin(field);
             BSON.Write(oprot);
             oprot.WriteFieldEnd();
         }
         if (UUID != null && __isset.UUID)
         {
             field.Name = "UUID";
             field.Type = TType.Struct;
             field.ID   = 14;
             oprot.WriteFieldBegin(field);
             UUID.Write(oprot);
             oprot.WriteFieldEnd();
         }
         oprot.WriteFieldStop();
         oprot.WriteStructEnd();
     }
     finally
     {
         oprot.DecrementRecursionDepth();
     }
 }
Example #12
0
        public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                var struc = new TStruct("LogicalType");
                await oprot.WriteStructBeginAsync(struc, cancellationToken);

                var field = new TField();
                if (STRING != null && __isset.@STRING)
                {
                    field.Name = "STRING";
                    field.Type = TType.Struct;
                    field.ID   = 1;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await STRING.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (MAP != null && __isset.MAP)
                {
                    field.Name = "MAP";
                    field.Type = TType.Struct;
                    field.ID   = 2;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await MAP.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (LIST != null && __isset.LIST)
                {
                    field.Name = "LIST";
                    field.Type = TType.Struct;
                    field.ID   = 3;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await LIST.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (ENUM != null && __isset.@ENUM)
                {
                    field.Name = "ENUM";
                    field.Type = TType.Struct;
                    field.ID   = 4;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await ENUM.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (DECIMAL != null && __isset.@DECIMAL)
                {
                    field.Name = "DECIMAL";
                    field.Type = TType.Struct;
                    field.ID   = 5;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await DECIMAL.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (DATE != null && __isset.DATE)
                {
                    field.Name = "DATE";
                    field.Type = TType.Struct;
                    field.ID   = 6;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await DATE.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (TIME != null && __isset.TIME)
                {
                    field.Name = "TIME";
                    field.Type = TType.Struct;
                    field.ID   = 7;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await TIME.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (TIMESTAMP != null && __isset.TIMESTAMP)
                {
                    field.Name = "TIMESTAMP";
                    field.Type = TType.Struct;
                    field.ID   = 8;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await TIMESTAMP.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (INTEGER != null && __isset.INTEGER)
                {
                    field.Name = "INTEGER";
                    field.Type = TType.Struct;
                    field.ID   = 10;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await INTEGER.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (UNKNOWN != null && __isset.UNKNOWN)
                {
                    field.Name = "UNKNOWN";
                    field.Type = TType.Struct;
                    field.ID   = 11;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await UNKNOWN.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (JSON != null && __isset.JSON)
                {
                    field.Name = "JSON";
                    field.Type = TType.Struct;
                    field.ID   = 12;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await JSON.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                if (BSON != null && __isset.BSON)
                {
                    field.Name = "BSON";
                    field.Type = TType.Struct;
                    field.ID   = 13;
                    await oprot.WriteFieldBeginAsync(field, cancellationToken);

                    await BSON.WriteAsync(oprot, cancellationToken);

                    await oprot.WriteFieldEndAsync(cancellationToken);
                }
                await oprot.WriteFieldStopAsync(cancellationToken);

                await oprot.WriteStructEndAsync(cancellationToken);
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }
Example #13
0
 public static bool EnumDisplaySettings(string deviceName, ENUM modeNum, ref DEVMODE devMode)
 {
     return EnumDisplaySettings(deviceName, (int)modeNum, ref devMode);
 }
Example #14
0
 public static bool EnumDisplaySettings(string deviceName, ENUM modeNum, ref DEVMODE devMode)
 {
     return(EnumDisplaySettings(deviceName, (int)modeNum, ref devMode));
 }