/// <see cref="ICustomSerialization"/> public virtual EntryPrototype[] Prototypes(Type memberType, ICustomAttributeProvider attributeProvider) { // Check if it is a list, array or dictionary if (EntryConvert.IsCollection(memberType)) { memberType = EntryConvert.ElementType(memberType); } object prototype; if (memberType == typeof(string)) { prototype = string.Empty; } else { prototype = Activator.CreateInstance(memberType); ValueProviderExecutor.Execute(prototype, new ValueProviderExecutorSettings().AddDefaultValueProvider()); } return(new[] { new EntryPrototype(memberType.Name, prototype) }); }
/// <see cref="ICustomSerialization"/> public virtual EntryPrototype[] Prototypes(Type memberType, ICustomAttributeProvider attributeProvider) { // Check if it is a list, array or dictionary if (EntryConvert.IsCollection(memberType)) { memberType = EntryConvert.ElementType(memberType); } List <EntryPrototype> prototypes = new List <EntryPrototype>(); if (memberType == typeof(string)) { prototypes.Add(new EntryPrototype(nameof(String), string.Empty)); } else if (memberType.IsEnum) { foreach (Enum enumValue in Enum.GetValues(memberType)) { prototypes.Add(new EntryPrototype(enumValue.ToString("G"), enumValue)); } } else { var prototype = Activator.CreateInstance(memberType); if (memberType.IsClass) { ValueProviderExecutor.Execute(prototype, new ValueProviderExecutorSettings().AddDefaultValueProvider()); } prototypes.Add(new EntryPrototype(memberType.Name, prototype)); } return(prototypes.ToArray()); }
/// <see cref="ICustomSerialization"/> public virtual object CreateInstance(Type memberType, ICustomAttributeProvider attributeProvider, Entry encoded) { if (EntryConvert.IsCollection(memberType)) { memberType = EntryConvert.ElementType(memberType); } return(CreateInstance(memberType, encoded)); }
/// <see cref="ICustomSerialization"/> public virtual string[] PossibleValues(Type memberType, ICustomAttributeProvider attributeProvider) { // Element type for collections if (EntryConvert.IsCollection(memberType)) { return new[] { EntryConvert.ElementType(memberType).Name } } ; // Names of Enums or null return(memberType.IsEnum ? Enum.GetNames(memberType) : null); }
/// <see cref="ICustomSerialization"/> public virtual string[] PossibleValues(Type memberType, ICustomAttributeProvider attributeProvider) { // Element type for collections var isCollection = EntryConvert.IsCollection(memberType); if (isCollection) { memberType = EntryConvert.ElementType(memberType); } // Enum names, member name or null return(memberType.IsEnum ? Enum.GetNames(memberType) : isCollection ? new[] { memberType.Name } : null); }