This is a continuation of LINK interface document 1; here we are showing how to retrieve the names of the interfaces used in an external class

Step: 1 Create a new website and add class. CallInteface.cs

Step: 2 Edit the code

Class : CallInterface.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for CallInterface
/// </summary>
public interface team1 { void myfunction(string str); }
public interface team2 { void myfunction(string str); }
public class CallInterface : team1, team2, IServiceProvider
{
interface team1 { void myfunction(string str); }
interface team2 { void myfunction(string str); }
public string strConstructior;
public string testInterface;
public string acknowledge;
public CallInterface()
{
//
// TODO: Add constructor logic here
//
strConstructior = " For Joining the Team";

}
public void myfunction(string strparam)
{
testInterface = strparam + "Joined the team";
acknowledge = strparam + strConstructior;

}
}

Code Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



public partial class _Default : System.Web.UI.Page, team1, team2
{

protected void Page_Load(object sender, EventArgs e)
{
show_interfaces();
L1.Text += "<hr/>";
CallInterface ci = new CallInterface();
//Debug.Print(ci.GetType().GetInterfaces().ToString());
L1.Text += "Object ci.GetType().GetInterfaces() : " +
(ci.GetType().GetInterfaces().ToString());
L1.Text += "<br/>Before Calling ci.myfunction() : "
+ ci.testInterface;
ci.myfunction(" Coach Pablo ");
L1.Text += "<br/>After Calling ci.myfunction() :"
+ ci.testInterface;
team1 t1 = (team1)ci;
t1.myfunction(" Thanks ");
L1.Text += "<br/>Team 1 Says" + ci.acknowledge;
team2 t2 = (team2)ci;
t2.myfunction(" Welcome ");
L1.Text += "<br/>Team 2 Says" + ci.acknowledge;

}
// this method must be added
public void myfunction(string str)
{
L1.Text += "<br/> What I am doing here" + str;
}

protected void show_interfaces()
{
try
{
Type[] myObjectArray= typeof(CallInterface).GetInterfaces();
L1.Text+=("The interfaces inherited by the CallInterface class are:<br/>");
for (int index = 0; index < myObjectArray.Length; index++)
{
L1.Text+="&nbsp : " +(myObjectArray[index]) + "&nbsp,";
}
}
catch (Exception e)
{
L1.Text+=("An exception occurred.");
L1.Text+=("Message: " + e.Message);
}
}
}



Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>mm.Interface1</title>

</head>
<body>
<form id="form1" runat="server">
<div style="padding: 10px; background-color: #FFFFCC; border: 2px solid #800000; width: 477px;">

<asp:Label ID="L1" runat="server" Text="Label Blank <br/>"></asp:Label>
</div>
</form>
</body>
</html>
 

 

Step: 3 Runtime

Step:

Step:

Step:

Step: