本文整理汇总了C#中ITypeDescriptor类的典型用法代码示例。如果您正苦于以下问题:C# ITypeDescriptor类的具体用法?C# ITypeDescriptor怎么用?C# ITypeDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITypeDescriptor类属于命名空间,在下文中一共展示了ITypeDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Retrieve
/// <summary>
/// Retrieves the value itself or the value of one of its item, depending on the given <see cref="Index"/>.
/// </summary>
/// <param name="value">The value on which this method applies.</param>
/// <param name="index">The index of the item to retrieve. If <see cref="Index.Empty"/> is passed, this method will return the value itself.</param>
/// <param name="descriptor">The descriptor of the type of <paramref name="value"/>.</param>
/// <returns>The value itself or the value of one of its item.</returns>
public static object Retrieve(object value, Index index, ITypeDescriptor descriptor)
{
if (index.IsEmpty)
return value;
if (value == null) throw new ArgumentNullException(nameof(value));
var collectionDescriptor = descriptor as CollectionDescriptor;
if (collectionDescriptor != null)
{
return collectionDescriptor.GetValue(value, index.Int);
}
var dictionaryDescriptor = descriptor as DictionaryDescriptor;
if (dictionaryDescriptor != null)
{
return dictionaryDescriptor.GetValue(value, index.Value);
}
// Try with the concrete type descriptor
var objectDescriptor = TypeDescriptorFactory.Default.Find(value.GetType());
if (objectDescriptor != descriptor)
{
return Retrieve(value, index, objectDescriptor);
}
throw new NotSupportedException("Unable to retrieve the value at the given index, this collection is unsupported");
}
示例2: ObjectContext
/// <summary>
/// Initializes a new instance of the <see cref="ObjectContext"/> struct.
/// </summary>
/// <param name="serializerContext">The serializer context.</param>
/// <param name="instance">The instance.</param>
/// <param name="descriptor">The descriptor.</param>
public ObjectContext(SerializerContext serializerContext, object instance, ITypeDescriptor descriptor)
: this()
{
SerializerContext = serializerContext;
Instance = instance;
Descriptor = descriptor;
}
示例3: TransformForSerialization
/// <inheritdoc/>
protected override object TransformForSerialization(ITypeDescriptor descriptor, object collection)
{
var dictionaryDescriptor = (DictionaryDescriptor)descriptor;
var instance = CreatEmptyContainer(descriptor);
CollectionItemIdentifiers identifier;
if (!CollectionItemIdHelper.TryGetCollectionItemIds(collection, out identifier))
{
identifier = new CollectionItemIdentifiers();
}
var keyWithIdType = typeof(KeyWithId<>).MakeGenericType(dictionaryDescriptor.KeyType);
foreach (var item in dictionaryDescriptor.GetEnumerator(collection))
{
ItemId id;
if (!identifier.TryGet(item.Key, out id))
{
id = ItemId.New();
identifier.Add(item.Key, id);
}
var keyWithId = Activator.CreateInstance(keyWithIdType, id, item.Key);
instance.Add(keyWithId, item.Value);
}
return instance;
}
示例4: VisitCollectionItem
/// <inheritdoc/>
public override void VisitCollectionItem(IEnumerable collection, CollectionDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
{
if (CurrentPath.Match(MemberPath))
VisitAssetMember(item, itemDescriptor);
else
base.VisitCollectionItem(collection, descriptor, index, item, itemDescriptor);
}
示例5: FlexiPlainTextSerializationContext
public FlexiPlainTextSerializationContext(
IFlexiPlainTextSerializer serializer,
ITypeDescriptor typeDescriptor,
TypeResolver typeResolver,
Func<Type, CreateInstanceContext, object> createInstanceWith = null)
: base(serializer, typeDescriptor, typeResolver, createInstanceWith)
{ }
示例6: ContentBase
protected ContentBase(ITypeDescriptor descriptor, bool isPrimitive, IReference reference)
{
if (descriptor == null) throw new ArgumentNullException(nameof(descriptor));
Reference = reference;
Descriptor = descriptor;
IsPrimitive = isPrimitive;
}
示例7: VisitArrayItem
/// <inheritdoc/>
public override void VisitArrayItem(Array array, ArrayDescriptor descriptor, int index, object item, ITypeDescriptor itemDescriptor)
{
if (CurrentPath.Match(MemberPath))
VisitAssetMember(item, itemDescriptor);
else
base.VisitArrayItem(array, descriptor, index, item, itemDescriptor);
}
示例8: TryCreate
public override IYamlSerializable TryCreate(SerializerContext context, ITypeDescriptor typeDescriptor)
{
if (CanVisit(typeDescriptor.Type))
return this;
return null;
}
示例9: ObjectContext
/// <summary>
/// Initializes a new instance of the <see cref="ObjectContext"/> struct.
/// </summary>
/// <param name="serializerContext">The serializer context.</param>
/// <param name="instance">The instance.</param>
/// <param name="descriptor">The descriptor.</param>
public ObjectContext(SerializerContext serializerContext, object instance, ITypeDescriptor descriptor) : this()
{
SerializerContext = serializerContext;
Instance = instance;
Descriptor = descriptor;
Properties = new PropertyContainer();
}
示例10: ObjectContent
public ObjectContent(object value, ITypeDescriptor descriptor, bool isPrimitive, IReference reference)
: base(descriptor, isPrimitive, reference)
{
if (reference is ObjectReference)
throw new ArgumentException($"An {nameof(ObjectContent)} cannot contain an {nameof(ObjectReference)}");
this.value = value;
}
示例11: Unbinder
public Unbinder(ITypeDescriptor typeDescriptor,
ITypeSimplicityEvaluator typeSimplicityEvaluator,
IValueUnbinder valueUnbinder)
{
_typeDescriptor = typeDescriptor;
_typeSimplicityEvaluator = typeSimplicityEvaluator;
_valueUnbinder = valueUnbinder;
}
示例12: 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}>";
}
示例13: ContentBase
protected ContentBase(ITypeDescriptor descriptor, bool isPrimitive, IReference reference)
{
if (descriptor == null) throw new ArgumentNullException("descriptor");
this.reference = reference;
Descriptor = descriptor;
IsPrimitive = isPrimitive;
SerializeFlags = ViewModelContentSerializeFlags.SerializeValue;
ShouldProcessReference = true;
}
示例14: VisitDictionaryKeyValue
public override void VisitDictionaryKeyValue(object dictionary, DictionaryDescriptor descriptor, object key, ITypeDescriptor keyDescriptor, object value, ITypeDescriptor valueDescriptor)
{
// TODO: CurrentPath is valid only for value, not key
//if (ProcessObject(key, keyDescriptor.Type)) key = null;
if (ProcessObject(value, valueDescriptor.Type)) return;
Visit(value, valueDescriptor);
//base.VisitDictionaryKeyValue(dictionary, descriptor, key, keyDescriptor, value, valueDescriptor);
}
示例15: CreateDataContextTypeStack
protected override IDataContextStack CreateDataContextTypeStack(ITypeDescriptor viewModelType, ITypeDescriptor wrapperType = null, IDataContextStack parentDataContextStack = null)
{
var dataContextTypeStack = new DataContextStack(ResolvedTypeDescriptor.ToSystemType(viewModelType), parentDataContextStack as DataContextStack);
if (wrapperType != null)
{
dataContextTypeStack.RootControlType = ResolvedTypeDescriptor.ToSystemType(wrapperType);
}
return dataContextTypeStack;
}