1 / 51

Microsoft .NET Interoperability for Beginners

Microsoft .NET Interoperability for Beginners. Vjekoslav Babic (Fortempo). About me. Vjekoslav Babić consultant, trainer, blogger, author Blog : vjeko.com E-mail: vjeko@vjeko.com Author of many How Do I… videos for MSDN and PartnerSource for NAV 2013 and NAV 2013 R2

alina
Télécharger la présentation

Microsoft .NET Interoperability for Beginners

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Microsoft .NET Interoperability for Beginners Vjekoslav Babic (Fortempo)

  2. About me Vjekoslav Babić consultant, trainer, blogger, author Blog: vjeko.com E-mail: vjeko@vjeko.com Author of many How Do I… videos for MSDN and PartnerSourcefor NAV 2013 and NAV 2013 R2 Co-author of “Implementing Microsoft Dynamics NAV 2009” book

  3. How Users See Programmers

  4. How Programmers See Users

  5. NAV Programmer Programming in C/AL

  6. NAV Programmer Programming in .NET

  7. What Do Programmers Really Do? • A lot of the time?

  8. So, What Do Programmers Do a Lotof the Time?

  9. Unfortunately – it is often a wrong wheel

  10. What Are We Going To Do Today… • Managing strings and text • Managing dates, times, and numbers • Accessing operating system, file system, and the environment • Managing data, arrays, collections, and streams C/AL.NET

  11. The DotNet Data Type • Variables of type DotNet give access to .NET Framework • Each DotNet variable specifies: • Assembly • Type • DotNet gives access to: • Methods • Properties • Constructors • Enumerations

  12. System.String • A powerful class to handle text information. • Maps fully and directly to Text data type in C/AL.

  13. System.Text.StringBuilder • A very powerful class to handle large text data efficiently.

  14. Constructors • Create an instance of a class. • There is no equivalent in C/AL to constructors. • CREATE function for instantiating automation objects is the closest • Typically used to: • Initialize the default state of an object • Execute default initialization logic • Limit instantiation

  15. Syntax of a Constructor • The name of the constructor always matches the class name. • This probably looks confusing in C/AL: • StringBuilder:= StringBuilder.StringBuilder; • (why in the Earth do we need all those StringBuilders?) • Replace the StringBuildervariable name with s, and it’s more manageable: • s := s.StringBuilder; • The syntax of the constructor in C/AL is the following: • Variable := Variable.[Class Name]({argument1, …});

  16. Overloading • Capability that allows multiple members to use the same name as long as the signature remains different. • C/AL understands overloading of: • Methods • Constructors

  17. System.Diagnostics.Stopwatch • A simple and useful class to handle time measurements.

  18. Namespace • A higher-level scope used to organize code • Namespace has a many-to-many relationship to assemblies: • One assembly can contain multiple namespaces • The same namespace can span multiple assemblies

  19. System.Text.RegularExpressions • A namespace containing classes for managing regular expressions. • In case you didn’t know: • Regular Expressions (RegEx) are a language used for searching text data through pattern matching • Regular Expressions are SQL of textual data

  20. System.DateTime • Manages date and time information. • Maps fully and directly to DateTimedata type in C/AL. • Many useful properties and methods.

  21. System.Globalization • Namespace that defines a lot of useful type for managing date and time formats, regional settings, cultures, etc. • Useful classes: • Calendar • CultureInfo • DateTimeFormatInfo • NumberFormatInfo

  22. System.Globalization.CultureInfo • Provides access to culture information. Cultures are the heart of the .NET localization/globalization functionality.

  23. System.Globalization.DateTimeFormatInfo • Provides access to date and time formatting information.

  24. System.Globalization.NumberFormatInfo • Provides access to number formatting information.

  25. System.Math • Provides methods for trigonometric, logarithmic, and other common mathematical functions.

  26. System.Numerics.BigInteger • Represents an arbitrarily large integer value, without any theoretical upper or lower bounds.

  27. System.Convert • Converts a base type to another base type.

  28. System.IO • Namespace that provides many useful input and output classes.

  29. System.IO.File • Provides static methods for the creation, copying, deletion, moving, and opening of files.

  30. Static objects and methods • Static classes cannot be instantiated • Static methodscan be called on classes • Static classes and members are sharedfor the whole application domain • Microsoft Dynamics NAV Server runs as a single application domain

  31. System.IO.Directory • Exposes static methods for creating, moving, and enumerating through directories and subdirectories.

  32. System.IO.Path • Performs operations on String instances that contain file or directory path information.

  33. System.IO.FileSystemWatcher • Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.

  34. Events • Enable a class to notify other classes when something of interest happens. • Equivalent to C/AL triggers. • Events are not automatically exposed. • You must first set the WithEventsproperty. • Events can run be: • Server-Side: default behavior, if RunOnClientis No • Client-Side: if RunOnClientis Yes

  35. Enumerations • Types that consist of set of named constants. • Similar, but not nearly equal to C/AL options.

  36. Support for Enumerations in C/SIDE

  37. System.Diagnostics.EventLog • Provides interaction with Windows event logs.

  38. Managing Type Information at Runtime • System.Type • GETDOTNETTYPE • CANLOADTYPE

  39. Arrays and Collections • Arrays: • Contain a fixed number of values of the same data type • Roughly correspond to C/AL arrays (variables with Dimensions property) • Collections: • Contain an arbitrary, flexible number of values of the same data type • No equivalent in C/AL • Both arrays and collections are extensively used in .NET

  40. System.Array • Provides methods for creating, manipulating, searching, and sorting arrays. • Serves as the base class for all arrays in the common language runtime.

  41. Enumerators • Enable iterating through arrays and collections. • C# uses the foreachkeyword to manage the iteration. • Two interfaces are in charge of the enumerator-based iteration: • IEnumerable<T> • IEnumerator<T> • IEnumerable<T> • Exposestheenumerator • IEnumerator<T> • Allowsiterationthroughenumerableobject • Current • MoveNext

  42. System.Object • The ultimate base class of all classes in the .NET Framework. • The root of the type hierarchy.

  43. System.Collections.HashTable • Represents a list of key/value pairs that are stored by using a hash table.

  44. System.Collections.Generic.List<T> • Represents a strongly typed list of objects that can be accessed by index. • Provides methods to search, sort, and manipulate lists.

  45. Generics • Allow a single design-time declaration that compiles to multiple run-time types. • List<T> can compile to List<int>, List<string>, or List<MyDesiredClass> • Supported on: • Classes and interfaces • Methods • Properties • Structures • Fields • In C/AL, all generics are of type System.Object

  46. Mapping .NET Types to C/AL • Some types map fully: • String • DateTime • InStream and OutStream • Many data types map uni-directionally: • Most simple data types (Boolean, Decimal, Integer, etc.) • Some complex data types (Duration) • You cannot use uni-directionally mapped .NET data types in C/AL directly.

  47. System.IO.Stream • A class that provides a generic view of a sequence of bytes. • Typical descendants: • System.IO.MemoryStream • System.IO.FileStream • Fully mutually interchangeable with both InStream and OutStream C/AL types. • Limitation: • CREATEOUTSTREAM and CREATEINSTREAM cannot be called on System.IO.Stream

More Related