<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