/// <summary>
        ///   Reads the specified object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">Obj has other than ID type.</exception>
        public static ID Read(ClrObject obj)
        {
            if (obj.IsNullObj)
            {
                return(null);
            }

            obj.ReEvaluateType();

            if (obj.Type == null)
            {
                return(null);
            }

            if (!obj.Type.Name.Equals(typeof(ID).FullName, StringComparison.Ordinal))
            {
                throw new ArgumentException("Obj has wrong " + obj.Type.Name + " instead of ID");
            }
            ClrObject guidObject = obj.GetValueFld("_guid", false);

            if (guidObject.IsNullObj)
            {
                return(null);
            }
            return(new ID(ClrObjectValuesReader.ReadGuidValue(guidObject)));
        }
Beispiel #2
0
        public object Read(ClrObject obj, string fldName)
        {
            ClrObject guidObject = obj.GetValueFld(fldName, false);

            // TOOD: Ensure this code works.
            return(ClrObjectValuesReader.ReadGuidValue(guidObject));
        }
        protected virtual bool Parse([CanBeNullObject] ClrObject clrObject, out string text)
        {
            text = string.Empty;
            if (clrObject.IsNullObj || (clrObject.Type == null))
            {
                return(false);
            }

            var elementType = clrObject.Type.ElementType;
            var type        = clrObject.Type;

            switch (elementType)
            {
            case ClrElementType.String:
            {
                text = type.GetValue(clrObject.Address) as string;
                break;
            }

            case ClrElementType.Int32:
            {
                text = ((int)type.GetValue(clrObject.Address)).ToString();

                break;
            }

            case ClrElementType.Int64:
            {
                text = ((long)type.GetValue(clrObject.Address)).ToString();
                break;
            }

            case ClrElementType.Boolean:
            {
                text = ((bool)type.GetValue(clrObject.Address)).ToString();
                break;
            }

            case ClrElementType.Double:
            {
                text = ((double)type.GetValue(clrObject.Address)).ToString();
                break;
            }

            case ClrElementType.UInt64:
            {
                text = ((ulong)type.GetValue(clrObject.Address)).ToString();
                break;
            }

            case ClrElementType.Struct:
            {
                if (string.Equals(type.Name, typeof(Guid).FullName))
                {
                    text = ClrObjectValuesReader.ReadGuidValue(clrObject).ToString();
                    break;
                }

                if (string.Equals(type.Name, typeof(DateTime).FullName))
                {
                    text = DateTimeReader.FromObjToDate(clrObject).ToString();
                    break;
                }

                if (string.Equals(type.Name, typeof(TimeSpan).FullName))
                {
                    text = TimeSpanReader.Read(clrObject).ToString();
                    break;
                }

                break;
            }
            }

            return(string.IsNullOrEmpty(text));
        }