本文整理汇总了C#中DataType.ToActualType方法的典型用法代码示例。如果您正苦于以下问题:C# DataType.ToActualType方法的具体用法?C# DataType.ToActualType怎么用?C# DataType.ToActualType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataType
的用法示例。
在下文中一共展示了DataType.ToActualType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadMemberInfo
//.........这里部分代码省略.........
string[] paramTypeStrings = new string[paramCount];
for (int i = 0; i < paramCount; i++)
paramTypeStrings[i] = this.reader.ReadString();
Type declaringType = this.ResolveType(declaringTypeString);
Type propertyType = this.ResolveType(propertyTypeString);
Type[] paramTypes = new Type[paramCount];
for (int i = 0; i < paramCount; i++)
paramTypes[i] = this.ResolveType(paramTypeStrings[i]);
PropertyInfo property = declaringType.GetProperty(
propertyName,
isStatic ? ReflectionHelper.BindStaticAll : ReflectionHelper.BindInstanceAll,
null,
propertyType,
paramTypes,
null);
result = property;
}
else if (dataType == DataType.MethodInfo)
{
bool isStatic = this.reader.ReadBoolean();
string declaringTypeString = this.reader.ReadString();
string methodName = this.reader.ReadString();
int paramCount = this.reader.ReadInt32();
string[] paramTypeStrings = new string[paramCount];
for (int i = 0; i < paramCount; i++)
paramTypeStrings[i] = this.reader.ReadString();
Type declaringType = this.ResolveType(declaringTypeString);
Type[] paramTypes = new Type[paramCount];
for (int i = 0; i < paramCount; i++)
paramTypes[i] = this.ResolveType(paramTypeStrings[i]);
MethodInfo method = declaringType.GetMethod(methodName, isStatic ? ReflectionHelper.BindStaticAll : ReflectionHelper.BindInstanceAll, null, paramTypes, null);
result = method;
}
else if (dataType == DataType.ConstructorInfo)
{
bool isStatic = this.reader.ReadBoolean();
string declaringTypeString = this.reader.ReadString();
int paramCount = this.reader.ReadInt32();
string[] paramTypeStrings = new string[paramCount];
for (int i = 0; i < paramCount; i++)
paramTypeStrings[i] = this.reader.ReadString();
Type declaringType = this.ResolveType(declaringTypeString);
Type[] paramTypes = new Type[paramCount];
for (int i = 0; i < paramCount; i++)
paramTypes[i] = this.ResolveType(paramTypeStrings[i]);
ConstructorInfo method = declaringType.GetConstructor(isStatic ? ReflectionHelper.BindStaticAll : ReflectionHelper.BindInstanceAll, null, paramTypes, null);
result = method;
}
else if (dataType == DataType.EventInfo)
{
bool isStatic = this.reader.ReadBoolean();
string declaringTypeString = this.reader.ReadString();
string eventName = this.reader.ReadString();
Type declaringType = this.ResolveType(declaringTypeString);
EventInfo e = declaringType.GetEvent(eventName, isStatic ? ReflectionHelper.BindStaticAll : ReflectionHelper.BindInstanceAll);
result = e;
}
else
throw new ApplicationException(string.Format("Invalid DataType '{0}' in ReadMemberInfo method.", dataType));
}
#endregion
else if (this.dataVersion >= 2)
{
if (dataType == DataType.Type)
{
string typeString = this.reader.ReadString();
result = this.ResolveType(typeString, objId);
}
else
{
string memberString = this.reader.ReadString();
result = this.ResolveMember(memberString, objId);
}
}
}
catch (Exception e)
{
result = null;
this.SerializationLog.WriteError(
"An error occurred in deserializing MemberInfo object Id {0} of type '{1}': {2}",
objId,
Log.Type(dataType.ToActualType()),
Log.Exception(e));
}
// Prepare object reference
this.idManager.Inject(result, objId);
return result;
}
示例2: ReadMemberInfo
/// <summary>
/// Reads a <see cref="System.Reflection.MemberInfo"/>, including referenced objects.
/// </summary>
/// <param name="dataType">The <see cref="Duality.Serialization.DataType"/> of the object to read.</param>
/// <returns>The object that has been read.</returns>
protected MemberInfo ReadMemberInfo(DataType dataType)
{
string objIdString = this.reader.GetAttribute("id");
uint objId = objIdString == null ? 0 : XmlConvert.ToUInt32(objIdString);
MemberInfo result;
try
{
if (dataType == DataType.Type)
{
string typeString = this.reader.GetAttribute("value");
result = this.ResolveType(typeString, objId);
}
else
{
string memberString = this.reader.GetAttribute("value");
result = this.ResolveMember(memberString, objId);
}
}
catch (Exception e)
{
result = null;
this.SerializationLog.WriteError(
"An error occurred in deserializing MemberInfo object Id {0} of type '{1}': {2}",
objId,
Log.Type(dataType.ToActualType()),
Log.Exception(e));
}
// Prepare object reference
this.idManager.Inject(result, objId);
return result;
}