本文整理汇总了C#中SerializationContext.GetTypeHandler方法的典型用法代码示例。如果您正苦于以下问题:C# SerializationContext.GetTypeHandler方法的具体用法?C# SerializationContext.GetTypeHandler怎么用?C# SerializationContext.GetTypeHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SerializationContext
的用法示例。
在下文中一共展示了SerializationContext.GetTypeHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertTo
public override object ConvertTo(object item, Type sourceType, SerializationContext serializationContext)
{
IDictionary dictionary = (IDictionary) Activator.CreateInstance(sourceType);
ICollection coll = (ICollection)item;
foreach (object colItem in coll)
{
IPropertyData propHandler = serializationContext.GetTypeHandler(colItem.GetType()).FindProperty(Context.ToString());
if (propHandler == null)
{
throw new MissingMemberException("Type: " + item.GetType().Name + " does not have an accessible property: " + Context);
}
dictionary[propHandler.GetValue(colItem)] = colItem;
}
return dictionary;
}
示例2: ConverterUtil
public ConverterUtil(Type forType, SerializationContext context)
{
_handler = context.GetTypeHandler(forType);
}
示例3: ResolveConstructorTypes
/// <summary>
/// Resolves and updates the types of any constructor arguments
/// </summary>
/// <param name="context">serialization context</param>
/// <param name="expression">object expression</param>
protected static void ResolveConstructorTypes(SerializationContext context, ObjectExpression expression)
{
TypeData handler = context.GetTypeHandler(expression.ResultType);
Type[] definedTypes = GetConstructorParameterTypes(handler.ConstructorParameters);
CtorArgTypeResolver resolver = new CtorArgTypeResolver(expression, context, definedTypes);
Type[] resolvedTypes = resolver.ResolveTypes();
for (int i = 0; i < resolvedTypes.Length; i++)
{
if (resolvedTypes[i] != null)
expression.ConstructorArguments[i].ResultType = resolvedTypes[i];
}
}