AP 08/01 Component Programming with C# and.NET 1st Class Component Support Robust and Versionable Creating and using attributes API integration –DLL import.

Slides:



Advertisements
Similar presentations
DIGIDOC A web based tool to Manage Documents. System Overview DigiDoc is a web-based customizable, integrated solution for Business Process Management.
Advertisements

Attributes Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Advanced Object-Oriented Programming Features
1/50 Project Management. 2/50 StumbleUpon 3/50 Overview Customize? Why, what, how?.NET Framework overview & fundamentals Class libraries, namespaces,
Writing Object Oriented Software with C#. C# and OOP C# is designed for the.NET Framework  The.NET Framework is Object Oriented In C#  Your access to.
C# Language Design Peter Hallam Software Design Engineer C# Compiler Microsoft Corporation.
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
GTECH 731 Lab Session 2 Lab 1 Review, Lab 2 Intro 9/6/10 Lab 1 Review Lab 2 Overview.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 20 Microsoft’s Approach 3 – C# Rob Pooley
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
OFC302 Building Smart Document Solutions in Word & Excel Martin Sawicki Lead Program Manager.
February 24 th -25 th 2004 Daragh Byrne – EPCC Additional.NET Concepts.
Java Beans.
.NET Framework Introduction: Metadata
The Metadata System1. 2 Introduction Metadata is data that describes data. Traditionally, metadata has been found in language- specific files (e.g. C/C++
CIS NET Applications1 Chapter 2 –.NET Component- Oriented Programming Essentials.
.NET Framework & C#.
Introduction to Classes SWE 344 Internet Protocols & Client Server Programming.
Obsydian OLE Automation Ranjit Sahota Chief Architect Obsydian Development Ranjit Sahota Chief Architect Obsydian Development.
Component-based software engineering
Component-Based Software Engineering Component process.
Nilotpal Bhattacharya Partner Technical Consultant| Microsoft.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
Web Services Week 2 Aims: Getting started with creating simple C# applications within Visual Studio.NET Objectives: –An introduction to the syntax of C#.NET.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
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.
Managed C++. Objectives Overview to Visual C++.NET Concepts and architecture Developing with Managed Extensions for C++ Use cases Managed C++, Visual.
.NET Framework Danish Sami UG Lead.NetFoundry
Writing JavaDocs Mimi Opkins CECS 274 Copyright (c) Pearson All rights reserved.
Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications.
.Net and Web Services Security CS795. Web Services A web application Does not have a user interface (as a traditional web application); instead, it exposes.
Introduction to C # – Part 2 Stephen Turner Software Design Engineer Microsoft UK.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Component Programming with C# and.NET. C# components The most commonly used components in.NET are the visual controls that you add to Windows Forms such.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Advanced C # Mark Sapossnek CS 594 Computer Science Department Metropolitan College Boston University.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Introduction to C # – Part 1 Stephen Turner Software Design Engineer Microsoft UK.
One of the most prevalent powerful programming languages.
Introduction to C#. C# – The Big Ideas The first component oriented language in the C/C++ family Everything.
ILM Proprietary and Confidential -
C# Programming: From Problem Analysis to Program Design1 10 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Harsh Jegadeesan (CSD) Introduction to C#. Harsh Jegadeesan (CSD) C# – The Big Ideas The first component oriented language in the C/C++ family Everything.
Module 14: Attributes. Overview Overview of Attributes Defining Custom Attributes Retrieving Attribute Values.
Attributes C#.Net Software Development Version 1.0.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Microsoft Visual Studio 2005 Tools for the Office System: Building Office Solutions Using Visual Studio 2005 Tools for Office Andrew Coates Developer Evangelist.
Classes Single inheritance Single inheritance Multiple interface implementation Multiple interface implementation Class members Class members  Constants,
.NET Mobile Application Development XML Web Services.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Arrays and Indexers Programming in C# Arrays and Indexers CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Introduction to Web Application
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Reflection and Attributes.
.Net Reflection Taipan Tamsare. Overview Reflection core concepts Exploring metadata Detail information Attributes Building Types at runtime.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
The 100% Inspiration Tour.
Native / Managed Interop
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
XAML User Interface Creation in C#
Introduction to C# AKEEL AHMED.
Moving from ASP to ASP.NET
.NET and .NET Core 10. Enabling Contracts Pan Wuming 2017.
How to organize and document your classes
Jim Fawcett CSE775 – Distributed Objects Spring 2006
Presentation transcript:

AP 08/01 Component Programming with C# and.NET 1st Class Component Support Robust and Versionable Creating and using attributes API integration –DLL import –COM support Preserve Existing Investments

AP 08/01 What defines a component? – Properties, methods, events – Design-time and runtime information – Integrated help and documentation C# has first class support – Not naming patterns, adapters, etc. – Not external files Easy to build and consume

AP 08/01 public class Button: Control { private string caption; private string caption; public string Caption { public string Caption { get { get { return caption; return caption; } set { set { caption = value; caption = value; Repaint(); Repaint(); } }} Properties Properties are “smart fields” –Natural syntax, accessors, inlining Button b = new Button(); b.Caption = "OK"; String s = b.Caption;

AP 08/01 Indexers Indexers are “smart arrays” –Can be overloaded public class ListBox: Control { private string[] items; public string this[int index]{ get { return items[index]; } set { items[index] = value; Repaint(); } ListBox listBox = new ListBox(); listBox[0] = "hello"; Console.WriteLine(listBox[0]);

AP 08/01 Events Efficient, type-safe and customizable –Built on delegates public class MyForm: Form { public MyForm() { Button okButton = new Button(...); okButton.Click += new EventHandler(OkButtonClick); } void OkButtonClick(…) { ShowMessage("You clicked OK"); }

AP 08/01 Design/Runtime Information Add information to types + methods? –Transaction required for a method? –Mark members for persistence? –Default event hookup? Traditional solutions –Lots of custom user code –Naming conventions between classes –External files (e.g..IDL,.DEF) The C# solution - Attributes

AP 08/01 Attributes [HelpUrl(“ class SomeClass { [WebMethod] [WebMethod] void GetCustomers() { … } void GetCustomers() { … } string Test([SomeAttr] string param1) {…} string Test([SomeAttr] string param1) {…}} Appear in square brackets Attached to code elements

AP 08/01 Attribute Fundamentals Attributes are classes! Completely generic Easy to attach to types and members Attributes can be queried at runtime class HelpUrl : System.Attribute { public HelpUrl(string url) { … } … } [HelpUrl(“ class SomeClass { … } Type type = Type.GetType(“SomeClass”); object[] attributes = type.GetCustomAttributes();

AP 08/01 Attributes in.NET Web Services COM Interop Platform Invoke (DLL Interop) Transaction Contexts Permissions Custom XML Persistence User-defined attributes to specify non-functional component properties (RT / FT / Security / Config. )

AP 08/01 XML Comments XML schema for comments – Method description – Parameter types, names and descriptions – Add your own tags - just XML Compiler and IDE support – Compiler creates XML file for all classes – IDE support for entry and display Used throughout.NET Framework

AP 08/01 Using Attributes [HelpUrl(“ class SomeClass { [Obsolete(“Use SomeNewMethod instead”)] public void SomeOldMethod() { … } public string Test( [SomeAttr()] string param1 ) { … } }

AP 08/01 Using Attributes (contd.) [HelpUrl(" class MyClass {} [HelpUrl(" Tag=“ctor”)] class MyClass {} [HelpUrl(" HelpUrl(" Tag=“ctor”)] class MyClass {}

AP 08/01 Querying Attributes Use reflection to query attributes Type type = typeof(MyClass); foreach(object attr in type.GetCustomAttributes() ) { if ( attr is HelpUrlAttribute ) { HelpUrlAttribute ha = (HelpUrlAttribute) attr; myBrowser.Navigate( ha.Url ); }

AP 08/01 Replication based on Attributes Specification of a component‘s non-functional properties at design time A tool may generate code to automatically create replicated objects Component behavior described by user-defined attributes namespace CalculatorClass { using System; using proxy; [TolerateCrashFaults(4)] public class Calculator {... public double add (double x, double y) { return x + y; }

AP 08/01 Behind the scenes... public sealed class Calculator:CalculatorClass.Calculator { private CalculatorClass.Calculator[] _bc; public Calculator(): base() { _ErrorCount=0; int _Count=1; System.Attribute[] _arAtt = System.Attribute.GetCustomAttributes(GetType()); foreach(System.Attribute _attr in _arAtt) { if(_attr is TolerateCrashFaults) _Count=((TolerateCrashFaults)_attr).Count; } /// creation of sufficiently many proxy objects _bc=new CalculatorClass.Calculator[_Count]; Reflection Attribute-based programming

AP 08/01 From the consumer‘s perspective namespace CalculatorFront { using System; using CalculatorClass; public class MainClass { public MainClass() {} public static int Main(string[] args) { Calculator calc = new Calculator();... result = calc.add(val1, val2); /// using CalculatorClass; using proxy; Minimal code changes

AP 08/01 Calling Into Existing DLLs.NET Framework contains attributes to enable calling into existing DLLs System.Runtime.InteropServices –DLL Name, Entry point, Parameter and Return value marshalling, etc. Use these to control calling into your existing DLLs –System functionality is built into Framework

AP 08/01 Attributes to specify DLL Imports [DllImport("gdi32.dll",CharSet=CharSet.Auto)] public static extern int GetObject( int hObject, int nSize, [In, Out] ref LOGFONT lf); [DllImport("gdi32.dll")] public static extern int CreatePen(int style, int width, int color);

AP 08/01 COM Support.NET Framework provides great COM support –TLBIMP imports existing COM classes –TLBEXP exports.NET types Most users will have a seamless experience

AP 08/01 Calling into a COM component Create.NET assembly from COM component via tlbimp Client apps may access the newly created assembly using System; using System.Runtime.InteropServices; using CONVERTERLib; class Convert { public static void Main(string [] args) { CFConvert conv = new CFConvert();... fahrenheit = conv.CelsiusToFahrenheit( celsius );

AP 08/01 COM Support Sometimes you need more control –Methods with complicated structures as arguments –Large TLB – only using a few classes System.Runtime.InteropServices –COM object identification –Parameter and return value marshalling –HRESULT behavior

AP 08/01 COM Support Example [Guid(“56A868B1-0AD4-11CE-B03A-0020AF0BA770”)] interface IMediaControl { void Run(); void Pause(); void Stop(); … void RenderFile(string strFilename); } Back to projects

AP 08/01 The Evolution of Components (Microsoft-style)

AP 08/01 Type fragmentation under COM

AP 08/01 Pervasive Type in the CLR

AP 08/01 Type segregation under XML

AP 08/01 Object Creation and the Loader

AP 08/01 CLR Architecture

AP 08/01 on-the-fly COM COM callable wrapper (CCW) runtime callable wrapper (RCW)

AP 08/01 The CLR Type System

AP 08/01 Metaprogramming and Reflection in.NET

AP 08/01 Pervasive type and GetType

AP 08/01 Pervasive type and System.Type Back to overview