GetValue() private method

private GetValue ( ) : Object
return Object
Example #1
0
        public bool HasFlag(Enum value)
        {
            var thisValue = (int)GetValue();
            var intValue  = (int)value.GetValue();

            return((thisValue & intValue) == intValue);
        }
Example #2
0
        internal void SetValue(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            Enum e = value as Enum;

            if (e != null)
            {
                value = e.GetValue();
            }

            Type vtype = GetValueType();

            try
            {
                Function f = vtype.m_unbox;
                if (f != null)
                {
                    object v = f.call(null, value);
                    avm.set_m_value(this, v);
                    return;
                }

                avm.set_m_value(this, value);
            }
            catch (Exception)
            {
                throw new InvalidCastException("Value type is " + value.GetType()
                                               + ", but enum value type is " + vtype);
            }
        }
Example #3
0
        //| <include path='docs/doc[@for="Enum.Equals"]/*' />
        public override bool Equals(Object obj)
        {
            Enum that = obj as Enum;

            if (that == null || this.GetType() != obj.GetType())
            {
                return(false);
            }
            return(this.GetValue().Equals(that.GetValue()));
        }
        public bool HasFlag(Enum flag)
        {
            if (!base.GetType().IsEquivalentTo(flag.GetType()))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EnumTypeDoesNotMatch", new object[] { flag.GetType(), base.GetType() }));
            }
            ulong num = ToUInt64(flag.GetValue());

            return((ToUInt64(this.GetValue()) & num) == num);
        }
Example #5
0
        public override bool Equals(object o)
        {
            object v = GetValue();

            if (Equals(v, o))
            {
                return(true);
            }
            Enum e = o as Enum;

            if (e == null)
            {
                return(false);
            }
            if (e.GetType() != GetType())
            {
                return(false);
            }
            return(Equals(v, e.GetValue()));
        }
Example #6
0
 public bool HasFlag(Enum value)
 {
     var thisValue = (int)GetValue();
     var intValue = (int)value.GetValue();
     return (thisValue & intValue) == intValue;
 }
Example #7
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        public void InitDB()
        {
            try
            {

                string CommandText = "SELECT COUNT(*) as cnt FROM sqlite_master where type='table' and name='{0}'";
                object count = this.SqliteHelper.ExecuteScalar(CommandType.Text, String.Format(CommandText, "cards"));
                if (count == null || count.ToString() == "0")
                {
                    CommandText = "CREATE TABLE [cards] (kdt integer,epc nvarchar(200),dt integer,flag int,PRIMARY KEY(kdt,epc))";
                    int x = this.SqliteHelper.ExecuteNonQuery(CommandType.Text, CommandText);
                }

                CommandText = "SELECT COUNT(*) as cnt FROM sqlite_master where type='table' and name='{0}'";
                count = this.SqliteHelper.ExecuteScalar(CommandType.Text, String.Format(CommandText, "WorkTimeList"));
                if (count == null || count.ToString() == "0")
                {
                    CommandText = "CREATE TABLE [WorkTimeList] (ID varchar(32),LatestTime integer,FromTime integer,ToTime integer,Flag int ,PRIMARY KEY(ID,LatestTime))";
                    this.SqliteHelper.ExecuteNonQuery(CommandType.Text, CommandText);
                }

                CommandText = "SELECT COUNT(*) as cnt FROM sqlite_master where type='table' and name='{0}';";
                count = this.SqliteHelper.ExecuteScalar(CommandType.Text, String.Format(CommandText, "params"));
                if (count == null || count.ToString() == "0")
                {
                    CommandText = "CREATE TABLE [params] (pkey nvarchar(200),pvalue nvarchar(200),PRIMARY KEY(pkey))";
                    this.SqliteHelper.ExecuteNonQuery(CommandType.Text, CommandText);

                    CommandText = "";
                    CfgAttribute cfgAttr = null;

                    //Array Arrays = Enum.GetValues(typeof(ConfigParams));

                    ///// <summary>
                    ///// 采集器编号
                    ///// </summary>
                    //[Cfg("1", "^[a-zA-Z_0-9]+$", RegexOptions.None)]
                    //DeviceNo,

                    ///// <summary>
                    ///// 循环周期(卡循环使用一次最少用时,单位:分钟)
                    ///// </summary>
                    //[Cfg("90", @"\d+$", RegexOptions.None)]
                    //CycInterval,

                    ///// <summary>
                    ///// 采集器功能类型
                    ///// </summary>
                    //[Cfg("-1", "*", RegexOptions.None)]
                    //DeviceFuncType

                    Array Arrays = new Enum[] {
                        //采集器编号
                        ConfigParams.DeviceNo,
                        //循环周期(卡循环使用一次最少用时,单位:分钟)
                        ConfigParams.CycInterval,
                        //采集器功能类型
                        ConfigParams.DeviceFuncType
                        };

                    for (int i = 0; i < Arrays.Length; i++)
                    {
                        ConfigParams cp = (ConfigParams)Arrays.GetValue(i);
                        cfgAttr = CfgAttribute.GetAttribute<CfgAttribute>(cp);
                        CommandText += String.Format("insert into [params] (pkey,pvalue) values('{0}','{1}');", cp.ToString(), cfgAttr.DefaultValue);
                    }
                    this.SqliteHelper.ExecuteNonQuery(CommandType.Text, CommandText);
                }

            }
            catch (Exception ex)
            {
                LogManager.WriteLog(Framework.Libs.Common.LogFile.Error, ex.Message);
                throw ex;
            }
        }
Example #8
0
        internal static string Format(Type enumType, object value, string format)
        {
            if (enumType == null)
            {
                throw new ArgumentNullException("enumType");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }

            if (!enumType.IsEnum)
            {
                throw new ArgumentException("Type provided must be an Enum.");
            }

            Type vType          = value.GetType();
            Type underlyingType = GetUnderlyingType(enumType);

            if (vType.IsEnum)
            {
                if (vType != enumType)
                {
                    throw new ArgumentException(string.Format("Object must be the same type as the enum. The type" +
                                                              " passed in was {0}; the enum type was {1}.",
                                                              vType.FullName, enumType.FullName));
                }
            }
            else if (vType != underlyingType)
            {
                throw new ArgumentException(string.Format("Enum underlying type and the object must be the same type" +
                                                          " or object. Type passed in was {0}; the enum underlying" +
                                                          " type was {1}.", vType.FullName, underlyingType.FullName));
            }

            if (format.Length != 1)
            {
                throw new FormatException("Format String can be only \"G\",\"g\",\"X\"," +
                                          "\"x\",\"F\",\"f\",\"D\" or \"d\".");
            }

            Enum e = value as Enum;

            if (e != null)
            {
                value = e.GetValue();
            }

            char   formatChar = format[0];
            string retVal;

            if ((formatChar == 'G' || formatChar == 'g'))
            {
                EnumInfo info = enumType.EnumInfo;
                if (info == null)
                {
                    throw new ArgumentException("enumInfo is null");
                }
                if (!info.flags)
                {
                    retVal = GetName(enumType, value);
                    if (retVal == null)
                    {
                        retVal = value.ToString();
                    }

                    return(retVal);
                }

                formatChar = 'f';
            }

            if ((formatChar == 'f' || formatChar == 'F'))
            {
                return(FormatFlags(enumType, value));
            }

            switch (formatChar)
            {
            case 'X':
                retVal = FormatHex(enumType, value, true);
                break;

            case 'x':
                retVal = FormatHex(enumType, value, false);
                break;

            case 'D':
            case 'd':
                if (underlyingType == typeof(ulong))
                {
                    ulong ulongValue = Convert.ToUInt64(value);
                    retVal = ulongValue.ToString();
                }
                else
                {
                    long longValue = Convert.ToInt64(value);
                    retVal = longValue.ToString();
                }
                break;

            default:
                throw new FormatException("Format String can be only \"G\",\"g\",\"X\"," +
                                          "\"x\",\"F\",\"f\",\"D\" or \"d\".");
            }
            return(retVal);
        }