Skip to content

Instantly share code, notes, and snippets.

@urasandesu
urasandesu / PowerShellAsLinq.ps1
Created June 17, 2012 11:50
PowerShell as LINQ
# ----------------------------------------------------------------------------------------------------------
# PowerShell as LINQ
# * When I created this snippet, the blog written by NyaRuRu-san was very helpful.
# I would like to thank him for his article:
# - PowerShell で LINQ - NyaRuRuの日記: http://d.hatena.ne.jp/NyaRuRu/20080112/p2
#
# Change History
# * 2012/06/20 07:23:24: Fix the bug that occurs unintended pipeline breaking.
# The keyword 'return' is reserved, so I use the function name 'run' instead of it.
# * 2012/06/23 22:26:47: Fix the bug that function 'run' doesn't stop enumeration.
$script = {
($InputObject, $2to1Ready, $1to2Ready, $2to1End, $1to2End) = $($input)
$InputObject_ = $InputObject.GetNewClosure()
try {
do {
& $InputObject_ |
ForEach-Object {
$_
[Void]$2to1Ready.Set()
[Void]$1to2Ready.WaitOne()
#pragma once
#ifndef URASANDESU_SWATHE_METADATA_BASECLASSPIMPL_BASETYPEMETADATAPIMPL_HPP
#define URASANDESU_SWATHE_METADATA_BASECLASSPIMPL_BASETYPEMETADATAPIMPL_HPP
#ifndef URASANDESU_SWATHE_METADATA_BASECLASSPIMPL_BASETYPEMETADATAPIMPL_H
#include <Urasandesu/Swathe/Metadata/BaseClassPimpl/BaseTypeMetadataPimpl.h>
#endif
namespace Urasandesu { namespace Swathe { namespace Metadata { namespace BaseClassPimpl {
#include "stdafx.h"
#ifndef URASANDESU_SWATHE_METADATA_SIGNATURE_H
#include <Urasandesu/Swathe/Metadata/Signature.h>
#endif
#ifndef URASANDESU_SWATHE_METADATA_IMETHOD_H
#include <Urasandesu/Swathe/Metadata/IMethod.h>
#endif
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace ConsoleApplication9
{
# +実行には、事前に PSAnonym(https://github.com/urasandesu/PSAnonym) のインストールが必要。
# +また、PSAnonym は PowerShell v2 でしか動作しないため、このコード片を実行するには、
# PS C:\> powershell -version 2
# する等して、プロンプトの実行環境を合わせてやる必要がある。
Import-Module Urasandesu.PSAnonym
# -----------------------------------------------------------------------------------------------
#
# テンプレートエンジンを構成するプロトタイプ群
#
using System;
using System.IO;
namespace mscorlib.Prig
{
public class EHClass
{
public void ReadFile(string path, int index)
{
var file = default(StreamReader);
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
namespace EHTrial
{
class Program
{
static void Main(string[] args)
#include "stdafx.h"
#include <Urasandesu/Swathe/Swathe.h>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace Urasandesu::Swathe;
using namespace Urasandesu::Swathe::Hosting;
using namespace Urasandesu::Swathe::Metadata;
using namespace Urasandesu::Swathe::StrongNaming;
...
STDMETHODIMP CWeaverImpl::JITCompilationStartedCore(
/* [in] */ FunctionID functionId,
/* [in] */ BOOL fIsSafeToBlock)
{
using boost::lexical_cast;
using boost::filesystem::path;
using std::vector;
using Urasandesu::CppAnonym::Utilities::AnyPtr;