示例#1
0
 private static string ReadAsString(PSObject sourceObject, out PSSourceInfo sourceInfo)
 {
     sourceInfo = null;
     if (sourceObject.BaseObject is string)
     {
         return(sourceObject.BaseObject.ToString());
     }
     else if (sourceObject.BaseObject is FileInfo fileInfo)
     {
         sourceInfo = new PSSourceInfo(fileInfo);
         using (var reader = new StreamReader(fileInfo.FullName))
         {
             return(reader.ReadToEnd());
         }
     }
     else
     {
         var uri = sourceObject.BaseObject as Uri;
         sourceInfo = new PSSourceInfo(uri);
         using (var webClient = new WebClient())
         {
             return(webClient.DownloadString(uri));
         }
     }
 }
示例#2
0
        private static void NoteSource(PSObject[] value, PSSourceInfo source)
        {
            if (value == null || value.Length == 0 || source == null)
            {
                return;
            }

            for (var i = 0; i < value.Length; i++)
            {
                NoteSource(value[i], source);
            }
        }
示例#3
0
        private static void NoteSource(PSObject value, PSSourceInfo source)
        {
            if (value == null || source == null)
            {
                return;
            }

            if (!value.HasProperty(PropertyName_PSPath))
            {
                value.Properties.Add(new PSNoteProperty(PropertyName_PSPath, source.PSPath));
            }

            if (!value.HasProperty(PropertyName_PSParentPath))
            {
                value.Properties.Add(new PSNoteProperty(PropertyName_PSParentPath, source.PSParentPath));
            }

            if (!value.HasProperty(PropertyName_PSChildName))
            {
                value.Properties.Add(new PSNoteProperty(PropertyName_PSChildName, source.PSChildName));
            }
        }