• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

.NET Reflection.Emit extensions

GrEmit

NuGet Status Build status

GrEmit is a library containing different helpers for generating code using Reflection.Emit with the main one being GroboIL - a smart wrapper over ILGenerator.

Usage

GroboIL is a replacement for ILGenerator. Instead of calling ILGenerator.Emit(OpCode, ..), one may call GroboIL.OpCode(..).

Example

ILGenerator:

// .. creating DynamicMethod, MethodBuilder or ConstructorBuilder
var il = method.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldc_i4_4);
il.EmitCall(OpCodes.Callvirt, someMethod, null);
il.Emit(OpCodes.Ret);

GroboIL:

// .. creating DynamicMethod, MethodBuilder or ConstructorBuilder
using(var il = new GroboIL(method))
{
    il.Ldarg(0);
    il.Ldc_I4(4);
    il.Call(someMethod);
    il.Ret();
}

Advantages

Besides more beautiful interface GroboIL has some more advantages over ILGenerator:

  • GroboIL has a single method for all instructions from the same family, for instance, instead of 11 instructions OpCodes.Ldelem_* there is one method GroboIL.Ldelem(Type type).
  • During code generation GroboIL builds the content of the evaluation stack and validates instructions arguments, and if something is not OK, immediately throws an Exception.
  • There is a debug ouput of the code being generated.
  • Full generics support.
  • It is possible to debug MethodBuilders (use constructor of GroboIL with parameter ISymbolDocumentWriter).
  • Appropriate performance. For instance, once I had to compile a program with 500000 instructions and it was verified by GroboIL in 3 seconds (I guess there is a way to break performance, but in practice such a program won't occure).

Example of debug output:

GroboIL.GetILCode()

        ldarg.0              // [List<T>]
        dup                  // [List<T>, List<T>]
        brtrue notNull_0     // [null]
        pop                  // []
        ldc.i4.0             // [Int32]
        newarr T             // [T[]]
notNull_0:                   // [{Object: IList, IList<T>, IReadOnlyList<T>}]
        ldarg.1              // [{Object: IList, IList<T>, IReadOnlyList<T>}, Func<T, Int32>]
        call Int32 Enumerable.Sum<T>(IEnumerable<T>, Func<T, Int32>)
                             // [Int32]
        ret                  // []

Release Notes

See CHANGELOG.

More Repositories

1

ZstdNet

Zstd wrapper for .NET
C#
276
star
2

retail-ui

React controls to implement standards at https://guides.kontur.ru/
TypeScript
245
star
3

dotEducation

База знаний для .NET разработчиков
215
star
4

GroBuf

Fast binary serializer
C#
61
star
5

cement

C# dependency management tool
C#
55
star
6

TypeScript.ContractGenerator

A tool that can generate TypeScript types from C# classes
C#
51
star
7

extern-csharp-sdk

SDK для работы с API Контур.Экстерна
C#
43
star
8

extern-java-sdk

SDK для работы с API Контур.Экстерна для платформы JVM
Java
27
star
9

project-calendar

Календари на каждый месяц от дизайнеров Контура
26
star
10

contests

C#
25
star
11

frontreport

Simple frontend logging collector written in Go
Go
24
star
12

GrobExp.Compiler

Efficient compiler of .NET expression trees
C#
21
star
13

results

C#
17
star
14

simple-container

Yet another DI container
C#
14
star
15

AoC2021

Advent of Code 2021 solutions from our community
1C Enterprise
12
star
16

react-ui-tour

Tours system for retail-ui
TypeScript
12
star
17

AoC2022

Advent of Code 2022 solutions from our community
Python
9
star
18

Selone

Flexible Selenium WebDriver extension
C#
9
star
19

GroboTrace

Lightweight .NET performance profiler
C#
9
star
20

markdown

TypeScript
8
star
21

openvpn-auth-radius

C# authentication plugin for OpenVPN
C#
8
star
22

perl-jsonschema-validator

JSON Schema and OpenAPI data validator for Perl
Perl
8
star
23

react-stack-layout

Flexbox based stack layouts for react
TypeScript
8
star
24

WiredTigerNet

C++/CLI wrapper for WiredTiger key-value engine
C
7
star
25

elopen

Kibana plugin for smooth opening of Elasticsearch indexes
JavaScript
6
star
26

cspreport

Simple CSP and HPKP report collector written in Go
Go
6
star
27

AoC2020

Advent of Code 2020 solutions by SKB Kontur's developers
C#
5
star
28

react-ui-testing

Page objects and useful extensions for testing applications based on react-ui control
C#
5
star
29

Excel.TemplateEngine

Engine for printing Excel documents with templates
C#
5
star
30

db-viewer

Database Viewer with custom configuration
C#
5
star
31

edi-api-client

EDI API client
C#
4
star
32

searchpicker

Searchpicker or combo-box dropdown ui form component, written in typescript
TypeScript
4
star
33

OctoPnP

TeamCity plugin to support Octopus-based deployment process
Java
4
star
34

extern-api-docs

Документация по работе с API Контур.Экстерна
4
star
35

react-ui-validations

Репозиторий переехал в skbkontur/retail-ui
JavaScript
4
star
36

AoC2023

Advent of Code 2023 solutions from our community
3
star
37

django-ru-validators

Django RU financial validators
Python
3
star
38

ofd-api-docs

3
star
39

cassandra-thrift-client

.NET client for Apache Cassandra thrift interface
C#
3
star
40

serilog-enrichers-exceptionstacktracehash

C#
3
star
41

cassandra-distributed-task-queue

.NET library implementing distributed task queue machinery using Apache Cassandra
C#
3
star
42

angular-router-ex

TypeScript
3
star
43

GrobExp.Mutators

Code generation mechanics for documents conversion and validation
C#
3
star
44

billing-ux-starter

CSS
2
star
45

edi-api-docs

Python
2
star
46

GroboContainer

Simple DI-container
C#
2
star
47

kontur.lz4.net

C#
2
star
48

perl-dbd-avatica

DBI driver for Apache Avatica
Perl
2
star
49

react-ui

React UI components doc
HTML
2
star
50

cajrr

Cassandra Java Range Repair service
Java
2
star
51

portal-oidc-docs

Python
2
star
52

highload-2017-quiz

Задание для участников HighLoad++ 2017
Go
1
star
53

GroboContainer.NUnitExtensions

NUnit extensions simplifying DI-container management in tests
C#
1
star
54

serilog-sinks-elkstreams

C#
1
star
55

oidc-client

1
star
56

react-sorge

TypeScript
1
star
57

react-props2attrs

TypeScript
1
star
58

KFixture

Generate test data
Kotlin
1
star
59

spring-reactive-mongo-soft-delete

SoftDelete with mongo for spring
Kotlin
1
star
60

docker-kibana

Custom Kibana image with plugins
Shell
1
star