public IDisposable Scope(TextWriter writer) { WriterScope scope = new WriterScope(this, InnerWriter); if (writer != this) { InnerWriter = writer; } return(scope); }
public IDisposable Scope(TextWriter writer) { WriterScope scope = new WriterScope(this, InnerWriter); try { if (writer != this) { InnerWriter = writer; } return(scope); } catch { scope.Dispose(); throw; } }
private IOrderedEnumerable <Type> GetWritersForCurrentContext(WriterScope scope, Func <TemplateSchemaWriterAttribute, Int32?> sortingSelector) { // Get all serializers to run in automated mode, ordered by sortingSelector var currentAssembly = this.GetType().Assembly; var writers = currentAssembly.GetTypes() // Get all the writers .Where(t => t.GetInterface(typeof(IPnPSchemaWriter).FullName) != null && t.BaseType.Name == typeof(PnPBaseSchemaWriter <>).Name) // Order the writers by sequence .OrderBy(s => { var a = s.GetCustomAttributes <TemplateSchemaWriterAttribute>(false).FirstOrDefault(); if (a != null) { return(a.WriterSequence); } return(0); } ); return(writers); }
public IDisposable Scope(TextWriter writer) { WriterScope scope = new WriterScope(this, InnerWriter); if (writer != this) { InnerWriter = writer; } return scope; }
private IOrderedEnumerable <IGrouping <string, Type> > GetSerializersForCurrentContext(WriterScope scope, Func <TemplateSchemaWriterAttribute, Int32?> sortingSelector) { // Get all serializers to run in automated mode, ordered by sortingSelector var currentAssembly = this.GetType().Assembly; //PnP.Framework.Provisioning.Providers.Xml.XMLPnPSchemaVersion currentSchemaVersion = GetCurrentSchemaVersion(); var serializers = currentAssembly.GetTypes() // Get all the serializers .Where(t => t.GetInterface(typeof(IPnPSchemaWriter).FullName) != null && t.BaseType.Name == typeof(Xml.PnPBaseSchemaSerializer <>).Name) // Filter out those that are not targeting the current schema version or that are not in scope Template .Where(t => { var a = t.GetCustomAttributes <TemplateSchemaWriterAttribute>(false).FirstOrDefault(); return(a.Scope == scope); }) // Order the remainings by supported schema version descendant, to get first the newest ones .OrderByDescending(s => { var a = s.GetCustomAttributes <TemplateSchemaWriterAttribute>(false).FirstOrDefault(); return(a.MinimalSupportedSchemaVersion); } ) // Group those with the same target type (which is the first generic Type argument) .GroupBy(t => t.BaseType.GenericTypeArguments.FirstOrDefault()?.FullName) // Order the result by SerializationSequence .OrderBy(g => { var maxInGroup = g.OrderByDescending(s => { var a = s.GetCustomAttributes <TemplateSchemaWriterAttribute>(false).FirstOrDefault(); return(a.MinimalSupportedSchemaVersion); } ).FirstOrDefault(); return(sortingSelector(maxInGroup.GetCustomAttributes <TemplateSchemaWriterAttribute>(false).FirstOrDefault())); }); return(serializers); }
public IDisposable Scope(TextWriter writer) { WriterScope scope = new WriterScope(this, InnerWriter); try { if (writer != this) { InnerWriter = writer; } return scope; } catch { scope.Dispose(); throw; } }