?? propertypackage.cs
字號:
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace JeasonZhao.Sms.SGIP.Command
{
public enum PackageDataTypes
{
Uint,
String,
Byte,
}
public class PropertyPackage
{
#region members
private PropertyInfo m_pInfo = null;
private string m_strValue = null;
private PackageDataTypes m_PackageDataType = PackageDataTypes.String;
private uint m_IntValue = 0;
private SmsFieldAttribute m_attribute = null;
private uint m_nLength = 0;
private BaseCommand m_command = null;
#endregion
public PropertyPackage(BaseCommand cmd, PropertyInfo pInfo, SmsFieldAttribute smsAttr)
{
if (null == pInfo || null == smsAttr)
{
return;
}
m_pInfo = pInfo;
m_attribute = smsAttr;
m_command = cmd;
ReBuildPackage();
}
#region Get Functions
public uint Length
{
get { return m_nLength; }
}
public SmsFieldAttribute Attribute
{
get { return m_attribute; }
}
public PropertyInfo Property
{
get { return m_pInfo; }
}
public PackageDataTypes PackageDataType
{
get { return m_PackageDataType; }
}
public string StringValue
{
get { return m_strValue; }
}
public uint UIntValue
{
get { return m_IntValue; }
}
public override string ToString()
{
return null == m_pInfo ? "[非法節點]" :
m_pInfo.Name + "(" +
m_PackageDataType + ")=" +
(m_PackageDataType != PackageDataTypes.String ? "" + m_IntValue : "" + m_strValue);
}
#endregion
#region Function
public bool IsProperty(String str)
{
return null != m_pInfo && null != str &&
m_pInfo.Name.Trim().ToLower().Equals(str.Trim().ToLower());
}
public void ReBuildPackage()
{
if (m_pInfo.PropertyType != typeof(string))
{
Type type = m_pInfo.PropertyType;
UInt32 nValue = Convert.ToUInt32(m_pInfo.GetValue(m_command, null));
m_IntValue = nValue;
m_PackageDataType = PackageDataTypes.Uint;
m_nLength = 4;
if ((type == typeof(Enum) || type.BaseType == typeof(Enum)) &&
type.GetFields() != null && type.GetFields().Length > 0)
{
if (type.GetFields()[0].FieldType == typeof(byte))
{
m_nLength = 1;
m_PackageDataType = PackageDataTypes.Byte;
}
}
else if (type == typeof(byte))
{
m_nLength = 1;
m_PackageDataType = PackageDataTypes.Byte;
}
}
else
{
string sValue = m_pInfo.GetValue(m_command, null) as string;
if (null == sValue)
{
sValue = "";
}
m_PackageDataType = PackageDataTypes.String;
m_strValue = sValue;
m_nLength = (uint)m_attribute.Length;
m_nLength = (m_nLength <= 0 || m_nLength >1024? (uint)System.Text.Encoding.Default.GetByteCount(sValue) : m_nLength);
System.Console.WriteLine(m_pInfo.Name + "-["+sValue+"]--" + m_nLength);
}
}
#endregion
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -