It's good to use. The request is converted to an entity method and a method that determines that all parameters of an entity cannot be empty

Source: Internet
Author: User

<summary>
Model-assisted processing classes
2016-04-18
</summary>
public class Modelhelper
{
<summary>
Turning data into a model
2016-04-18 basic Data type: Int32,decimal
</summary>
<typeparam name= "T" ></typeparam>
<param name= "T" ></param>
public static void converttomodel<t> (ref T T)
{
System.reflection.propertyinfo[] Properties = T.gettype (). GetProperties (System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
type[] Temparr = new type[] {typeof (Int32), typeof (Decimal)};
Object tempobject = null;
for (Int32 i = 0; i < properties. Length; i++)
{
if (requtils.formstring (properties[i). NAME)! = NULL | | Properties[i]. PropertyType.Name.ToLower () = = "Httpfilecollection")
{
Switch (Properties[i]. PropertyType.Name.ToLower ())
{
Case "Int32": Tempobject = Int32.Parse (string. Format ("0{0}", Requtils.formstring (Properties[i]. Name)); Break
Case "decimal": Tempobject = Decimal. Parse (String. Format ("0{0}", Requtils.formstring (Properties[i]. Name)); Break
Case "Httpfilecollection": Tempobject = System.Web.HttpContext.Current.Request.Files; Break
Default
Tempobject = string. Format ("{0}", Requtils.formstring (properties[i). Name));
Break
}
Properties[i]. SetValue (t, tempobject, NULL);
}
}
}
<summary>
Whether the entity is empty
</summary>
<param name= "Model" ></param>
<returns></returns>
public bool Modelisnotnull (object model)
{
bool IsTrue = true;
Type type = model. GetType ();
var flags = Getonlyproperty ();
var list = type. GetProperties (Flags). ToList ();
foreach (var p in list)
{
if (Iscolumn (p))
{
Object value = P.getvalue (model, null)?? "";
if (string. Isnullorwhitespace (value. ToString ()))
{
IsTrue = false;
Break
}
}
}
return istrue;
}
Private BindingFlags Getonlyproperty ()
{
return BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance;
}
private bool Iscolumn (PropertyInfo info)
{
object[] Objs = info. GetCustomAttributes (typeof (Attribute), true);
Return OBJS. Length = = 0;
}
<summary>
Get Action Tip Translation
</summary>
<param name= "Key" ></param>
<param name= "LAN" ></param>
<returns></returns>
public static string Gettans (string key, String lan = "")
{
Try
{
if (string. Isnullorwhitespace (LAN))
{
LAN = "CN";
}
if (LAN. ToLower (). Contains ("cn") | | Lan. ToLower (). Contains ("zh"))
{
lan = "zh";
}
String className = "Pageinfo_" + lan;
var globalresourceobject = Httpcontext.getglobalresourceobject (ClassName, key);
if (globalresourceobject! = null)
return globalresourceobject.tostring () = = ""? Key:globalResourceObject.ToString ();
Else
{
Return key;
}
}
Catch
{
Return key;
}
}
}

Useful request conversion to entity methods and methods to determine that all parameters of an entity cannot be empty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.