|
I am coding this utility to test raising of an exception, however, I have noted that Visual Studio 2010 IDE does not allow me to call the ArithmeticUtilityException.Divide() method. Why?
I have also (desperately) tried to declare the class as static and the Divide() method as static, however, no joy either.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CustomException
{
class Program
{
static void Main(string[] args)
{
ArithmeticUtilityException utility = new ArithmeticUtilityException();
}
}
public class ArithmeticUtilityException : ApplicationException
{
public ArithmeticUtilityException() : base() {}
public ArithmeticUtilityException(string message) : base(message) {}
public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
}
public static class ArithmethicUtility
{
public decimal Divide(decimal number, decimal divisor)
{
try
{ return number / divisor; }
catch (Exception err)
{
ArithmeticUtilityException errNew = new ArithmeticUtilityException("Divide by zero", err);
throw errNew;
}
}
}
}
NOTES
1. Related link Static Classes and Static Class Members (C# Programming Guide)
2. Personal note. ..\Training\CustomException.
Jon
|
|
|
|
|
jon_80 wrote: does not allow me to call the ArithmeticUtilityException.Divide() method. Why?
Because you don't have one?
public class ArithmeticUtilityException : ApplicationException
{
public ArithmeticUtilityException() : base() {}
public ArithmeticUtilityException(string message) : base(message) {}
public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
}
public static class ArithmethicUtility
{
public decimal Divide(decimal number, decimal divisor)
{
...
}
}
Divide is a member of ArithmethicUtility, not ArithmeticUtilityException
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CustomException;
namespace CustomException
{
class Program
{
static void Main(string[] args)
{
ArithmethicUtility utility = new ArithmethicUtility();
Decimal myNumber = utility.Divide(5, 0);
}
}
public class ArithmeticUtilityException : ApplicationException
{
public ArithmeticUtilityException() : base() {}
public ArithmeticUtilityException(string message) : base(message) {}
public ArithmeticUtilityException(string message, Exception inner) : base(message, inner) {}
}
public class ArithmethicUtility
{
public decimal Divide(decimal number, decimal divisor)
{
try
{ return number / divisor; }
catch (Exception err)
{
ArithmeticUtilityException errNew = new ArithmeticUtilityException("Divide by zero", err);
throw errNew;
}
}
}
}
Jon
|
|
|
|
|
You're welcome.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
There is a com dll written by C++ ATL. There is no embedded type library resource in it, although I have its type library(.tlb file) seperately.
I can't add it to my C# project references. So, how should i do to use it?
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:18am.
|
|
|
|
|
Thanks for your reply. As we know, an atl com dll only export five functions:
DllCanUnloadNow,DllGetClassObject,DllRegisterServer,DllUnregisterServer.
So, im afraid that couldn't help to reach my aim, right?
|
|
|
|
|
Because it exports the function DllRegisterServer I would assume, that this COM dll isn't
registered. Just use the regsrv32.exe to register it.
Example:
regsvr32.exe [Path]example.dll
After you registered it, it should be visible in the COM tab of the "add reference" wizard.
Greetings
Covean
|
|
|
|
|
Oh, of course the com dll has been registered successfully. When add its reference by vs(it can be listed in the com tab list), vs will give me an error messagebox says "A reference to '*** Type Library' couldn't be added. This is not a COM component". But, if the dll has embedded type library in it, it will be ok.
|
|
|
|
|
Sorry but I never ran in this problem, so I never had to find a solution for this.
Greetings
Covean
|
|
|
|
|
Oh, thanks all the same. I will be glad to tell you the solution if i got it.
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:17am.
|
|
|
|
|
My be. But my main problem is create the component class.
You know, in C#, i just reference the com dll. If i have to use the raw com dll file as common unmanaged dll, im not sure how to create the object and how to translate parameters.
So, I hope to add referenct it via its type library(.tlb file).
|
|
|
|
|
I am trying to put this into actual class and i am having difficutlties in it. I am not sure how to show relationships. I have put down some classes that it may need.
Build a class called Employee reporting relationships. The class will be used as a part of some application. Its main purpose is to keep and maintain data related to the reporting relationships between employees within an organization.
Employee can have zero or more managers. Manager is an employee who has one or more other employees reporting to him.
Class EmployeeReportingRelationships
{
}
Class Employee
{
}
Class Manager:Employee
{
}
modified on Wednesday, June 23, 2010 1:47 AM
|
|
|
|
|
I'm afraid noone will do your homework for you.
Try thinking further, and come back with a more precise question.
|
|
|
|
|
Well, I am not asking to write exact code for me or atleast if you could engligten me with some ideas wouldn't be bad. I find hard to comphrend and put into OOP. I know how to write classes and properties but i am not so sure what to do in it.
|
|
|
|
|
So you need to break down the requirements into logical parts.
Employee can have zero or more managers.
So, your Employee class will need a property that has a variable size that is of type Manager . Perhaps a List<Manager>
Manager is an employee...
So the Manager class should derive from Employee as you have already done.
...who has one or more other employees reporting to him.
So the Manager class needs an additional property that has a variable size that is of type Employee . Possibly, the extra Manager class isn't needed as checking this property is > 0 will indicate that they are manager anyway.
This is what programming is all about, turning real world situations into code and in the case of OOP creating objects to represent them and adding properties to give the details/descriptions of thos objects and methods/events for the things they actually do. Not really that hard to grasp.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks Dave, your comments were really helpful. I've given you my vote of 5.
However there is still a little confusion about the relationship, how could i get a list of managers for a given employee. For example, let's say I have an employee named "Frank" and he has two managers (Sean and manager2).
|
|
|
|
|
You should keep a list of the managers - something like this...
public class Employee
{
private string name;
private List<Manager> managers;
public string Name
{
get { return name; }
set { name = value; }
}
public List<Manager> Managers
{
get
{
if(managers == null)
return new List<Manager>();
return managers;
}
set { managers = value; }
}
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
modified on Thursday, June 24, 2010 6:04 AM
|
|
|
|
|
You should use the UML tools, visio or rational rose to draw the class diagram.
The class Manager is derived from Employee,
The class employee and manager is depended by clas EmployeeReportingRelationships.
|
|
|
|
|
Hi,
I am using “Heaton Research” for crawling data. In this process I think a very small issue is there, which I am not getting, or rather leaving it each time. The basic problem which I am facing is to use the "SQLWorkloadManager" method in place of "WorkloadManager" , In the book example is given for "WorkloadManager" and it is for one site, and it is further said that if you want to use it for more sites, then use "SQLWorkloadManager", It is further written that it can be used, but I am not getting the way to use "SQLWorkloadManager", I am sure that it may be a very small thing, but I am confused and not getting it correctly, It is working fine with “WorkloadManager” but not working with “SQLWorkloadManager” Any Idea to solve the problem will be great. Thanks in advance.
Deepak Upreti
|
|
|
|
|
Hi Expert
i am using VS 2005 and Making Some .dll File but i see that their are
some tool like .net reflector like to decomplied the .dll file
code is their any way to prevent to decomplied my .NET Dll.
|
|
|
|
|
Use a tool like a Dotfuscator[^].
Unfortunately, such tools dont very often prevent assemblies from getting decompiled.
They just make the decompiled code harder to read.
|
|
|
|
|
The short answer is no. If someone wants to decompile it they will.
You could use an obfusticator to make it less readable, but that would not stop them being able to decompile it.
So the long answer is also no.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
By design .NET embeds rich Meta data inside the executable code using MSIL. Anyone can easily decompile your DLL back using tools like ILDASM (owned by Microsoft) or Reflector for.NET which is a third party. Secondly there are many third party tools which make this decompiling process a click away. So any one can easily look in to your assemblies and reverse engineer them back in to actual source code and understand some real good logic which can make it easy to crack your application.
The process by which you can stop this reverse engineering is using “obfuscation”. It’s a technique which will foil the de compilers. There are many third parties (XenoCode, Demeanor for .NET) which provide .NET obfuscation solution. Microsoft includes one that is Dotfuscator Community Edition with Visual Studio.NET
lklklhjsdg
|
|
|
|