473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Check where library is called from

I have an class library, which I shared with some of my apps.
Some of them are Winfroms apps, others are ASP .NET.
How could I check from a method in my library, is it called form an
Winforms or ASP .NET?

tnx

Nov 21 '05 #1
4 1254
You could use reflection to walk the stack and see who called you, but... If
you have a routine that wants to behave differently based on who calls it,
you would really be better off providing an argument to that routine to
specify the desired behavior explicitly. Along the same lines, you could
give the class a parameterized constructor that lets the instance know
whether it has been instantiated by WinForms or ASP.NET; store that info in
a class variable, and let the instance methods use that info as they see
fit.

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have an class library, which I shared with some of my apps.
Some of them are Winfroms apps, others are ASP .NET.
How could I check from a method in my library, is it called form an
Winforms or ASP .NET?

tnx

Nov 21 '05 #2
I don't realy want to do it this way.
The library hold 100-120 classes and modifing their constructors is a
big pain. That is way I asked the question.
I need this only in method level.

Nov 21 '05 #3
Hi,

(Untested) Throw an exception that you handle to be able to look
at the exceptions classes stack trace.

http://msdn.microsoft.com/library/de...tracetopic.asp
Ken
---------------------------
"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have an class library, which I shared with some of my apps.
Some of them are Winfroms apps, others are ASP .NET.
How could I check from a method in my library, is it called form an
Winforms or ASP .NET?

tnx
Nov 21 '05 #4
Nikolay,
I would consider having a value in my app.config/web.config that indicated
if the app itself is a web app or a win forms app. Especially if web or win
determined how a specific routine behaved. The specific routine would be an
overridable method of an abstract base class (a MustInherit class), where
the app.config indicated the specific concrete class to create (basically a
Strategy pattern & Plug-in pattern
http://www.martinfowler.com/eaaCatalog/plugin.html)

My app/dll would only use the StrategyBase abstraction, while there would be
specific implementations for both ASP.NET & Win Forms. This would also allow
defining a Console App & Windows Service strategies also.

I would store the full name of the concrete class that inherits from the
abstract base class in the app.config file. I then use
System.Activator.CreateInstance to create instances of this class. Something
like:

<configuration>
<configSections>
<!-- define a custom config section to keep appSettings clean -->
<sectionGroup name="myCompany">
<sectionGroup name="myProduct">
<section name="myDll"
type="System.Configuration.SingleTagSectionHandler "
/>
</sectionGroup>
</sectionGroup>
</configSections>
<myCompany>
<myProduct>
<!-- the "type" attribute is "namespace.class, assembly" -->
<myDll setting1="Value1" setting2="value two"
type="MyProject.AspNetStrategy, MyProject" />
</myProduct>
</myCompany>
</configuration>

Imports System.Configuration

Public MustInherit Class StrategyBase

Public MustOverride Sub Something()

Public Shared Function GetStrategy() As StrategyBase
Dim myDllConfig As IDictionary
Dim value1 As String
Dim value2 As String
Dim strategyTypeName As String

myDllConfig =
DirectCast(ConfigurationSettings.GetConfig("myComp any/myProduct/myDll"),
IDictionary)
value1 = DirectCast(myDllConfig("setting1"), String)
value2 = DirectCast(myDllConfig("setting2"), String)
strategyTypeName = DirectCast(myDllConfig("type"), String)

Dim strategyType As Type = Type.GetType(strategyTypeName)
Dim strategyObject As Object =
Activator.CreateInstance(strategyType)
Return DirectCast(strategyObject, StrategyBase)
End Function

End Class

Public Class AspNetStrategy
Inherits StrategyBase

Public Overrides Sub Something()
' Do "Something" for ASP.NET apps
End Sub

End Class

Public Class WinFormsStrategy
Inherits StrategyBase

Public Overrides Sub Something()
' Do "Something" for Win Forms apps
End Sub

End Class

In the above "value1" & "value2" could optionally be used as parameters to
the specific StrategyBase object.

See the following on how to create new sections via the configSections
section.

http://msdn.microsoft.com/library/de...onhandlers.asp

and:
http://msdn.microsoft.com/library/de...ionsschema.asp

Also read about the System.Configuration.ConfigurationSettings class and
other classes in the System.Configuration namespace.
Hope this helps
Jay

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
|I have an class library, which I shared with some of my apps.
| Some of them are Winfroms apps, others are ASP .NET.
| How could I check from a method in my library, is it called form an
| Winforms or ASP .NET?
|
| tnx
|
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
23
by: John Rivers | last post by:
This shows you how to implement html rendering methods and libraries in ASPX pages. This also means super fast debugging as no re-initialising of IIS is required after editting! This gets...
4
by: Shawn | last post by:
Hi. I have a ToolBar with a couple of ToolBarButtons. On postback after clicking on of the buttons Page_Load is called first then the ToolBarButton's click event is called. Is there anyway for...
4
by: Rich | last post by:
Hi I have five check boxes in a windows form. They are called chkEQUDS01, chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am getting the text name for the check boxes from a datatable...
9
by: Sameh Ahmed | last post by:
Hello there Is there a way through dotNet to check if a certain user is a member of a specific group? I use ADSI to get the memberships of the user then compare them to the group I want to check,...
5
by: Tony | last post by:
Every 10 seconds I need to search a SQL table for orders to print. The orders are created through WebForms on ASP.NET clients. The orders should not print until 10 minutes before they are due. ...
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
55
by: lovecreatesbea... | last post by:
Do you check all error conditions for all library calls in you code? Is it necessary to check all errors? Is it convenient to check all errors (or how to make code clean and readable with mass of...
2
by: Christof Warlich | last post by:
Hi, I'm working on a (template) library that is up to now entirely implemented in header-files. This makes the library quite convenient to use as no extra object code needs to be linked when...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.