本文整理汇总了C#中TypeInfo.GetMember方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInfo.GetMember方法的具体用法?C# TypeInfo.GetMember怎么用?C# TypeInfo.GetMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.GetMember方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public bool Read(DeserializationContext context, out Object outVal, uint id, TypeInfo typeInfo)
{
bool ret = true;
// create instance
Object obj = null;
SerializationInfo info = null;
if(typeInfo.IsISerializable)
{
info = typeInfo.GetSerializationInfo();
// create instance
obj = FormatterServices.GetUninitializedObject(typeInfo.ObjectType);
// read and set values
for(uint i = 0; i < typeInfo.NumMembers; i++)
{
// first get inlined data
Object memberValue;
if(typeInfo.GetTypeTag(i) == BinaryTypeTag.PrimitiveType)
{
memberValue = ReadPrimitiveType(context, typeInfo.GetTypeSpecification(i).GetPrimitiveType());
}
else
{
ret &= ReadValue(context, out memberValue);
}
// set value
String field = typeInfo.GetFieldName(i);
if(memberValue is DelayedReferenceHolder)
{
// this is a reference
DelayedReferenceHolder holder = (DelayedReferenceHolder) memberValue;
context.Manager.RecordDelayedFixup(id, field, holder.ReferenceId);
}
else
{
// this is a real value
info.AddValue(field, memberValue, typeInfo.GetTypeSpecification(i).GetObjectType(context));
}
}
context.Manager.RegisterObject(obj, id, info);
}
else
{
// create instance
obj = FormatterServices.GetUninitializedObject(typeInfo.ObjectType);
// read and set values
for(uint i = 0; i < typeInfo.NumMembers; i++)
{
// first get inlined data
Object memberValue;
if(typeInfo.GetTypeTag(i) == BinaryTypeTag.PrimitiveType)
{
memberValue = ReadPrimitiveType(context, typeInfo.GetTypeSpecification(i).GetPrimitiveType());
}
else
{
ret &= ReadValue(context, out memberValue);
}
// set value
MemberInfo field = typeInfo.GetMember(i);
if(memberValue is DelayedReferenceHolder)
{
// this is a reference
DelayedReferenceHolder holder = (DelayedReferenceHolder) memberValue;
context.Manager.RecordFixup(id, field, holder.ReferenceId);
}
else
{
// this is a real value
if(field is FieldInfo)
{
FieldInfo fi = (FieldInfo) field;
fi.SetValue(obj, memberValue);
}
// TODO: i'm not sure if I have to cover that case, too!
// I just noticed that Mono does this
// else if(field is PropertyInfo)
// {
// PropertyInfo pi = (PropertyInfo) field;
// pi.SetValue();
else
{
throw new SerializationException("unknown memeber type:"+field.GetType());
}
}
}
context.Manager.RegisterObject(obj, id);
}
outVal = obj;
return ret;
}