public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
 {
     if (destinationType == null)
     {
         throw new System.ArgumentNullException("destinationType\uFFFD");
     }
     if (culture == System.Globalization.CultureInfo.InvariantCulture)
     {
         return(base.ConvertTo(context, culture, value, destinationType));
     }
     if ((destinationType == typeof(string)) && (value != null))
     {
         System.Type         type         = System.Enum.GetUnderlyingType(EnumType);
         System.IConvertible iconvertible = value as System.IConvertible;
         if ((iconvertible != null) && (value.GetType() != type))
         {
             value = iconvertible.ToType(type, culture);
         }
         if (!EnumType.IsDefined(typeof(System.FlagsAttribute), false) && !System.Enum.IsDefined(EnumType, value))
         {
             object[] objArr = new object[] {
                 value.ToString(),
                      EnumType.Name
             };
             throw new System.ArgumentException(System.String.Format(System.Globalization.CultureInfo.CurrentCulture, "ArgumentException_InvalidEnumValue", objArr), "value");
         }
         return(customValueNames[(int)value]);
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
 /// <summary>
 /// Convertiert zu dem Typ oder gibt
 /// den Standartwehrt zurück.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static T ToOrDefault <T>
     (this System.IConvertible obj)
 {
     try {
         return(To <T>(obj));
     } catch {
         return(default(T));
     }
 }
Esempio n. 3
0
        public void test()
        {
            Double myDouble = 3;
            double other    = myDouble;

            other.GetHashCode();
            System.IConvertible myConvertible = other;
            Object myObject = other;
        }
Esempio n. 4
0
        public void test()
        {
            Boolean myBool = true;
            bool    other  = myBool;

            other.GetHashCode();
            System.IConvertible myConvertible = other;
            Object myObject = other;
        }
Esempio n. 5
0
        public void test()
        {
            Char myChar = 'a';
            char other  = myChar;

            other.GetHashCode();
            System.IConvertible myConvertible = other;
            Object myObject = other;
        }
 /// <summary>
 /// Convertiert zu dem Typ oder übergibt
 /// den Standartwehrt in der newObj Variable.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="obj"></param>
 /// <param name="newObj"></param>
 /// <returns>Gibt an ob die KOnvertierung erfolgreich war</returns>
 public static bool ToOrDefault <T>
     (this System.IConvertible obj,
     out T newObj)
 {
     try {
         newObj = To <T>(obj);
         return(true);
     } catch {
         newObj = default(T);
         return(false);
     }
 }
        // GET: Usuario/Delete/5
        //public ActionResult Delete(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    USUARIO uSUARIO = db.USUARIO.Find(id);
        //    if (uSUARIO == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(uSUARIO);
        //}

        // POST: Usuario/Delete/5
        //[HttpPost, ActionName("Delete")]
        //[ValidateAntiForgeryToken]
        //public ActionResult DeleteConfirmed(int id)
        //{

        //    USUARIO uSUARIO = db.USUARIO.Find(id);
        //    db.USUARIO.Remove(uSUARIO);
        //    db.SaveChanges();
        //    return RedirectToAction("Index");
        //}

        #endregion

        #region Util
        protected UsuarioModel viewParaEntidade(System.IConvertible id, FormCollection campos)
        {
            string       _senha = "";
            UsuarioModel _item  = new UsuarioModel();

            _item.USU_NM = campos["USU_NM"];
            _item.USU_LG = campos["USU_LG"];
            _senha       = campos["USU_SN"].ToMD5();
            _item.USU_SN = _senha;//.ToMD5();
            _item.USU_ST = Convert.ToBoolean(campos["USU_ST"] == "true,false");

            return(_item);
        }
 /// <summary>
 /// Convertiert zu dem Typ.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static T To <T>(this System.IConvertible obj)
 {
     return((T)Convert.ChangeType(obj, typeof(T)));
 }
Esempio n. 9
0
 private void SerializeValueInternal(object o, System.Text.StringBuilder sb, int depth, System.Collections.Hashtable objectsInUse, JavaScriptSerializer.SerializationFormat serializationFormat)
 {
     if (o == null || System.DBNull.Value.Equals(o))
     {
         sb.Append("null");
     }
     else
     {
         string text = o as string;
         if (text != null)
         {
             JavaScriptSerializer.SerializeString(text, sb);
         }
         else if (o is char)
         {
             if ((char)o == '\0')
             {
                 sb.Append("null");
             }
             else
             {
                 JavaScriptSerializer.SerializeString(o.ToString(), sb);
             }
         }
         else if (o is bool)
         {
             JavaScriptSerializer.SerializeBoolean((bool)o, sb);
         }
         else if (o is System.DateTime)
         {
             JavaScriptSerializer.SerializeDateTime((System.DateTime)o, sb, serializationFormat);
         }
         else if (o is System.TimeSpan)
         {
             JavaScriptSerializer.SerializeDateTime(System.Convert.ToDateTime(o.ToString()), sb, serializationFormat);
         }
         else if (o is ulong)
         {
             JavaScriptSerializer.SerializeCuid((ulong)o, sb);
         }
         else if (o is long && serializationFormat == JavaScriptSerializer.SerializationFormat.JavaScript)
         {
             JavaScriptSerializer.SerializeCuidForSqlServer((long)o, sb);
         }
         else if (o is System.Guid)
         {
             JavaScriptSerializer.SerializeGuid((System.Guid)o, sb);
         }
         else if (o is RawText)
         {
             sb.Append(((RawText)o).Value);
         }
         else
         {
             Uri uri = o as Uri;
             if (uri != null)
             {
                 JavaScriptSerializer.SerializeUri(uri, sb);
             }
             else if (o is double)
             {
                 sb.Append(((double)o).ToString("r", System.Globalization.CultureInfo.InvariantCulture));
             }
             else if (o is float)
             {
                 sb.Append(((float)o).ToString("r", System.Globalization.CultureInfo.InvariantCulture));
             }
             else if (o.GetType().IsPrimitive || o is decimal)
             {
                 System.IConvertible convertible = o as System.IConvertible;
                 if (convertible == null)
                 {
                     throw new System.InvalidOperationException();
                 }
                 sb.Append(convertible.ToString(System.Globalization.CultureInfo.InvariantCulture));
             }
             else
             {
                 System.Type type = o.GetType();
                 if (type.IsEnum)
                 {
                     sb.Append((int)o);
                 }
                 else
                 {
                     try
                     {
                         if (objectsInUse == null)
                         {
                             objectsInUse = new System.Collections.Hashtable(new JavaScriptSerializer.ReferenceComparer());
                         }
                         else if (objectsInUse.ContainsKey(o))
                         {
                             throw new System.InvalidOperationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "A circular reference was detected while serializing an object of type '{0}'.", new object[]
                             {
                                 type.FullName
                             }));
                         }
                         objectsInUse.Add(o, null);
                         System.Collections.IDictionary dictionary = o as System.Collections.IDictionary;
                         if (dictionary != null)
                         {
                             this.SerializeDictionary(dictionary, sb, depth, objectsInUse, serializationFormat);
                         }
                         else
                         {
                             System.Collections.IEnumerable enumerable = o as System.Collections.IEnumerable;
                             if (enumerable != null)
                             {
                                 this.SerializeEnumerable(enumerable, sb, depth, objectsInUse, serializationFormat);
                             }
                             else
                             {
                                 this.SerializeCustomObject(o, sb, depth, objectsInUse, serializationFormat);
                             }
                         }
                     }
                     finally
                     {
                         if (objectsInUse != null)
                         {
                             objectsInUse.Remove(o);
                         }
                     }
                 }
             }
         }
     }
 }
    private static bool PopData(ref ByteArray buf, ref object Data, FieldInfo Info)
    {
        System.IConvertible convertible = Data as System.IConvertible;

        if (convertible != null)
        {
            switch (convertible.GetTypeCode())
            {
            case TypeCode.Boolean:
                Data = GetBufToBool(ref buf);
                return(true);

            case TypeCode.SByte:
                Data = GetBufToSByte(ref buf);
                return(true);

            case TypeCode.Byte:
                Data = GetBufToByte(ref buf);
                return(true);

            case TypeCode.Int16:
                Data = GetBufToShort(ref buf);
                return(true);

            case TypeCode.UInt16:
                Data = GetBufToWord(ref buf);
                return(true);

            case TypeCode.Int32:
                Data = GetBufToInt(ref buf);
                return(true);

            case TypeCode.UInt32:
                Data = GetBufToDWord(ref buf);
                return(true);

            case TypeCode.UInt64:
                Data = GetBufToULong(ref buf);
                return(true);

            case TypeCode.Single:
                Data = GetBufToFloat(ref buf);
                return(true);

            case TypeCode.Double:
                Data = GetBufToDouble(ref buf);
                return(true);

            case TypeCode.DateTime:
                Data = DateTime.FromOADate(GetBufToDouble(ref buf));
                return(true);

            case TypeCode.String:
                int len = GetTypeSize(Info);
                Data = GetBufToStr(ref buf, len, true);
                return(true);

            default:
                return(false);
            }
        }

        return(false);
    }