本文整理汇总了C#中ITypeDescriptor.GetPreferedType方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeDescriptor.GetPreferedType方法的具体用法?C# ITypeDescriptor.GetPreferedType怎么用?C# ITypeDescriptor.GetPreferedType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeDescriptor
的用法示例。
在下文中一共展示了ITypeDescriptor.GetPreferedType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitFromItemDescriptor
void InitFromItemDescriptor(ITypeDescriptor descriptor)
{
if (descriptor == _itemDescriptor && _name != null) return;
_itemDescriptor = descriptor;
if ((descriptor.Name?.Length ?? 0) == 0) return;
_itemType = _itemDescriptor.GetPreferedType();
Sealed = _itemDescriptor.Sealed;
Name = $"List<{_itemDescriptor.Name}>";
}
示例2: InitFromKeyValueDescriptors
void InitFromKeyValueDescriptors(ITypeDescriptor keyDescriptor, ITypeDescriptor valueDescriptor)
{
if (_keyDescriptor == keyDescriptor && _valueDescriptor == valueDescriptor && _name != null) return;
_keyDescriptor = keyDescriptor;
_valueDescriptor = valueDescriptor;
if ((_keyDescriptor.Name?.Length ?? 0) == 0 || (_valueDescriptor.Name?.Length ?? 0) == 0) return;
_keyType = _keyDescriptor.GetPreferedType();
_valueType = _valueDescriptor.GetPreferedType();
Sealed = _keyDescriptor.Sealed && _valueDescriptor.Sealed;
Name = $"Dictionary<{_keyDescriptor.Name}, {_valueDescriptor.Name}>";
}
示例3: InitFromItemDescriptor
void InitFromItemDescriptor(ITypeDescriptor descriptor)
{
if (descriptor == _itemDescriptor) return;
_itemDescriptor = descriptor;
_itemType = _itemDescriptor.GetPreferedType();
Sealed = _itemDescriptor.Sealed;
Name = "List<" + _itemDescriptor.Name + ">";
}
示例4: BuildComplexSaver
Action<AbstractBufferedWriter, ITypeBinarySerializerContext, object> BuildComplexSaver(ITypeDescriptor descriptor)
{
var method = ILBuilder.Instance.NewMethod<Action<AbstractBufferedWriter, ITypeBinarySerializerContext, object>>(descriptor.Name + "Saver");
var il = method.Generator;
descriptor.GenerateSave(il, ilgen => ilgen.Ldarg(0), ilgen => ilgen.Ldarg(1), ilgen =>
{
ilgen.Ldarg(2);
var type = descriptor.GetPreferedType();
if (type != typeof(object))
{
ilgen.Castclass(type);
}
}, descriptor.GetPreferedType());
il.Ret();
return method.Create();
}
示例5: LoadAsType
public Type LoadAsType(ITypeDescriptor descriptor, Type targetType)
{
return descriptor.GetPreferedType(targetType) ?? TypeNameMapper.ToType(descriptor.Name) ?? typeof(object);
}
示例6: InitFromKeyValueDescriptors
void InitFromKeyValueDescriptors(ITypeDescriptor keyDescriptor, ITypeDescriptor valueDescriptor)
{
if (_keyDescriptor == keyDescriptor && _valueDescriptor == valueDescriptor) return;
_keyDescriptor = keyDescriptor;
_valueDescriptor = valueDescriptor;
_keyType = _keyDescriptor.GetPreferedType();
_valueType = _valueDescriptor.GetPreferedType();
Sealed = _keyDescriptor.Sealed && _valueDescriptor.Sealed;
Name = string.Format("Dictionary<{0}, {1}>", _keyDescriptor.Name, _valueDescriptor.Name);
}
示例7: NewSimpleSaver
Action<AbstractBufferedWriter, object> NewSimpleSaver(ITypeDescriptor descriptor)
{
if (descriptor.AnyOpNeedsCtx()) return null;
var method = ILBuilder.Instance.NewMethod<Action<AbstractBufferedWriter, object>>(descriptor.Name + "SimpleSaver");
var il = method.Generator;
descriptor.GenerateSave(il, ilgen => ilgen.Ldarg(0), null, ilgen =>
{
ilgen.Ldarg(1);
var type = descriptor.GetPreferedType();
if (type != typeof(object))
{
ilgen.UnboxAny(type);
}
}, descriptor.GetPreferedType());
il.Ret();
return method.Create();
}
示例8: LoadAsType
public Type LoadAsType(ITypeDescriptor descriptor)
{
return descriptor.GetPreferedType() ?? NameToType(descriptor.Name) ?? typeof(object);
}