Here is my code, I trimmed out the stuff that wasn't necessary.
Create a project called TestSamples with a form that does nothing for now.
Simple insert this code and it will compile with the error I indicated. If
you change "public struct TimeDelayEventData" to "public class
TimeDelayEventData" then it works just fine.
This code is my "GlobalData class"
using System;
using System.Collections;
namespace TestSamples
{
/// <summary>
/// Summary description for Class1.
/// </summary>
internal class GlobalData
{
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit.
static GlobalData() {}
/// <summary>
/// Default constructor
/// </summary>
private GlobalData()
{
// Set up the global data structures
this.timeDelayData = new TimeDelayEventData();
// Set up event handlers for the time delay events
this.timeDelayRequestor = new TimeDelayRequestEvents();
this.timeDelayListener = new TimeDelayFullfillEvents();
this.timeDelayListener.AddEvent(this.timeDelayRequ estor);
}
/// <summary>
/// Create a static instance of this class.
/// </summary>
static readonly GlobalData instance = new GlobalData();
/// <summary>
/// References the data regarding the time delays for the testing
/// </summary>
private TimeDelayEventData timeDelayData;
/// <summary>
/// Reference to the event handler to fulfill the event of passing
time delay data to the global data structure
/// </summary>
private TimeDelayFullfillEvents timeDelayListener;
/// <summary>
/// Reference to the event handler to request time delay events
/// </summary>
private TimeDelayRequestEvents timeDelayRequestor;
/// <summary>
/// Get a reference to this instance of this class.
/// </summary>
public static GlobalData Instance
{
get { return GlobalData.instance; }
}
/// <summary>
/// Get a reference to the time delay data.
/// </summary>
public TimeDelayEventData MyTimeDelayData
{
get
{
return this.timeDelayData;
}
}
/// <summary>
/// Get a reference to the time delay requestor
/// </summary>
public TimeDelayRequestEvents MyTimeDelayRequestor
{
get
{
return this.timeDelayRequestor;
}
}
}
}
Here is my TimeDelayEventData struct...
using System;
using System.Collections.Generic;
using System.Text;
namespace TestSamples
{
public struct TimeDelayEventData
{
/// <summary>
/// Ignore the date when asked to run the test
/// </summary>
private bool ignoreDate;
/// <summary>
/// This enum identifies the data that is to be updated
/// </summary>
private TimeDelayIdentifiers timeDelayIdentifier;
/// <summary>
/// Get or set the flag indicating that the date should be ignored
when asked to run the test
/// </summary>
public bool IgnoreDate
{
get
{
return ignoreDate;
}
set
{
ignoreDate = value;
}
}
/// <summary>
/// Get or set the identifier that identifies the data to be updated
in the event
/// </summary>
public TimeDelayIdentifiers Identifier
{
get
{
return timeDelayIdentifier;
}
set
{
timeDelayIdentifier = value;
}
}
}
}
Here is my event handler classes...
using System;
using System.Collections.Generic;
using System.Text;
namespace TestSamples
{
/// <param name="hourData">This structure identifies and contains the
data to be sent to the event</param>
public delegate void TimeDelayEventHandler(TimeDelayEventData data);
public class TimeDelayRequestEvents
{
/// <summary>
/// This event requests an update to the hour data.
/// </summary>
public event TestSamples.TimeDelayEventHandler
timeDelayUpdateRequestEvent;
/// <summary>
/// Default constructor
/// </summary>
public TimeDelayRequestEvents()
{
}
/// <summary>
/// Issue the request to update the hour data.
/// </summary>
/// <param name="obj">Time Delay data to be updated when an event
occurs</param>
private void RequestUpdateEvent(TimeDelayEventData obj)
{
if (timeDelayUpdateRequestEvent != null)
timeDelayUpdateRequestEvent(obj);
}
/// <summary>
/// Make the request to update the data being passed for time delay
information.
/// </summary>
/// <param name="obj">Time Delay data to be udpated when an event
occurs</param>
public void OnUpdate(TimeDelayEventData obj)
{
RequestUpdateEvent(obj);
}
}
/// <summary>
/// This class handles all fullfillments requests for updating the
global data representing the time delay data.
/// </summary>
public class TimeDelayFullfillEvents
{
/// <summary>
/// References the request to handle a time delay event
/// </summary>
private TimeDelayRequestEvents requestEvent = null;
/// <summary>
/// Default constructor
/// </summary>
public TimeDelayFullfillEvents()
{
}
/// <summary>
/// Remove any previous event instance.
/// </summary>
protected void RemoveEvent()
{
if (this.requestEvent != null)
this.requestEvent.timeDelayUpdateRequestEvent -= new
TimeDelayEventHandler(this.UpdateTimeDelayData);
}
/// <summary>
/// Update the data for the time delay information
/// </summary>
private void UpdateTimeDelayData(TimeDelayEventData data)
{
switch (data.Identifier)
{
case TimeDelayIdentifiers.IgnoreDate:
GlobalData.Instance.MyTimeDelayData.IgnoreDate =
data.IgnoreDate;
break;
}
}
/// <summary>
/// Add the event handler for the time delay events
/// </summary>
/// <param name="request">Requesting event to update the time delay
data</param>
public void AddEvent(TimeDelayRequestEvents request)
{
// Remove any instances of an old request.
this.RemoveEvent();
// Create the new handler.
this.requestEvent = request;
this.requestEvent.timeDelayUpdateRequestEvent +=new
TimeDelayEventHandler(this.UpdateTimeDelayData);
}
}
}
Here is my TimeDelayIdentifiers...
using System;
using System.Collections.Generic;
using System.Text;
namespace TestSamples
{
/// <summary>
/// This enum is used to identify which data in the event is to be updated
/// </summary>
public enum TimeDelayIdentifiers
{
/// <summary>
/// Indicates the data is in the ignoreDate field
/// </summary>
IgnoreDate = 1,
}
}
--
-----------
Thanks,
Steve
"Bruce Wood" wrote:
I copied your code in to a VS2003 project, removed the spurious
constructor, and it compiles with no warnings or errors.
Please post the exact code that caused this compiler error. I suspect I
know what's going on, but I can't say until I see the real code.