Click here to Skip to main content
15,896,456 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
In IService.cs file, I have created 2 classes.
C#
[ServiceContract]
    public interface IService1
    {

    }

    [DataContract]
    public class CLSReportMenu
    {
        int _reportID = 0;
        string _reportName = string.Empty;

        int _parentID = 0;

        [DataMember]
        public int ReportID
        {
            get { return _reportID; }
            set { _reportID = value; }
        }

        [DataMember]
        public string ReportName
        {
            get { return _reportName; }
            set { _reportName = value; }
        }

        [DataMember]
        public int ParentID
        {
            get { return _parentID; }
            set { _parentID = value; }
        }

        public CLSReportMenu(string reportname)
        {
            ReportName = reportname;
        }

    }

    [DataContract]
    public class ReportHierarchy
    {
        public ReportHierarchy()
        {
        }

        [DataMember]
        public DataTable ReportRecord
        {
            get;
            set;
        }

        [DataMember]
        public CLSReportMenu objreport { get; set; }
        [DataMember]
        public List<ReportHierarchy> Children { get; set; }

        public ReportHierarchy(CLSReportMenu report)
        {
            objreport = report;
            Children = new List<ReportHierarchy>();
        }

    }

Now I would like to access the Constructors "public ReportHierarchy(CLSReportMenu report)" from ReportHierarchy class and "public CLSReportMenu(string reportname)" from CLSReportMenu class under Datacontract. I just want to access the logic inside both the constructors. The logic that I am building is Parent & child Hierarchy that I will using to build menu when I am able to access those constructors on my client application.

Looking for some help.

Regards
Vasavi
Posted
Updated 14-Nov-12 23:10pm
v2
Comments
Sergey Alexandrovich Kryukov 15-Nov-12 13:59pm    
What logic inside? I cannot see any logic in your code sample. Data Contract is based on the use of parameterless constructors. It's absolutely not clear what do you mean by "access", and "access from data contract". Now, hierarchy (tree structure of relationship) is the simplest case for Data Contract, something which always works automatically. You probably don't quite understand what Data Contract does. In brief, you create some arbitrary object graph and persist it. When you read the previously stored data, Data Contract serializers simply restore the object graph exactly to the same logical state as it was before, but the mechanism takes into consideration only [DataMember] members. That's it -- a hierarchy is not a problem at all.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900