//------------------------------------------------------------------------------------------------------------------------------------------------- protected override void OnImplementBaseClass(ImplementationClassWriter<TT.TBase> writer) { var modelTypeKey = (EdmModelTypeKey)base.Context.TypeKey; var model = modelTypeKey.Model; writer.Constructor<Uri>((w, uri) => w.Base<Uri, string>(uri, w.Const(model.GetEntityNamespace()))); var allEntityTypes = model.SchemaElements.OfType<IEdmEntityType>().ToArray(); foreach ( var entityEdmType in allEntityTypes ) { var entityClrType = _entityFactory.ImplementClientEntity(model, entityEdmType); using ( TT.CreateScope<TT.TItem>(entityClrType) ) { writer.NewVirtualWritableProperty<DataServiceQuery<TT.TItem>>(entityEdmType.Name).Implement( p => p.Get(w => { w.If(p.BackingField == w.Const<DataServiceQuery<TT.TItem>>(null)).Then(() => p.BackingField.Assign( w.This<DataServiceContext>().Func<string, DataServiceQuery<TT.TItem>>( x => x.CreateQuery<TT.TItem>, w.Const(entityEdmType.Name))) ); w.Return(p.BackingField); }), p => p.Set((w, value) => { })); } } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void ImplementConstructor(ImplementationClassWriter<TypeTemplate.TInterface> writer, List<PropertyMember> properties) { writer.Constructor<Auto<IConfigurationLogger>, string>((cw, logger, path) => { cw.Base(logger, path); foreach ( var property in properties ) { using ( TT.CreateScope<TT.TProperty>(property.PropertyDeclaration.PropertyType) ) { IOperand<TT.TProperty> defaultValue; if ( TryGetPropertyDefaultValue(cw, property.PropertyDeclaration, out defaultValue) ) { property.BackingField.AsOperand<TT.TProperty>().Assign(defaultValue); } } } }); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected override void OnImplementPrimaryInterface(ImplementationClassWriter<TypeTemplate.TInterface> writer) { _threadLogAppenderField = writer.Field<IThreadLogAppender>("_threadLogAppender"); writer.Constructor<IThreadLogAppender>((w, appender) => _threadLogAppenderField.Assign(appender)); writer.AllMethods().Implement(ImplementLogMethod); writer.AllProperties().Implement( p => p.Get(w => w.Throw<NotSupportedException>("Events are not supported")), p => p.Set((w, value) => w.Throw<NotSupportedException>("Events are not supported"))); writer.AllEvents().Implement( e => e.Add((w, args) => w.Throw<NotSupportedException>("Events are not supported")), e => e.Remove((w, args) => w.Throw<NotSupportedException>("Events are not supported"))); }
//------------------------------------------------------------------------------------------------------------------------------------------------- protected override void OnImplementBaseClass(ImplementationClassWriter<TT.TBase> writer) { var entityTypeKey = (EdmEntityTypeKey)base.Context.TypeKey; var entityType = entityTypeKey.EntityType; WriteEntityAttributes(writer, entityType); var initializers = new List<Action<ConstructorWriter>>(); foreach (var property in entityType.Properties()) { WriteEntityProperty(writer, entityTypeKey.Model, property, initializers); } writer.Constructor(cw => { initializers.ForEach(init => init(cw)); }); }