/// <summary> /// Serializes PSObject whose base objects are of primitive known type /// </summary> /// <param name="source"></param> /// <param name="property"></param> /// <param name="depth"></param> /// <param name="result"></param> /// <returns> /// true if source is handled, else false. /// </returns> private bool HandlePrimitiveKnownTypePSObject ( object source, string property, int depth, out CimInstance result ) { // To avoid compiler error result = CreateNullCimInstance(); Dbg.Assert(source != null, "caller should validate the parameter"); bool sourceHandled = false; PSObject moSource = source as PSObject; if (moSource != null && !moSource.immediateBaseObjectIsEmpty) { //Check if baseObject is primitive known type object baseObject = moSource.ImmediateBaseObject; MITypeSerializationInfo pktInfo = KnownMITypes.GetTypeSerializationInfo(baseObject.GetType()); if (pktInfo != null) { CreateCimInstanceForPrimitiveTypePSObject(moSource, baseObject, pktInfo, property, depth, out result); sourceHandled = true; } } return(sourceHandled); }
/// <summary> /// Handles primitive known type by first converting it to a PSObject. /// </summary> /// <param name="source"></param> /// <param name="property"></param> /// <param name="depth"></param> /// <param name="result"></param> /// <returns></returns> private bool HandlePrimitiveKnownTypeByConvertingToPSObject( object source, string property, int depth, out CimInstance result ) { // To avoid compiler error result = CreateNullCimInstance(); Dbg.Assert(source != null, "caller should validate the parameter"); //Check if source is of primitive known type MITypeSerializationInfo pktInfo = KnownMITypes.GetTypeSerializationInfo(source.GetType()); if (pktInfo != null) { PSObject pktInfoPSObject = PSObject.AsPSObject(source); return(HandlePrimitiveKnownTypePSObject(pktInfoPSObject, property, depth, out result)); } return(false); }