ghada naim

ghada naim

  • NA
  • 3
  • 985

C# Object Casting

Dec 13 2013 6:48 PM
Hi,
Please I want to help me.
First:
The code below the stars work according to the Rent check if the Rent is true it will work with RentingDB object else it will work with SellingDB object.
Is it possible to change the newRealty reference according to Rent check in C#?
 I attempted use the common referance with Object type,but it did not work and I do not know how to cast and complete this.
                            Object newRealty;
                            if(Rent)
                             newRealty= new RentingDB();
                              else
                             newRealty= new SellingDB();
//**********************************************************************************
                            newRealty.OwnerId = "";
                            newRealty.Type = (string)RealtyType.SelectedItem;
                            newRealty.City = City.SelectedItem.ToString();
                            newRealty.SubCity = SubCity.SelectedItem.ToString();
                            newRealty.Street = Street.Text;
Second:
I have this method (ImageOwnerInf),when I call it from another method it reach to /**/ point ,then return to the caller method and execute the code below the call statement that depends on the method(ImageOwnerInf).
 I think it is a deadlock.
I tried to use ConfigureAwait(false) but it did not make any change.
What is the solution,please.
private static async void ImageOwnerInfo(ParseObject x)
      {              ..................
                    foreach (ParseFile Photo in Photos)
                    {
                        if (Photo != null)
                        {
                       /**/   byte[] data = await new HttpClient().GetByteArrayAsync(Photo.Url);
                            BitmapImage image = await ByteArrayToBitmapImage(data).ConfigureAwait(false);
                            ListOfImages.Add(image);
                        }
                    }
                    ImagesAsSource.Add(x.ObjectId, ListOfImages);

    }

}

Thank you.
 
Kind regards

Answers (2)