uniblab icon

Loading the intrinsic operators from embedded resource

uniblab | PRO | 12/05/20 09:59:05 PM UTC (Edited) | 0 ⭐ | 2669 👁️ | Never ⏰ | []
C# |

1.68 KB

|

None

|

0 👍

/

0 👎

private static System.Collections.Generic.IDictionary<System.String, Type> GetInitialDictionary( System.IO.TextReader file ) {
    var output = new System.Collections.Generic.Dictionary<System.String, Type>( System.StringComparer.Ordinal );
 
    var headers = new System.Collections.Generic.Dictionary<System.String, System.Int32>( System.StringComparer.OrdinalIgnoreCase );
    System.Int32 i = 0;
    foreach ( var header in file.ReadRecord( "\r\n", '\"', ',' ) ) {
        headers.Add( header, i++ );
    }
    while ( -1 != file.Peek() ) {
        var row = file.ReadRecord( "\r\n", '\"', ',' ).ToArray();
        if ( row.Length <= 3 ) {
            continue;
        }
        var assembly = System.Reflection.Assembly.Load( row[ headers[ "Assembly" ] ] );
        var type = assembly.GetType( row[ headers[ "Type" ] ], true, true );
        var method = type.GetMethod(
            row[ headers[ "Method" ] ],
            0,
            System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public,
            null,
            System.Reflection.CallingConventions.Standard,
            new System.Type[ 1 ] { typeof( Icod.Collections.Immutable.IStack<Type> ) },
            null
        );
        if ( method.ReturnType != typeof( Icod.Collections.Immutable.IStack<Type> ) ) {
            throw new System.InvalidOperationException( "Intrinsic operator misconfigured" );
        }
        var code = method.CreateDelegate(
            typeof( System.Func<Icod.Collections.Immutable.IStack<Type>, Icod.Collections.Immutable.IStack<Type>> )
        );
        var name = row[ headers[ "Name" ] ];
        var @operator = new Type(
            name,
            row[ headers[ "Ancestry" ] ],
            null,
            (System.Func<Icod.Collections.Immutable.IStack<Type>, Icod.Collections.Immutable.IStack<Type>>)code
        );
        output.Add( name, @operator );
    }
 
    return output;
}
 

Comments