Snippets tagged reflection
Create generic IEnumerable from non-generic
Depends on Castle Dynamic Proxy 2. Returns an IEnumerable<T> from a System.Type and a System.Collections.IEnumerable. It is a hack I wrote simply because I couldn't find anything in the framework to do this.
19 people like this
Posted: 1 years ago by Dan FinchConvert a obj list to a typed list without generics
This is used for building things with reflection at runtime. As ConstructorInfo arguments require typed collections, it is necessary when parsing to reflected records to first build up contents and then afterward convert the collected obj[] to a 'a[]. This is finally cast back to obj so it can be used as a ConstructorInfo argument.
18 people like this
Posted: 1 years ago by Rick MinerichFind verbose .NET types using Reflection
Searches all (currently loaded) types using Reflection to find the types with longest and shortest names of members. Uses average length of all type member names as a metric.
8 people like this
Posted: 1 years ago by Tomas PetricekDynamic operator using Dynamic Language Runtime
The snippet shows a simple implementation of the dynamic operator (?) that uses Dynamic Language Runtime and the C# implementation of dynamic operations. The snippet shows how to invoke instance methods with single argument.
25 people like this
Posted: 1 years ago by Tomas PetricekDynamic operator using Reflection
Demonstrates how to implement the dynamic operator (?) using .NET Reflection. The implementation supports calling constructors, propreties and methods using simple overload resolution (based on parameter count). It handles instance as well as static members.
41 people like this
Posted: 1 years ago by Tomas Petricek
Wimbledon special!
Tennis scoring system (at the game level). Includes some pattern-matching examples including 'when' guards.
4 people like this
Posted: 10 months ago by Kit EasonGet the F# module or type of the calling code.
This code snippet enables the retrieval of the entity (Module or F# Type) in which the calling code is executing. This can be used to find the module or type name.
2 people like this
Posted: 8 months ago by Huw SimpsonTransform expressions into Excel formulae
Sometimes it is extremely useful to check some calculations with Excel. The snippet shows how F# expressions can be transformed into Excel formulae. The data is exported together with the formulae, e.g. a, b and sum function as input sets A1's value to a, B1's to b and C1's formula to "=$A$1+$B$1"
14 people like this
Posted: 4 months ago by Natallie BaikevichFactoring out FSharpChart
Using FSharpChart control. Just call Charting.Plot() to chart series or collections of series. No need to create forms, etc.
2 people like this
Posted: 2 months ago by Boris Koganreflection
reflection, not exactly efficient but good canvas to start exploring
5 people like this
Posted: 1 months ago by David Klein