你认为什么是最img.Group.Contents简洁的方法来循环并写出galleryImage的值.??? 对象?
galleryImage.TinyImage = new myModel.Image._Img();
galleryImage.TinyImage.Url = img.Group.Contents[0].Url;
galleryImage.TinyImage.FileSize = img.Group.Contents[0].FileSize;
galleryImage.TinyImage.Type = img.Group.Contents[0].Type;
galleryImage.TinyImage.Medium = img.Group.Contents[0].Medium;
galleryImage.TinyImage.Width = img.Group.Contents[0].Width;
galleryImage.TinyImage.Height = img.Group.Contents[0].Height;
galleryImage.TinyImage.Hash = img.Group.Contents[0].Hash;
galleryImage.Thumbnail.Url = img.Group.Contents[1].Url;
galleryImage.Thumbnail.FileSize = img.Group.Contents[1].FileSize;
galleryImage.Thumbnail.Type = img.Group.Contents[1].Type;
galleryImage.Thumbnail.Medium = img.Group.Contents[1].Medium;
galleryImage.Thumbnail.Width = img.Group.Contents[1].Width;
galleryImage.Thumbnail.Height = img.Group.Contents[1].Height;
galleryImage.Thumbnail.Hash = img.Group.Contents[1].Hash;
galleryImage.SmallImage.Url = img.Group.Contents[2].Url;
galleryImage.SmallImage.FileSize = img.Group.Contents[2].FileSize;
galleryImage.SmallImage.Type = img.Group.Contents[2].Type;
galleryImage.SmallImage.Medium = img.Group.Contents[2].Medium;
galleryImage.SmallImage.Width = img.Group.Contents[2].Width;
galleryImage.SmallImage.Height = img.Group.Contents[2].Height;
galleryImage.SmallImage.Hash = img.Group.Contents[2].Hash;
galleryImage.MediumImage.Url = img.Group.Contents[3].Url;
galleryImage.MediumImage.FileSize = img.Group.Contents[3].FileSize;
galleryImage.MediumImage.Type = img.Group.Contents[3].Type;
galleryImage.MediumImage.Medium = img.Group.Contents[3].Medium;
galleryImage.MediumImage.Width = img.Group.Contents[3].Width;
galleryImage.MediumImage.Height = img.Group.Contents[3].Height;
galleryImage.MediumImage.Hash = img.Group.Contents[3].Hash;
galleryImage.LargeImage.Url = img.Group.Contents[4].Url;
galleryImage.LargeImage.FileSize = img.Group.Contents[4].FileSize;
galleryImage.LargeImage.Type = img.Group.Contents[4].Type;
galleryImage.LargeImage.Medium = img.Group.Contents[4].Medium;
galleryImage.LargeImage.Width = img.Group.Contents[4].Width;
galleryImage.LargeImage.Height = img.Group.Contents[4].Height;
galleryImage.LargeImage.Hash = img.Group.Contents[4].Hash;
galleryImage.ExtraLargeImage.Url = img.Group.Contents[5].Url;
galleryImage.ExtraLargeImage.FileSize = img.Group.Contents[5].FileSize;
galleryImage.ExtraLargeImage.Type = img.Group.Contents[5].Type;
galleryImage.ExtraLargeImage.Medium = img.Group.Contents[5].Medium;
galleryImage.ExtraLargeImage.Width = img.Group.Contents[5].Width;
galleryImage.ExtraLargeImage.Height = img.Group.Contents[5].Height;
galleryImage.ExtraLargeImage.Hash = img.Group.Contents[5].Hash;
Run Code Online (Sandbox Code Playgroud)
函数提供了一种简化重复任务的好方法:
void ConfigureImage(MyImageType img, int pos) {
img.Url = img.Group.Contents[pos].Url;
img.FileSize = img.Group.Contents[pos].FileSize;
img.Type = img.Group.Contents[pos].Type;
img.Medium = img.Group.Contents[pos].Medium;
img.Width = img.Group.Contents[pos].Width;
img.Height = img.Group.Contents[pos].Height;
img.Hash = img.Group.Contents[pos].Hash;
}
Run Code Online (Sandbox Code Playgroud)
有了这个功能,只需要在六行中重写代码:
ConfigureImage(galleryImage.TinyImage, 0);
ConfigureImage(galleryImage.Thumbnail, 1);
ConfigureImage(galleryImage.SmallImage, 2);
ConfigureImage(galleryImage.MediumImage, 3);
ConfigureImage(galleryImage.LargeImage, 4);
ConfigureImage(galleryImage.ExtraLargeImage, 5);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |