2. • Reusable concepts in c#.net:
• c#.net supports 2 types of reusable concepts
• 1.class Library(namespace)
• 2.windows forms control library(control)
• 1.Class library:
• It is the collection of namespaces. every namespace one dll(dynamic link library)
dll are implemented by oops concepts.by default dll are supported by cui
features(character user interface)
• dll are directly not executable.it is reusable concept from the .net framework.
• suppose we can create our own dll. this dll file reference to any application
• dll is converts into .exe file. class libraries one more reference name is called
assembly.
3. • Assemblies are classified into 3 types
• 1.private assembly
• 2.shared assembly
• 3.satellite assembly
• with extension .exe called application without exception .dll called
assembly
• 1.Private assembly:
• This is the module level dll. These dll files are implemented by oops
concept. private assembly dll is distributed only one application at a time.
it doesn't supports version, key file, Gac(Glabal assembly cache);
4. • example private assembly:
• 1.open vs-2012
• 2.file-new-project-classlibrary-ok
• namespace privateassembly
• {
• public class student
• {
• public int add(int a, int b)
• {
• return a + b;
• }
• public string addstr(string s1, string s2)
• {
• return s1 + s2;
• }
• public string display(string s)
• {
• return s;
• }
• }
• }
5. • Compile:
• goto-bulid -bulid solution-getting privateassebly.dll this dll file directly not
executable. its reusable concept. private assembly reference to console
application:
• 1.vs-2012
• 2.file -new -project-console application-ok
• add private assembly dll in the console application:
• goto -project menu-add reference-click on browse-privateassembly.dll-ok
• using privateassembly;
• static void Main(string[] args)
• { student obj = new student();
• Console.WriteLine(obj.add(100, 200).ToString());
• Console.WriteLine(obj.addstr("suresh", "technologies"));
• Console.ReadLine();
• }
6. • 2.Shared assembly:
• Shared assembly is module level dll. This dll file is implemented by oops
concepts.
• Shared assembly dll is distributed multiple applications.
• It supports version, key file, GAC(global assembly cache) shared assembly is also
called as public assembly.
• Shares assemblies sharing features from the assembly folder
c:windowsassembly
• This folder getting automatically while installing .net framework in the
windows folder.
• Shared assembly dll file depending on the unique version. we can create the
shared assembly following 5 steps.
7. • step 1:create shared assembly
• step 2:create strong name key
• step 3:strong name key reference to the shared assembly
• step 4:install the shared assembly in the assembly folder using
• Gacutil command
• step 5:shared assembly dll file reference to the windows
application
• strong name key file(.snk)
• using snk file(.snk) we can give unique version to the shared
assembly
• dll file
• version communicator between exe and shared assembly dll
file
8. sn command options:
• -k(key file):
• this command is used to creaye key file. by combining sn -k we can get file and
unique version
• syntax:
• sn -k filename.snk
• sn -k abc.snk
• sn is the .net framework dos command prompt.
• GACUtil(global assembly cache)
• gacutil is .net framework dos command prompt. using this command we can
install the assembly and uninstall assembly.
9. • Gacutil command options:
• 1.-i(install):
• using this command we can install shared assembly dll file
into assembly folder.
• 2.-U(uninstall):
• using this command we can uninstall shared assembly dll file
into assembly folder.
• example on shared assembly:
• step 1:create shared assembly
• step 2:create strong name key
• step 3:strong name key reference to the shared assembly
• step 4:install the shared assembly in the assembly folder using
10. • Gacutil command
• step 5:shared assembly dll file reference to the windows application
• step 1:create shared assembly
• 1.file-new-project-classlibrary-sharedassembly-ok
• code:
• namespace sharedassembly
• { public class Class1
• {
• public int tsal(int sal, int bonus, int ta)
• {
• return sal + bonus + ta;
• }
• public string display(string s)
• {
• return s;
• }
• }
• }
11. • Compilation:
• goto build-build solution-after getting sharedassembly.dll
• E:7pmonlinesharedassemblysharedassemblybinDebugsharedass
embly.dll
• copy the sharedassembly.dll path.
• step 2:create strongname key(.snk):
• to create strong name key in vs-dos command prompt
• how to open vs-crosstools command prompt:
• start-all programs-vs-2012-vstools-vs cross tools command
prompt-
• right click-Run as Administrator
12. • open vs-command promt
• c:>e:
• e:>cd paste sharedassembly.dll path
• e:>cd
E:7pmonlinesharedassemblysharedassemblybinDebug
• e:7pmonlineSaSaBindebug>dir(display all files)
• sharedassembly.dll
• sharedassemly.pdb
• e>7pmonlinesasabindebug>sn -k abc.snk
• key pair written to abc.snk
• step 3:strong name key reference to the shared assembly
13. • Assemblyinfo.cs:
• It is also called as metadata
• this file is used to give information about dll file(or)exe file.
Metadata means it gives the complete information about assembly
ie assembly key file, tile, version etc.
• go to solution explorer
• click on properties-click on assemblyinfo.cs
• [assembly:AssemblyKeyFile("E:7pmonlinesharedassemblyshare
dassemblybinDebugabc.snk")]
• goto -build-build solution-dll file
• step 4:install the shared assembly in the assembly folder using
• Gacutil command
14. • GAC (global assembly cache)
• using this command we install, uninstall assembly in the GAC folder
• open vs studio command prompt: e:7pmonlinesabindebug>gacutil -i sharedassembly.dll
• assembly successfully added to cache.
• step 5:shared assembly dll file reference to the windows application
• open -vs-2012 file-New-Project-windows application in the add button control
• add sharedassembly dll reference
• goto-project menu-add reference-browse-sharedassembly.dll
• using sharedassembly;
• private void button1_Click(object sender, EventArgs e)
• {
• Class1 obj = new Class1();
• MessageBox.Show(obj.tsal(15000, 5000, 500).ToString());
• MessageBox.Show(obj.display("sureshtechnologies"));
• }
15. • Satellite assembly:
• This assembly is supported only globalization and localization. we can
converts local language into global language. global language into local
language.
• Globalization:
• It involves writing the executable code for an application in such a way that
makes it culture-neutral and language neutral.
• Localization:
• It involves the customization of an application for specific local language. in
the satellite assembly add Resource file . Resource file extension is .resx
• Example on Multi-Language Application:
• 1.take the form
• 2.add 2 labels,2 textboxes,2 buttons,3 Link Buttons
• 3.add 3 Resource Files
16. Example
• using System.Reflection;
• using System.Resources;
• using System.Globalization;
• CultureInfo ci;
• ResourceManager rm;
• private void Form1_Load(object sender, EventArgs e)
• {
• rm = new ResourceManager("MultiLang.MyRes", Assembly.GetExecutingAssembly());
• }
• private void getvalues()
• {
• label1.Text=rm.GetString("L1",ci);
• label2.Text=rm.GetString("L2",ci);
• button1.Text=rm.GetString("B1",ci);
• button2.Text=rm.GetString("B2",ci);
• }
17. • private void linkLabel1_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
• { ci = new CultureInfo("en-US");
• getvalues();
• }
• private void linkLabel2_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
• { ci = new CultureInfo("hi-IN");
• getvalues();
• }
• private void linkLabel3_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
• { ci = new CultureInfo("te-IN");
• getvalues();
• }