Solved

Attribute Class - Constant Expression Required

Posted on 2011-09-13
2
354 Views
Last Modified: 2012-05-12
I have an attribute class which I am using to check a business rule. The problem is it says "Constant expression required"

  <DisplayName("Schedule Start Date"), DateNotBefore(Date.Now)> _
    Public SchedStartDate As Date
 
....
  <AttributeUsage(AttributeTargets.Field Or AttributeTargets.Property)> _
    Public Class DateNotBeforeAttribute
        Inherits System.Attribute

        Implements ITest

        Private _value As Date

        Public Sub New(ByVal value As Date)
            _value = value
        End Sub

        Public Function TestCondition(ByVal value As Object, ByRef cls As Object) As Boolean Implements ITest.TestCondition

            Dim dt As Date = CType(value, Date)

            If dt < _value Then
                Return True
            Else
                Return False
            End If

        End Function



0
Comment
Question by:rocky050371
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36530054
Attributes are fixed at compilation time. So you cannot use Date.Now in the attribute call, because it is variable. You need a constant.

If you want to record now in the attribute, do not pass it as a parameter, simply set as such in the constructor:

Public Sub New()
    _value = Date.Now
End Sub
0
 

Author Comment

by:rocky050371
ID: 36530210
As I see thank you
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now