private FormatMessagesContextManager.OutputContext CreateOutputContext(FormatMessagesContextManager.OutputContext parentContext, FormatInfoData formatInfoData) { FormatStartData formatData = formatInfoData as FormatStartData; if (formatData != null) { return new FormatOutputContext(parentContext, formatData); } GroupStartData data2 = formatInfoData as GroupStartData; if (data2 == null) { return null; } GroupOutputContext context2 = null; switch (this.ActiveFormattingShape) { case FormatShape.Table: context2 = new TableOutputContext(this, parentContext, data2); break; case FormatShape.List: context2 = new ListOutputContext(this, parentContext, data2); break; case FormatShape.Wide: context2 = new WideOutputContext(this, parentContext, data2); break; case FormatShape.Complex: context2 = new ComplexOutputContext(this, parentContext, data2); break; } context2.Initialize(); return context2; }
// returns null on error internal static FormatInfoData CreateInstance(PSObject so, FormatObjectDeserializer deserializer) { if (so == null) { throw PSTraceSource.NewArgumentNullException("so"); } // look for the property that defines the type of object string classId = FormatObjectDeserializer.GetProperty(so, FormatInfoData.classidProperty) as string; if (classId == null) { string msg = StringUtil.Format(FormatAndOut_format_xxx.FOD_InvalidClassidProperty); ErrorRecord errorRecord = new ErrorRecord( PSTraceSource.NewArgumentException("classid"), "FormatObjectDeserializerInvalidClassidProperty", ErrorCategory.InvalidData, so); errorRecord.ErrorDetails = new ErrorDetails(msg); deserializer.TerminatingErrorContext.ThrowTerminatingError(errorRecord); } FormatInfoData fid = CreateInstance(classId, deserializer); return(fid); }
internal FormatInfoData DeserializeMandatoryMemberObject(PSObject so, string property) { FormatInfoData fid = DeserializeMemberObject(so, property); VerifyDataNotNull(fid, property); return(fid); }
internal FormatInfoData DeserializeMandatoryMemberObject(PSObject so, string property) { FormatInfoData data = this.DeserializeMemberObject(so, property); this.VerifyDataNotNull(data, property); return(data); }
/// <summary> /// class factory for output context /// </summary> /// <param name="parentContext">parent context in the stack</param> /// <param name="formatInfoData"> fromat info data received from the pipeline</param> /// <returns></returns> private FormatMessagesContextManager.OutputContext CreateOutputContext( FormatMessagesContextManager.OutputContext parentContext, FormatInfoData formatInfoData) { FormatStartData formatStartData = formatInfoData as FormatStartData; // initialize the format context if (formatStartData != null) { FormatOutputContext foc = new FormatOutputContext(parentContext, formatStartData); return(foc); } GroupStartData gsd = formatInfoData as GroupStartData; // we are starting a group, initialize the group context if (gsd != null) { GroupOutputContext goc = null; switch (ActiveFormattingShape) { case FormatShape.Table: { goc = new TableOutputContext(this, parentContext, gsd); break; } case FormatShape.List: { goc = new ListOutputContext(this, parentContext, gsd); break; } case FormatShape.Wide: { goc = new WideOutputContext(this, parentContext, gsd); break; } case FormatShape.Complex: { goc = new ComplexOutputContext(this, parentContext, gsd); break; } default: { Diagnostics.Assert(false, "Invalid shape. This should never happen"); } break; } goc.Initialize(); return(goc); } return(null); }
// returns null on error internal FormatInfoData DeserializeObject(PSObject so) { FormatInfoData fid = FormatInfoDataClassFactory.CreateInstance(so, this); if (fid != null) { fid.Deserialize(so, this); } return(fid); }
internal FormatInfoData DeserializeObject(PSObject so) { FormatInfoData data = FormatInfoDataClassFactory.CreateInstance(so, this); if (data != null) { data.Deserialize(so, this); } return(data); }
private static void ReadListHelper(IEnumerable en, List <T> lst, FormatObjectDeserializer deserializer) { deserializer.VerifyDataNotNull(en, "enumerable"); foreach (object obj in en) { FormatInfoData fid = deserializer.DeserializeObject(PSObjectHelper.AsPSObject(obj)); T entry = fid as T; deserializer.VerifyDataNotNull(entry, "entry"); lst.Add(entry); } }
// returns null on failure private static FormatInfoData CreateInstance(string clsid, FormatObjectDeserializer deserializer) { Func <FormatInfoData> ctor; if (!s_constructors.TryGetValue(clsid, out ctor)) { CreateInstanceError(PSTraceSource.NewArgumentException(nameof(clsid)), clsid, deserializer); return(null); } try { FormatInfoData fid = ctor(); return(fid); } catch (ArgumentException e) { CreateInstanceError(e, clsid, deserializer); } catch (NotSupportedException e) { CreateInstanceError(e, clsid, deserializer); } catch (TargetInvocationException e) { CreateInstanceError(e, clsid, deserializer); } catch (MemberAccessException e) // also MethodAccessException and MissingMethodException { CreateInstanceError(e, clsid, deserializer); } catch (System.Runtime.InteropServices.InvalidComObjectException e) { CreateInstanceError(e, clsid, deserializer); } catch (System.Runtime.InteropServices.COMException e) { CreateInstanceError(e, clsid, deserializer); } catch (TypeLoadException e) { CreateInstanceError(e, clsid, deserializer); } catch (Exception e) // will rethrow { Diagnostics.Assert(false, "Unexpected Activator.CreateInstance error in FormatInfoDataClassFactory.CreateInstance: " + e.GetType().FullName); throw; } return(null); }
/// <summary> /// class factory for output context /// </summary> /// <param name="parentContext">parent context in the stack</param> /// <param name="formatInfoData"> fromat info data received from the pipeline</param> /// <returns></returns> private FormatMessagesContextManager.OutputContext CreateOutputContext( FormatMessagesContextManager.OutputContext parentContext, FormatInfoData formatInfoData) { FormatStartData formatStartData = formatInfoData as FormatStartData; // initialize the format context if (formatStartData != null) { FormatOutputContext foc = new FormatOutputContext(parentContext, formatStartData); return foc; } GroupStartData gsd = formatInfoData as GroupStartData; // we are starting a group, initialize the group context if (gsd != null) { GroupOutputContext goc = null; switch (ActiveFormattingShape) { case FormatShape.Table: { goc = new TableOutputContext(this, parentContext, gsd); break; } case FormatShape.List: { goc = new ListOutputContext(this, parentContext, gsd); break; } case FormatShape.Wide: { goc = new WideOutputContext(this, parentContext, gsd); break; } case FormatShape.Complex: { goc = new ComplexOutputContext(this, parentContext, gsd); break; } default: { Diagnostics.Assert(false, "Invalid shape. This should never happen"); } break; } goc.Initialize(); return goc; } return null; }
private FormatMessagesContextManager.OutputContext CreateOutputContext(FormatMessagesContextManager.OutputContext parentContext, FormatInfoData formatInfoData) { FormatStartData formatData = formatInfoData as FormatStartData; if (formatData != null) { return(new FormatOutputContext(parentContext, formatData)); } GroupStartData data2 = formatInfoData as GroupStartData; if (data2 == null) { return(null); } GroupOutputContext context2 = null; switch (this.ActiveFormattingShape) { case FormatShape.Table: context2 = new TableOutputContext(this, parentContext, data2); break; case FormatShape.List: context2 = new ListOutputContext(this, parentContext, data2); break; case FormatShape.Wide: context2 = new WideOutputContext(this, parentContext, data2); break; case FormatShape.Complex: context2 = new ComplexOutputContext(this, parentContext, data2); break; } context2.Initialize(); return(context2); }