Force Compiler Error/Warning Within Custom Control

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Force Compiler Error/Warning Within Custom Control

    I assume there's a way to do this since I've seen third-party
    components act the same way.

    How do I force the compiler to throw an error or warning message during
    compile or build? For instance, if a certain property of my custom
    component isn't set, how can I force my compile to fail -- and force me
    to fix it before compiling successfully?

    I've added some pseudo-code below for reference.........


    Public Class MyClass
    Inherits Control

    Private _TestString As Label

    <Browsable(True)> _
    Public Property TestString() As String
    Get
    Return _TestString
    End Get
    Set(ByVal value As String)
    _TestString = value
    End Set
    End Property

    <pseudo-code>

    If Me.TestString = "" Then

    <This is where I'd want to throw the error during compilation,
    forcing me to set TestString in the Properties window before I can
    compile.......>

    End If

    </pseudo-code>

    End Class

    philaphan80@yahoo.com Guest

  2. Similar Questions and Discussions

    1. #40683 [NEW]: zend_operators.h generates discard qualifier compiler warning
      From: lstefani at fortresstech dot com Operating system: linux 2.6.12-1.1381_FC3smp PHP version: 5.2.1 PHP Bug Type: Compile...
    2. How to force a load of one control from another control on another form?
      I have 2 forms, frm1, frm2. They each have a user control on them, uc1, uc2. When a drop down list on frm1.uc1 is changed, I want frm2.uc2 to be...
    3. Web Custom Control error on ID field
      I get the following error when trying to view in browser an aspx page that has my simple Web Custom Control. If I remove the ID=Controlname from...
    4. ControlDesigner not invoked on custom control when control is rendered within another custom control
      I have a custom control that has a simple designer (derived from System.Web.UI.Design.ControlDesigner) associated with it (using the...
    5. Compiler Error Message: The compiler failed with error code 128.
      Hi. I am having trouble running my aspx code. I created two simple webforms, which i try to run from two different directories one is giving me...
  3. #2

    Default Re: Force Compiler Error/Warning Within Custom Control

    <philaphan80@yahoo.com> wrote in message
    news:1160166686.105011.25070@k70g2000cwa.googlegro ups.com...
    >I assume there's a way to do this since I've seen third-party
    > components act the same way.
    >
    > How do I force the compiler to throw an error or warning message during
    > compile or build? For instance, if a certain property of my custom
    > component isn't set, how can I force my compile to fail -- and force me
    > to fix it before compiling successfully?
    How would the compiler know if the property wasn't set? That happens at
    run-time.

    John


    John Saunders Guest

  4. #3

    Default Re: Force Compiler Error/Warning Within Custom Control

    > How would the compiler know if the property wasn't set? That happens at
    > run-time.
    I'm not sure. That's what I'm trying to work through in my head at the
    moment.

    I've evaluated components that throw a compiler error if, say, an
    evaluation period has expired or a registration key is missing, etc.
    So I thought, maybe they're using some kind of coding technique that I
    could utilize within my control.

    As it stands right now, my control is working pretty well for my needs.
    It displays an error within its Text property (at design time and run
    time) if a property isn't set correctly. I just figured I'd challenge
    myself by trying to force a compiler error. That way, I'd know there's
    a problem before the project was even built.

    Thoughts? Anyone? They're always gratefully appreciated.

    philaphan80@yahoo.com Guest

  5. #4

    Default Re: Force Compiler Error/Warning Within Custom Control

    <philaphan80@yahoo.com> wrote in message
    news:1160235775.465327.211970@b28g2000cwb.googlegr oups.com...
    >> How would the compiler know if the property wasn't set? That happens at
    >> run-time.
    >
    > I'm not sure. That's what I'm trying to work through in my head at the
    > moment.
    >
    > I've evaluated components that throw a compiler error if, say, an
    > evaluation period has expired or a registration key is missing, etc.
    > So I thought, maybe they're using some kind of coding technique that I
    > could utilize within my control.
    >
    > As it stands right now, my control is working pretty well for my needs.
    > It displays an error within its Text property (at design time and run
    > time) if a property isn't set correctly. I just figured I'd challenge
    > myself by trying to force a compiler error. That way, I'd know there's
    > a problem before the project was even built.
    >
    > Thoughts? Anyone? They're always gratefully appreciated.
    I was gently trying to suggest that there is fundamentally no way to do what
    you're asking for.

    First of all, please define "property wasn't set". Do you mean "property
    wasn't set during initialization"? If so, define "initialization", realizing
    that you have to define it in a way that you can explain to a compiler.
    You'll also have to make the decision to rule out "setting" the property by
    some method which is not "initialization".

    This would be interesting, since any definition of run-time initialization
    is going to have to be understood by the compiler in compile-time terms. For
    instance, if you defined "initialization" as "set by an unconditional
    statement in the InitializeComponent method", then the compiler could
    understand that. It could generate a (hidden) try-catch-finally block around
    the InitializeComponent method and check to see if the property had been
    "set".

    My advice is to punt on this until you find that some other piece of code
    has done this. You really are mistaken about the inherent difficulty in
    this.

    John


    John Saunders Guest

  6. #5

    Default Re: Force Compiler Error/Warning Within Custom Control

    <philaphan80@yahoo.com> wrote in message
    news:1160235775.465327.211970@b28g2000cwb.googlegr oups.com...
    >> How would the compiler know if the property wasn't set? That happens at
    >> run-time.
    >
    > I'm not sure. That's what I'm trying to work through in my head at the
    > moment.
    >
    > I've evaluated components that throw a compiler error if, say, an
    > evaluation period has expired or a registration key is missing, etc.
    > So I thought, maybe they're using some kind of coding technique that I
    > could utilize within my control.
    >
    > As it stands right now, my control is working pretty well for my needs.
    > It displays an error within its Text property (at design time and run
    > time) if a property isn't set correctly. I just figured I'd challenge
    > myself by trying to force a compiler error. That way, I'd know there's
    > a problem before the project was even built.
    >
    > Thoughts? Anyone? They're always gratefully appreciated.
    Things are different today than they were 30 years ago when I learned the
    difference between compile-time and run-time, so I gave this some more
    thought.

    The one situation in which I know of a compiler having anything at all to do
    with something we typically thing of as runtime is in the case of attributes
    in .NET. When we do something like the following:

    [WebService]
    public class SomeService
    {
    }

    then we find something like the following in the IL:

    .custom instance void
    [System.Web.Services]System.Web.Services.WebServiceAttribute::.ctor() = (
    .... )

    So, I tried placing a throw new Exception("Boom!") in the constructor of an
    attribute I use. No boom.


    Are you sure you didn't see these license things happen at design-time and
    not runtime?

    I suggest you limit yourself to runtime validation of property values. See
    the ISupportInitialization interface in the documentation.


    John


    John Saunders Guest

  7. #6

    Default Re: Force Compiler Error/Warning Within Custom Control

    > Things are different today than they were 30 years ago when I learned the
    > difference between compile-time and run-time, so I gave this some more
    > thought.
    John,

    First, let me thank you for taking time out of your schedule to help me
    with this. I appreciate it.

    One of your last comments worries me a bit, though. I'm afraid I may
    have misled you somehow.
    > Are you sure you didn't see these license things happen at design-time and
    > not runtime?
    Actually, that was what I was trying to get at. I'm sorry if I said
    anything inaccurate that may have led you to draw the wrong conclusion.

    I'm basically looking for the action (error/warning) to take place
    during compile-time, if there is such a thing. So this would be
    between design-time and run-time, when I have manually chosen to
    compile (or build) my project. I'm hoping to produce a compile-time
    error within the IDE, similar to the ones that force you to fix them
    before recompiling (e.g. paraphrased: "The string 'test' cannot be
    converted to type Integer -- testing.vb: line 47"). That way, I
    wouldn't have to worry about run-time at all. I'd have to fix my error
    before the project even successfully compiles.

    Does that help clear things up at all?

    Thanks again.

    philaphan80@yahoo.com Guest

  8. #7

    Default Re: Force Compiler Error/Warning Within Custom Control

    <philaphan80@yahoo.com> wrote in message
    news:1160444033.957409.72730@c28g2000cwb.googlegro ups.com...
    >> Things are different today than they were 30 years ago when I learned the
    >> difference between compile-time and run-time, so I gave this some more
    >> thought.
    >
    > John,
    >
    > First, let me thank you for taking time out of your schedule to help me
    > with this. I appreciate it.
    >
    > One of your last comments worries me a bit, though. I'm afraid I may
    > have misled you somehow.
    >
    >> Are you sure you didn't see these license things happen at design-time
    >> and
    >> not runtime?
    >
    > Actually, that was what I was trying to get at. I'm sorry if I said
    > anything inaccurate that may have led you to draw the wrong conclusion.
    >
    > I'm basically looking for the action (error/warning) to take place
    > during compile-time, if there is such a thing. So this would be
    > between design-time and run-time, when I have manually chosen to
    > compile (or build) my project. I'm hoping to produce a compile-time
    > error within the IDE, similar to the ones that force you to fix them
    > before recompiling (e.g. paraphrased: "The string 'test' cannot be
    > converted to type Integer -- testing.vb: line 47"). That way, I
    > wouldn't have to worry about run-time at all. I'd have to fix my error
    > before the project even successfully compiles.
    >
    > Does that help clear things up at all?
    It does. It can't be done, and probably shouldn't be done.

    The compiler couldn't possibly know, for instance, that the property on your
    control is being set by a piece of code in another assembly not in the
    solution.

    The right way to do this is at runtime, using ISupportInitialization.

    John


    John Saunders Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139