Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I don't know where I am doing mistake, I tried lot times, but somthing wrong with this code, In updates method I am geting id, version and set values, those properties are in logodetails class, and I am using logodetails as a base class to image details. when iam using ImageDetails class in other place in the project I am getting the values 0 ; (id = 0, version =0, set = 0)

public void Updates(AUnit _aUnit, int Id)
{
    ImageDetails _details = new ImageDetails(_aUnit, Id);
    List<LogoDetails> logolist = new List<LogoDetails>(); 
    LogoDetails logoDetails = new LogoDetails();

    int count = (int) _aUnit.ReadBits(8);
    for (int i = 0; i < (int) count; i++)
    {
        logoDetails.ID = 15;(int) _aUnit.ReadBits(8);
        logoDetails.Version = 6; (int) _aUnit.ReadBits(8);
        logoDetails.set = 14; (int) _aUnit.ReadBits(24);
        logolist.Add(logoDetails);
    }
    foreach (LogoDetails listitem in logolist)
    {
        _details.Rset = _aUnit.Buffer.Skip(10).Take(_details.set).ToArray();
    }
}

public class ImageDetails :LogoDetails
{
    public ImageDetails(AUnit _au, int carouselId)
    {            
        carId = carouselId;
        _AUnit = _au;         

        _updateTime = "";
    }
    private string _updateTime;

    public string UpdateTime
    {
        get { return _updateTime; }
        set { _updateTime = value; }
    }
}

public class LogoDetails
{
    public int LogoID { get; set; }
    public int LogoVersion { get; set; }
    public int Offset { get; set; }
}


What I have tried:

I tried using the same class, instead of using base class, it worked like this
Posted
Updated 5-Jul-17 22:32pm
Comments
F-ES Sitecore 6-Jul-17 5:18am    
Classes are instances of types so when you create a class in your Updates method, any properties you set on that object only apply to that object. If you create a new instance of the same class elsewhere it will have default values. As mentioned in Solution 1, you are creating classes but doing nothing with them, they just disappear when your Updates method ends. You might be getting confused between normal properties and static properties. When you define something as static then it is a "global" property for want of a better phrase, and if you set that static property in a method then anything accessing that static property will see the update. It's unlikely that's what you want though.

1 solution

C#
public void Updates(AUnit _aUnit, int Id)
{
    ImageDetails _details = new ImageDetails(_aUnit, Id);  // new object
    List<LogoDetails> logolist = new List<LogoDetails>();  // new object
    LogoDetails logoDetails = new LogoDetails();           // new object
 
    int count = (int) _aUnit.ReadBits(8);
    for (int i = 0; i < (int) count; i++)
    {
        logoDetails.ID = 15;(int) _aUnit.ReadBits(8);
        logoDetails.Version = 6; (int) _aUnit.ReadBits(8);
        logoDetails.set = 14; (int) _aUnit.ReadBits(24);
        logolist.Add(logoDetails);
    }
    foreach (LogoDetails listitem in logolist)
    {
        _details.Rset = _aUnit.Buffer.Skip(10).Take(_details.set).ToArray();
    }
}

You create three new objects inside this method, but you do not save them anywhere. So as soon as the method ends the objects go out of scope and they, and their contents, are never seen again.
 
Share this answer
 

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