sherbug1015
asked on
Getting the value of a public virtual property from an assembly
OK. Here goes.
I have a user control that gets all its properties from another user control.
<%@ Control Language="C#" AutoEventWireup="true"
Inherits="CMSWebParts_Poll s_PollRace Trac" CodeFile="~/CMSWebParts/Po lls/PollRa ceTrac.asc x.cs" %>
<%@ Register Src="~/CMSModules/Polls/Co ntrols/Vie w/PollView .ascx" TagName="PollView" TagPrefix="cms" %>
<cms:PollView ID="viewPoll" runat="server" />
The PollView.ascx has a data container called PollInfo. PolllInfo is an assembly with a namespace as follows:
namespace CMS.Polls
{
// Summary:
// PollInfo data container class.
public class PollInfo : AbstractInfo<PollInfo>
PollView.ascx also has a protected reference to the PollInfo data container
defined as follows: protected Pollinfo pi = null;
Then PollInfo fills up with the data from the UI
Contained within the PollInfo object are some public virtual properties. Many are exposed as properties on the PollView.ascx, but one of them that I need is not exposed. PollOpenTo is the property defined as follows in the PollInfo class
public virtual DateTime PollOpenTo { get; set; }
Since the accessor is protected I can see all the properties that are contained in the PollInfo. so I thought I could go
if (viewPoll.pi.PostOpenTo <= DateTime.Now)
Do something
This statement is throwing an object reference not set error.
What can't I read this value?
Document2.txt
I have a user control that gets all its properties from another user control.
<%@ Control Language="C#" AutoEventWireup="true"
Inherits="CMSWebParts_Poll
<%@ Register Src="~/CMSModules/Polls/Co
<cms:PollView ID="viewPoll" runat="server" />
The PollView.ascx has a data container called PollInfo. PolllInfo is an assembly with a namespace as follows:
namespace CMS.Polls
{
// Summary:
// PollInfo data container class.
public class PollInfo : AbstractInfo<PollInfo>
PollView.ascx also has a protected reference to the PollInfo data container
defined as follows: protected Pollinfo pi = null;
Then PollInfo fills up with the data from the UI
Contained within the PollInfo object are some public virtual properties. Many are exposed as properties on the PollView.ascx, but one of them that I need is not exposed. PollOpenTo is the property defined as follows in the PollInfo class
public virtual DateTime PollOpenTo { get; set; }
Since the accessor is protected I can see all the properties that are contained in the PollInfo. so I thought I could go
if (viewPoll.pi.PostOpenTo <= DateTime.Now)
Do something
This statement is throwing an object reference not set error.
What can't I read this value?
Document2.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The software I am using has a lot of API that I found and was able to drill down and get the field I needed from there
DateTime PollClosed = new DateTime(1900, 01, 01);
var activePolls = PollInfoProvider.GetPolls( "PollID = 5", "");
foreach (PollInfo pi in activePolls)
{
PollClosed = pi.PollOpenTo;
}
DateTime PollClosed = new DateTime(1900, 01, 01);
var activePolls = PollInfoProvider.GetPolls(
foreach (PollInfo pi in activePolls)
{
PollClosed = pi.PollOpenTo;
}
1) viewPoll
2) pi
I can see where you are declaring the "pi" property, but I can't see where you are creating the instance:
protected PollInfo pi = null;
The "protected" keyword means that the property is only visible to inheriting classes. I can't quite make out the class hierarchy and inheritance.