|
unfortunately I don't have that book.
Have you got the "play around"'s source code that you mententioned?
Don't forget, that's " Persian Gulf " not Arabian gulf!
|
|
|
|
|
Hi
1. Why cant you have a "params" parameter for the constructor of an attribute?
2. Why do you have to provide a constructor in an inherited abstract class where the base class does not have a default constructor?
Any input welcome
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
leppie wrote:
Why cant you have a "params" parameter for the constructor of an attribute?
This compiled for me:
public class Foo : System.Attribute
{
public int [] bar;
public Foo(params int [] a)
{
bar = a;
}
} leppie wrote:
Why do you have to provide a constructor in an inherited abstract class where the base class does not have a default constructor?
I assume you mean the abstract class has a constructor that takes parameters rather than no constructor at all.
With C# if you don't supply a constructor, a default constructor is supplied for you. Similarly if you don't explicitly call the base class's constructor it attempts to call the default constructor for you.
In the case where the base class has only non-default constructors the compiler still tries to call one from the auto-generated default constructor for the child class, causing an error saying that method "Foo" has no overload that takes 0 arguments.
For example:
public class Foo
{
public int bar;
public Foo(int a)
{
bar = a;
}
}
public class What
{
} Results in the said error message.
Whether the base class is abstract doesn't play a part in this at all
All testing on .NET v1.1
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
James T. Johnson wrote:
This compiled for me:
Did you try use it? Sorry forgot to mention it does compile, but its not usable.
James T. Johnson wrote:
I assume you mean the abstract class has a constructor that takes parameters rather than no constructor at all.
This is what I mean:
class Foo
{
public Foo(string blah){...}
}
abstract class Poo : Foo
{
}
An abstract class may not be constructed, so why do you need to provide a constructor?
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
leppie wrote:
An abstract class may not be constructed, so why do you need to provide a constructor?
It really isn't required, in fact this compiled fine for me (and worked) when I commented out the constructor:
abstract class CreditCard
{
public static bool Validate(string CreditCardNumber)
{
int sum = 0;
for(int i = 0; i < CreditCardNumber.Length; i++)
{
if((int)CreditCardNumber[i]%2 != 0)
{
if((int)CreditCardNumber[i] * 2 > 9)
sum += ((int)CreditCardNumber[i] * 2) - 9;
else
sum += (int)CreditCardNumber[i] * 2;
}
else
{
if((int)CreditCardNumber[i] != 0)
sum += (int)CreditCardNumber[i];
}
}
return(Convert.ToBoolean(sum%10));
}
}
-Nick Parker
|
|
|
|
|
|
leppie wrote:
But alas no base class
You can do something like this, if this is what you mean:
abstract class Poo
{
...
}
public class Foo : Poo
{
Foo(){}
...
}
Foo f = new Foo();
-Nick Parker
|
|
|
|
|
leppie wrote:
Did you try use it? Sorry forgot to mention it does compile, but its not usable.
That's just it: it does work for us (otherwise our application wouldn't work right). How are you using the attribute?
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
|
1.0.5000.0 (.NET 1.0 SP2)
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
leppie wrote:
An abstract class may not be constructed, so why do you need to provide a constructor?
If you don't provide one at all (and alter the C# compiler to not provide one for you) you can't inherit from it to make use of the abstract class.
We can infer that because combining abstract with sealed results in an error that the C# desigers want the abstract keyword to imply that you want the class to be inherited from at some point.
It is perfectly legal to have a private constructor on an abstract class, which if all constructors are private then the class can't be inherited from.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
leppie wrote:
1. Why cant you have a "params" parameter for the constructor of an attribute?
You can. I've been doing it in our app for over a year (soon after the 1.0 release was released; never tried it before that). The following should work:
public class MyAttributeAttribute : Attribute
{
private string[] parms;
public MyAttributeAttribute(params string[] parms)
{
this.parms = parms;
}
}
It works for me. Perhaps a code snippet would help.
leppie wrote:
2. Why do you have to provide a constructor in an inherited abstract class where the base class does not have a default constructor?
Just to clarify, is the abstract class being inherited, or does it inherit from another class? If the latter is the case, is the base class also abstract?
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
|
|
|
Nope, that's how we do it at work, using String s and everything. The code snippet I gave before is the syntax I used. Is this in .NET 1.0 or 1.1, BTW?
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
|
Anybody got any ideas to show a tooltip anywhere on the screen, not attached to a control? I tried converting this article, but something must of gone wrong because it doesnt work
| Website: http://www.onyeyiri.co.uk
| Sonork: 100.21142 : TheEclypse
| "If a dolar was a chicken would the chicken be evil?"
|
|
|
|
|
Did you have a problem with the struct or something else?
-Nick Parker
|
|
|
|
|
i have fixed it now, i forgot to add the structlayout attribute to my definition of RECT, and i used long instead of int. thanks for replying though
| Website: http://www.onyeyiri.co.uk
| Sonork: 100.21142 : TheEclypse
| "If a dolar was a chicken would the chicken be evil?"
|
|
|
|
|
I am trying to implement a web service that uses client and server certificates - the problem is, this has to be transparent to the user. Has anyone seen any code examples of how to accept the ssl server-side certificate programatically? We do not want to put this in the client store - we want the code to just accept the certificate, so the user would not have to.
Thanks in advance!
Jeff Phillips
|
|
|
|
|
If you're just doing secure communications between client and server, you don't need to put a certificate in the code store. General, the root CA has to be in there for the certificate to be accepted, but if it is and it is trusted, the client will accept it.
Now, if this is a distribution app in which certificates are installed, current implementations of the CSPs in 2000 and XP require a user's confirmation. I've seen nothing to the contrary mentioned in the documentation. Think about the ramafications: if a client trusts a certificate that is signed by a CA already in their store (put there by a worm, for example) then a signed, malicious ActiveX control or Java applet could get nasty! Not a very secure approach, is it?
For this reason, users are notified when their store is being accessed or at least if it is being changed. I have mine configured to let me know when something is accessing my private key so I know when its being used. There's no documented way (and hopefully no way at all) for this to occur programmatically, otherwise something could be faking messages from me that are signed and valid.
As far as secure communications go (ex, HTTPS), this should all be transparent. If you need to first distribute a self-signed CA (one your company generated), distribute it manually or through your Certificate Server (assuming you're running it and have ActiveDirectory). Once the certificate is installed successfully (implies a user's trust), you shouldn't have a problem doing secure communications.
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
In my solution, I have two projects, lets call them A and B. Project A references project B and includes a namespace from project B in one of project A's classes. When I try to compile the solution, I get an error saying that the namespace that I am including in project A cannot be found. If I reboot my computer, it will compile the solution fine. However, if I make any changes to project B, project A will not see project B until I have to reboot my computer again. Does anyone have any suggestions because it is getting a little annoying having to reboot every 20 minutes? Thanks
Shaun
|
|
|
|
|
Did you add a Project refence of B to A, or a file reference? You should use a Project refernece because that sets-up a dependency. To compile A, B must compile. If B compiles successfully, it is automatically copied to project A's obj and bin subdirectories (and into Debug or Release subdirs appropriate). A file reference won't work this way.
Also, if B doesn't compile successfully, A will still try to compile but will fail because B doesn't exist in its private path (the obj and bin subdirs). The file must be in the same directory (during build-time; there are ways to override this at runtime) or in the Global Assembly Cache. When B starts to compile, the other B.dll assemblies are deleted.
This may explain what is happening, although I don't know how the reboot fits into this.
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
Yes, I had a reference to B from A. B compiled fine and then A would try to compile and it would say that it can't see a namespace from project B. Now rebooting doesn't even work anymore. I have to delete the reference to B in A and then re-add it and then save it, close out the IDE and then re-open the IDE for it to compile.
|
|
|
|