public static ITypeConfiguration <T> Member <T, TMember>(this ITypeConfiguration <T> @this, Expression <Func <T, TMember> > member, Action <IMemberConfiguration <T, TMember> > configure) { configure(@this.Member(member)); return(@this); }
public static ITypeConfiguration <T> CustomSerializer <T>(this ITypeConfiguration <T> @this, IExtendedXmlCustomSerializer serializer) { @this.Root.With <CustomSerializationExtension>() .XmlSerializers.Assign(@this.Get(), serializer); return(@this); }
public static ITypeConfiguration <T> EnableReferences <T, TMember>(this ITypeConfiguration <T> @this, Expression <Func <T, TMember> > member) { @this.Member(member) .Identity(); return(@this); }
public static ITypeConfiguration <T> AddMigration <T>(this ITypeConfiguration <T> @this, IEnumerable <Action <XElement> > migrations) { @this.Root.With <MigrationsExtension>() .Add(@this.Get(), migrations.Fixed()); return(@this); }
public static ITypeConfiguration <T> Alter <T>(this ITypeConfiguration <T> @this, IAlteration <T> read, IAlteration <T> write) { @this.Root.With <AlteredContentExtension>() .Types.Assign(Support <T> .Key, new ContentAlteration(read.Adapt(), write.Adapt())); return(@this); }
public AutoInputGraphType(IGraphQLConfiguration configuration) { _configuration = configuration; _typeConfiguration = _configuration.GetModelConfiguration <TSourceType>(); Name = GetTypeName(typeof(TSourceType)) + "Input"; Metadata["Type"] = typeof(TSourceType); var properties = GetRegisteredProperties().ToList(); foreach (var propertyInfo in properties) { var fieldConfiguration = _typeConfiguration.GetFieldConfiguration(propertyInfo.Name); var field = Field( type: propertyInfo.PropertyType.ToGraphType(), name: fieldConfiguration?.FieldName ?? GetFieldName(propertyInfo), description: propertyInfo.Description(), deprecationReason: propertyInfo.ObsoleteMessage() ); field.DefaultValue = (propertyInfo.GetCustomAttributes(typeof(DefaultValueAttribute), false).FirstOrDefault() as DefaultValueAttribute)?.Value; field.Metadata["PropertyInfo"] = propertyInfo; } }
public static ITypeConfiguration <T> EmitWhen <T>(this ITypeConfiguration <T> @this, Func <T, bool> specification) { @this.Root.With <AllowedInstancesExtension>() .Assign(@this.Get(), new AllowedValueSpecification(new DelegatedSpecification <T>(specification).AdaptForNull())); return(@this); }
public void SetUp() { _response = null; _enforce = false; _typeToLookup = typeof(BlendedCacheConfigurationBuildTests); _configurationDictionary = new Dictionary<Type, ITypeConfiguration>(); _configurationDictionary.Add(typeof(BlendedCacheConfigurationBuildTests), RMM.GenerateStrictMock<ITypeConfiguration>()); }
public static ITypeConfiguration <T> OnlyConfiguredProperties <T>(this ITypeConfiguration <T> @this) { foreach (var member in (IEnumerable <IMemberConfiguration>)@this) { member.Include(); } return(@this); }
internal static IMemberConfiguration Member(this ITypeConfiguration @this, string member) { var metadata = @this.Get() .GetMember(member) .SingleOrDefault(); var result = metadata != null ? ((IInternalTypeConfiguration)@this).Member(metadata) : null; return(result); }
public void SetUp() { _response = null; _registeredType = typeof(TDataMock); _registeredTypeCacheTimeout = RMM.GenerateStub<ICacheTimeout>(); _registeredConfig = RMM.GenerateStrictMock<ITypeConfiguration>(); RME.Stub(_registeredConfig, x => x.CacheTimeout).Return(_registeredTypeCacheTimeout); _lookedUpType = _registeredType; _defaultCacheTimeout = RMM.GenerateStrictMock<ICacheTimeout>(); }
private object GetParameterObject(ParameterInfo parameterInfo, ITypeConfiguration config) { object newObject = null; Type parameterAttb = null; if (parameterInfo.GetCustomAttributes(false).Length > 0) parameterAttb = parameterInfo.GetCustomAttributes(false)[0].GetType(); newObject = GetValuePropertyFromConstructorValues(parameterInfo, config); if(newObject == null) { if (_binder.IsConfigured(new TypeKey(parameterInfo.ParameterType, parameterAttb))) newObject = ResolveType(new TypeKey(parameterInfo.ParameterType, parameterAttb)); else if (_binder.IsConfigured(new TypeKey(parameterInfo.ParameterType))) newObject = ResolveType(new TypeKey(parameterInfo.ParameterType)); else throw new NotImplementedException("CANNOT RESOLVE PARAMETER"); } if (newObject == null) throw new UnboundTypeException(); return newObject; }
/// <summary> /// Convenience method to iterate through all explicitly configured members of a type and mark them as included. Only /// these members will be considered to emit content during serialization as well as reading it during /// deserialization. /// </summary> /// <typeparam name="T">The type under configuration.</typeparam> /// <param name="this">The type to configure.</param> /// <returns>The configured type.</returns> public static ITypeConfiguration <T> IncludeConfiguredMembers <T>(this ITypeConfiguration <T> @this) => @this.IncludeConfiguredTypeMembers().Return(@this);
public static ITypeConfiguration <T> CustomSerializer <T>(this ITypeConfiguration <T> @this, IExtendedXmlCustomSerializer <T> serializer) => @this.CustomSerializer(new Adapter <T>(serializer));
private void AddIfSingleton(object newObject, ITypeConfiguration config) { if (config.ActivationType == ActivationType.Singleton) _sigletonBag.Add(new TypeKey(config.Source), newObject); }
internal static void OnModelConfigurationCreated(ITypeConfiguration obj) { var handler = ModelConfigurationCreated; handler?.Invoke(obj); }
private object CreateObjectWithConstructor(ITypeConfiguration config) { var args = config.Constructor.GetParameters().Select(p => GetParameterObject(p, config)).ToArray(); return _recorder.ActivatorCreateInstance(config.Target, args, _binder.IsSingleton(new TypeKey(config.Source))); }
public static ITypeConfiguration <T> Alter <T>(this ITypeConfiguration <T> @this, Func <T, T> write) => Alter(@this, Self <T> .Default.Get, write);
/// <summary> /// Used to alter an instance of the configured result type whenever it is encountered during the serialization or /// deserialization process. This can be used in scenarios where it is desired to know when an instance of a /// particular type is emitted or read (for logging purposes, etc.) or, more generally, to alter it in some way /// (scrubbing data, etc) before it is written to the external stream or read into memory. You can consider this as a /// value interception of the serialization/deserialization pipeline. /// </summary> /// <typeparam name="T">The type under configuration.</typeparam> /// <param name="this">The type configuration to configure.</param> /// <param name="read">The alteration to apply during reading.</param> /// <param name="write">The alteration to apply during writing.</param> /// <returns>The configured type configuration.</returns> public static ITypeConfiguration <T> Alter <T>(this ITypeConfiguration <T> @this, IAlteration <T> read, IAlteration <T> write) => @this.Root.With <AlteredContentExtension>() .Types.Apply(Support <T> .Metadata, new ContentAlteration(read.Adapt(), write.Adapt())) .Return(@this);
/// <summary> /// Used to alter an instance of the configured result type whenever it is encountered during the serialization /// process. This can be used in scenarios where it is desired to know when an instance of a particular type is /// emitted (for logging purposes, etc.) or, more generally, to alter it in some way (scrubbing data, etc) /// before it is written to the external stream. You can consider this as a value interception of /// the serialization pipeline. /// </summary> /// <typeparam name="T">The type under configuration.</typeparam> /// <param name="this">The type configuration to configure.</param> /// <param name="write">The alteration delegate to invoke during writing.</param> /// <returns>The configured type configuration.</returns> public static ITypeConfiguration <T> Alter <T>(this ITypeConfiguration <T> @this, Func <T, T> write) => @this.Alter(Self.Of <T>(), write);
public static ITypeConfiguration <T> Name <T>(this ITypeConfiguration <T> @this, string name) { ((IInternalTypeConfiguration)@this).Name(name); return(@this); }
public static ITypeConfiguration <T> Member <T>(this ITypeConfiguration <T> @this, MemberInfo member) { ((IInternalTypeConfiguration)@this).Member(member); return(@this); }
public static IMemberConfiguration <T, TMember> Member <T, TMember>(this ITypeConfiguration <T> @this, Expression <Func <T, TMember> > member) => ((IInternalTypeConfiguration)@this).Member(member.GetMemberInfo()) .AsValid <MemberConfiguration <T, TMember> >();
/// <summary> /// Used in dire circumstances. If you encounter an older .NET object type that cannot be serialized (e.g. /// DataTable), and it implements <see cref="ISerializable"/>, call this method to configure the container to create a /// serializer that will serialize and deserialize using this interface. /// </summary> /// <typeparam name="T">The type under configuration.</typeparam> /// <param name="this">The type configuration to configure.</param> /// <returns>The configured type configuration.</returns> /// <seealso href="https://github.com/ExtendedXmlSerializer/home/issues/268" /> public static ITypeConfiguration <T> UseClassicSerialization <T>(this ITypeConfiguration <T> @this) where T : ISerializable => @this.Register().Serializer().Of <ClassicSerializationAdapter <T> >();
/// <summary> /// Applies a serialization monitor to a specific type. A serialization monitor is a component that gets notified /// whenever there is a serialization such as OnSerializing, OnSerialized, as well as deserialization events such as /// OnDeserializing, OnDeserialized, etc. /// /// Note that calling this method will establish a default monitor if one has not already been assigned. If you also /// want to use a default monitor in addition to type-specific monitors, call the <see cref="WithDefaultMonitor" /> /// first before calling this method on any types. /// </summary> /// <typeparam name="T">The type to monitor.</typeparam> /// <param name="this">The type configuration to configure.</param> /// <param name="monitor">The monitor to apply to the specified type.</param> /// <returns>The configured type configuration.</returns> /// <seealso href="https://github.com/ExtendedXmlSerializer/home/issues/264" /> public static ITypeConfiguration <T> WithMonitor <T>(this ITypeConfiguration <T> @this, ISerializationMonitor <T> monitor) => @this.Root.With <SerializationMonitorExtension>() .Apply(Support <T> .Metadata, new SerializationMonitor <T>(monitor)) .Return(@this);
public static ITypeConfiguration <T> AddMigration <T>(this ITypeConfiguration <T> @this, ICommand <XElement> migration) => @this.AddMigration(migration.Execute);
private object GetValuePropertyFromConstructorValues(ParameterInfo parameterInfo, ITypeConfiguration config) { object propObject = null; if (config.ConstructorValues != null) { var customArgs = _recorder.GetConstructorValues(config.ConstructorValues); var valueProperty = customArgs.GetType() .GetProperties() .FirstOrDefault(p => p.PropertyType.Equals(parameterInfo.ParameterType)); if (valueProperty != null) propObject = valueProperty.GetValue(customArgs, new object[] { }); } return propObject; }
public static ITypeConfiguration <T> AddMigration <T>(this ITypeConfiguration <T> @this, Action <XElement> migration) => @this.AddMigration(migration.Yield());
public static ITypeConfiguration <T> Register <T>(this ITypeConfiguration <T> @this, ISerializer <T> serializer) => Register(@this, serializer.Adapt());
public static ITypeConfiguration <T> Register <T>(this ITypeConfiguration <T> @this, Type serializerType) => @this.Register(new ActivatedSerializer(serializerType, Support <T> .Key));
public static ITypeConfiguration <T> Register <T>(this ITypeConfiguration <T> @this, ISerializer serializer) { @this.Root.With <CustomSerializationExtension>() .Types.Assign(@this.Get(), serializer); return(@this); }
public static ITypeConfiguration <T> Alter <T>(this ITypeConfiguration <T> @this, Func <T, T> read, Func <T, T> write) => @this.Alter(new DelegatedAlteration <T>(read), new DelegatedAlteration <T>(write));
public static ITypeConfiguration <T> Unregister <T>(this ITypeConfiguration <T> @this) { @this.Root.With <CustomSerializationExtension>() .Types.Remove(@this.Get()); return(@this); }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="configuration">The type configuration under configuration.</param> public TypeSerializationRegistrationContext(ITypeConfiguration <T> configuration) => _configuration = configuration;
public static ITypeConfiguration <T> CustomSerializer <T>(this ITypeConfiguration <T> @this, Action <System.Xml.XmlWriter, T> serializer, Func <XElement, T> deserialize) => @this.CustomSerializer(new ExtendedXmlCustomSerializer <T>(deserialize, serializer));
private void Execute() { var config = new Config(_enforce); foreach (var pair in _configurationDictionary) { config.RegisterTypeConfiguration(pair.Key, pair.Value); } _response = config.GetTypeConfiguration(_typeToLookup); }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="configuration">The type configuration to configure.</param> public TypeRegistrationContext(ITypeConfiguration <T> configuration) => _configuration = configuration;