Link to home
Start Free TrialLog in
Avatar of sherbug1015
sherbug1015Flag for United States of America

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_Polls_PollRaceTrac" CodeFile="~/CMSWebParts/Polls/PollRaceTrac.ascx.cs" %>
<%@ Register Src="~/CMSModules/Polls/Controls/View/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
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

There are 2 candidates for null reference:

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.
ASKER CERTIFIED SOLUTION
Avatar of sherbug1015
sherbug1015
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sherbug1015

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;
        }