Generating Data Access Assemblies with IronRuby Rob Rowe Blog: rob-rowe.blogspot.com.

Slides:



Advertisements
Similar presentations
Variables, Environments and Closures. Overview We will Touch on the notions of variable extent and scope Introduce the notions of lexical scope and.
Advertisements

1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
CPS 506 Comparative Programming Languages Abstract Data Type and Encapsulation.
Road Map Introduction to object oriented programming. Classes
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
Runtime Environments Source language issues Storage organization
Introduction to the C# Programming Language for the VB Programmer.
Run time vs. Compile time
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Lecture 9 Concepts of Programming Languages
.NET Attributes and Reflection “What a developer needs to know……” Dan Douglas Blog:
Abstract Data Types and Encapsulation Concepts
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
C++ fundamentals.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
OOP Languages: Java vs C++
Chapter 11 Abstract Data Types and Encapsulation Concepts.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
Programming Languages and Paradigms Object-Oriented Programming.
CIS NET Applications1 Chapter 2 –.NET Component- Oriented Programming Essentials.
Importing outside DLLs into.Net platform and using them By Anupama Atmakur.
Topic 3 The Stack ADT.
1 Stacks Chapter 4 2 Introduction Consider a program to model a switching yard –Has main line and siding –Cars may be shunted, removed at any time.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Mastering STACKS AN INTRODUCTION TO STACKS Data Structures.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
.NET Framework Danish Sami UG Lead.NetFoundry
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Introduction to TypeScript Sergey Barskiy Architect Level: Introductory.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Processes Introduction to Operating Systems: Module 3.
.NET Security and MSIL Tom Roeder CS fa. MSIL Common intermediate language really CIL in ECMA standard MSIL is common name Very close to C# (and.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Variables, Environments and Closures. Overview Touch on the notions of variable extent and scope Introduce the notions of lexical scope and dynamic.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Stack.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Bruno Cabral “Reflection, Code Generation and Instrumentation in the.NET platform” University of Coimbra.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
RealTimeSystems Lab Jong-Koo, Lim
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Abstract Data Types and Encapsulation Concepts
Variables, Environments and Closures
Activities and Intents
Chapter 3: Using Methods, Classes, and Objects
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Stacks Chapter 4.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Chapter 6 Methods: A Deeper Look
Variables, Environments and Closures
UNIT V Run Time Environments.
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Quiz Points 1 Rules Raise your hand if you know the question
Advanced .NET Programming I 9th Lecture
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Generating Data Access Assemblies with IronRuby Rob Rowe Blog: rob-rowe.blogspot.com

Why? Make tedious changes easier and quicker Create code based off of data specs from outside sources Wanted to learn Ruby Used IronRuby to access to.NET libraries such as System.Reflection.Emit Generate a DLL without compilation

What is IronRuby? An implementation of Ruby 1.8.x Built on top of.NET’s Dynamic Language Runtime Allows IronRuby to access.NET objects such as System.Reflection or any other.NET library Easy to ‘load’.NET libraries

Overview Generated Code – Models DLL and C# Domain/Service layer Consuming Application – ASP.NET MVC 2

Field Definitions Tables

Creating a.NET Assembly 1.Establish Assembly characteristics 2.Create the new Assembly 3.Define the Module 4.Create the Class 5.Create the Properties a.Create the backing field b.Create the Property c.Create Getter d.Create Setter 6.Save the Assembly

1. Establish Assembly Characteristics Create an instance of the System.Reflection.AssemblyName class Set Version Set Name Can set CultureInfo, Crypto KeyPair among as well as other settings

2. Create the new Assembly Creates the assembly in memory The first parameter is the AssemblyName object from step 1. Second parameter sets the permissions for the assembly. Here we can run it and save it to the file system. Returns an AssemblyBuilder Object. Used to create the module for the assembly.

3. Define the Module Each.NET assembly must have at least one module ‘Container’ for classes, interfaces, etc. Parameters: 1.Name of the module 2.Name of the DLL 3.false – so no symbols are created

4. Create the is the object returned when we created the module. Creates the class ‘under’ the module First parameter is fully qualified name of the class Second parameter is used to set public, static, etc. Returned TypeBuilder object is used to create the class’s fields and properties.

5a. Create Fields Must create a field for each property Creates a private field used by the getter/setters Uses the class’s TypeBuilder object Parameters ▫Defines the name ▫CLR Type ▫Sets Access level

5b. Create Properties Creates the Property’s TypeObject used for getter/setters Parameters: ▫Property Name ▫Says there’s a default value for this property ▫The CLR Type ▫Since there are no parameters for our properties we pass in null

5c. Create Getter – Prep Work Creates the Get method TypeObject DefineMethod’s parameters ▫Name of the method ▫Attributes for the method ▫Return type (CLR type) ▫Parameters to the method – none for getter GetILGenerator - creates the object that is used to create the IL code

5c. Create Getter – Method Body OpCodes.Ldarg_0 – loads the first argument on the stack which is ‘this’ in our case. OpCodes.Ldfld – pushes the value of the private field onto the stack. OpCodes.Ret – the returns the last item on the evaluation stack, the value of the private field.

5d. Create Setter – Parameters Constructs the Type array needed for the setter’s method parameters The type added to the list is the CLR type of the property Need to use a generic list to create the necessary CLR array Use List ’s ToArray method to get around CLR array type issues

5d. Create Setter – Method Body OpCodes.Ldarg_0 – loads the first argument on the stack which is ‘this’ in our case. OpCodes.Ldarg_1 - loads the setter parameter onto the stack OpCodes.Stfld – sets the value of private_field to the value of the item popped from the stack. OpCodes.Ret – adds the return statement.

5e. Finalizing Property Creation Need to associate the getter and setter with our new property Use the property TypeBuilder to associate the two method’s TypeBuilder objects with the IL we just created

6. Saving the Assembly The assembly is saved to the file system by using the AssemblyBuilder object’s Save method Once it has been saved we can use our new Models DLL like any other assembly.

Resources/Contact Info Blog: Code: ybuilder ybuilder Books: IronRuby Unleashed, Programming Ruby (AKA The Pickaxe Book)IronRuby UnleashedProgramming Ruby (AKA The Pickaxe Book)