本文整理汇总了C#中System.Object.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Object.GetValue方法的具体用法?C# Object.GetValue怎么用?C# Object.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Object
的用法示例。
在下文中一共展示了Object.GetValue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindReference
/// <summary>找到所引用的参考字段</summary>
/// <param name="target">目标对象</param>
/// <param name="member">目标对象的成员</param>
/// <param name="value">数值</param>
/// <returns></returns>
MemberInfo FindReference(Object target, MemberInfo member, out Object value)
{
value = null;
if (member == null) return null;
if (String.IsNullOrEmpty(ReferenceName)) return null;
// 考虑ReferenceName可能是圆点分隔的多重结构
MemberInfo mi = null;
Type type = member.DeclaringType;
value = target;
var ss = ReferenceName.Split(".");
for (int i = 0; i < ss.Length; i++)
{
var pi = type.GetPropertyEx(ss[i]);
if (pi != null)
{
mi = pi;
type = pi.PropertyType;
}
else
{
var fi = type.GetFieldEx(ss[i]);
if (fi != null)
{
mi = fi;
type = fi.FieldType;
}
}
// 最后一个不需要计算
if (i < ss.Length - 1)
{
if (mi != null) value = value.GetValue(mi);
}
}
// 目标字段必须是整型
var tc = Type.GetTypeCode(type);
if (tc >= TypeCode.SByte && tc <= TypeCode.UInt64) return mi;
return null;
}
示例2: SetReferenceSize
/// <summary>设置目标对象的引用大小值</summary>
/// <param name="target">目标对象</param>
/// <param name="member"></param>
/// <param name="encoding"></param>
internal void SetReferenceSize(Object target, MemberInfo member, Encoding encoding)
{
Object v = null;
var mi = FindReference(target, member, out v);
if (mi == null) return;
// 获取当前成员(加了特性)的值
var value = target.GetValue(member);
if (value == null) return;
// 尝试计算大小
Int32 size = 0;
if (value is String)
{
if (encoding == null) encoding = Encoding.UTF8;
size = encoding.GetByteCount("" + value);
}
else if (value.GetType().IsArray)
{
size = (value as Array).Length;
}
else if (value is IEnumerable)
{
foreach (var item in value as IEnumerable)
{
size++;
}
}
// 给参考字段赋值
v.SetValue(mi, size - Size);
}
示例3: AreNotEqual
/// <summary>
/// Asserts that two objects are not equal. If they are equal
/// an <see cref="AssertionException"/> is thrown.
/// </summary>
/// <param name="expected">The expected object</param>
/// <param name="actual">The actual object</param>
/// <param name="message">The message to be displayed when the two objects are the same object.</param>
/// <param name="args">Arguments to be used in formatting the message</param>
public static void AreNotEqual(Object[] expected, Object[] actual, string message, params object[] args)
{
bool fail = false;
if (expected != null && actual != null)
{
if (expected.GetLength(0) == actual.GetLength(0))
{
fail = true;
}
if (!fail)
{
int position = 0;
bool same = true;
foreach (object o in expected)
{
if (!o.Equals(actual.GetValue(position)))
{
same = false;
}
position++;
}
if (same)
fail = true;
}
}
else
{
fail = true;
}
if (fail)
{
if (args != null)
Assert.FailSame(expected, actual, message, args);
else
Assert.FailSame(expected, actual, message);
}
}
示例4: getParamsAsString
private static String getParamsAsString(Object [] pParams, String pClassName, String pMethodName)
{
StringBuilder buffer = new StringBuilder();
try
{
if (pParams != null)
{
bool tFistTime = true;
buffer.Append("[");
for (int i = 0; i < pParams.Length; i++)
{
if (!tFistTime)
{
buffer.Append(", ");
}
buffer.Append("" + pParams.GetValue(i));
tFistTime = false;
}
buffer.Append("]");
}
}
catch (Exception externalException)
{
String message = "Unable to get arguments of class=[" + pClassName + "] and method=[" + pMethodName + "]";
throw new NMonitoringException(message,externalException);
}
return buffer.ToString();
}
示例5: WriteObject
private void WriteObject(Object obj)
{
Int32 i = 0;
if (!_cirobj.TryGetValue(obj, out i)) _cirobj.Add(obj, _cirobj.Count + 1);
_Builder.Append('{');
_depth++;
if (_depth > 5) throw new Exception("超过了序列化最大深度 " + 5);
var map = new Dictionary<String, String>();
var t = obj.GetType();
var first = true;
foreach (var pi in t.GetProperties(true))
{
var value = obj.GetValue(pi);
if (NullValue || value != null && !(value is DBNull))
{
if (!first) _Builder.Append(',');
first = false;
var name = pi.Name;
if (LowerCaseName) name = name.ToLower();
WritePair(name, value);
}
}
_Builder.Append('}');
_depth--;
}
示例6: Save
/// <summary>
/// Method to save details to database
/// </summary>
public Boolean Save(Object[,] par, String Command, out String Message)
{
try
{
effectedRows = DPBaseClass.ExecuteNonQuery(Command, par);
if ((TransactionType)(par.GetValue((par.Length / 2) - 1, (par.Length / 2) - 1)) == TransactionType.INSERT)
Message = CustomMessages.INSERT_SUCESS.ToString();
else
Message = CustomMessages.UPDATE_SUCESS.ToString();
if (effectedRows > 0)
return true;
}
catch (Exception ex)
{
DPBaseClass.LogException(ex);
if ((TransactionType)(par.GetValue((par.Length / 2) - 1, (par.Length / 2) - 1)) == TransactionType.INSERT)
Message = CustomMessages.INSERT_FAILED.ToString();
else
Message = CustomMessages.UPDATE_FAILED.ToString();
}
return false;
}
示例7: WriteObject
private Boolean WriteObject(Object value, Type type)
{
var ims = Host.IgnoreMembers;
var ms = GetMembers(type).Where(e => !ims.Contains(e.Name)).ToList();
WriteLog("BinaryWrite类{0} 共有成员{1}个", type.Name, ms.Count);
Host.Hosts.Push(value);
// 获取成员
foreach (var member in ms)
{
var mtype = GetMemberType(member);
Host.Member = member;
var v = value.GetValue(member);
WriteLog(" {0}.{1} {2}", type.Name, member.Name, v);
var name = member.Name;
var att = member.GetCustomAttribute<XmlElementAttribute>();
if (att != null) name = att.ElementName;
// 特殊处理写入名值对
if (!WritePair(name, v))
{
Host.Hosts.Pop();
return false;
}
}
Host.Hosts.Pop();
return true;
}
示例8: CompareData
/// <summary>
///
/// </summary>
/// <param name="ouputList"></param>
/// <param name="targetList"></param>
/// <returns></returns>
protected string CompareData(Hashtable ouputList, Hashtable targetList)
{
Object[] keys = new Object[ouputList.Count];
//Array keys = new Array; // = null;
ouputList.Keys.CopyTo(keys, 0);
//ICollection keys = ouputList.Keys;
string outputString = string.Empty;
for (int i = 0; i < keys.Length; i++)
{
if (keys.GetValue(i).ToString().IndexOf("Date") != -1)
{
if (!Convert.ToDateTime(targetList[keys.GetValue(i)]).Date.Equals(Convert.ToDateTime(ouputList[keys.GetValue(i)]).Date))
{
outputString = outputString + "Source Value:" + ouputList[keys.GetValue(i)].ToString() + "and Target Value: " + targetList[keys.GetValue(i)].ToString() + Environment.NewLine;
}
}
else
{
if (!targetList[keys.GetValue(i)].ToString().Equals(ouputList[keys.GetValue(i)].ToString()))
{
outputString = outputString + "Source Value:" + ouputList[keys.GetValue(i)].ToString() + " and Target Value: " + targetList[keys.GetValue(i)].ToString() + Environment.NewLine;
}
}
}
return outputString;
}
示例9: Write
/// <summary>写入对象</summary>
/// <param name="value">目标对象</param>
/// <param name="type">类型</param>
/// <returns></returns>
public override Boolean Write(Object value, Type type)
{
if (value == null) return false;
// 不支持基本类型
if (Type.GetTypeCode(type) != TypeCode.Object) return false;
var ms = GetMembers(type);
WriteLog("JsonWrite类{0} 共有成员{1}个", type.Name, ms.Count);
Host.Hosts.Push(value);
// 获取成员
foreach (var member in ms)
{
if (IgnoreMembers != null && IgnoreMembers.Contains(member.Name)) continue;
var mtype = GetMemberType(member);
Host.Member = member;
var v = value.GetValue(member);
WriteLog(" {0}.{1} {2}", type.Name, member.Name, v);
if (!Host.Write(v, mtype))
{
Host.Hosts.Pop();
return false;
}
}
Host.Hosts.Pop();
return true;
}