get form proterty `cannot explicitly call operator or accessor`

让人想犯罪 __ 提交于 2020-01-14 05:28:06

问题


I'm makeing a small app for wp7, and I'm haveing an error when I try to get from a reference.

The code in something like this:

   private void refreshExistingShellTile()
    {
        using (IEnumerator<ShellTile> enumerator = ShellTile.get_ActiveTiles().GetEnumerator())
        {
            while (enumerator.MoveNext())
            {
                ShellTile current = enumerator.get_Current();
                if (null != current.get_NavigationUri() && !current.get_NavigationUri().ToString().Equals("/"))
                {
                    Black_n_Gold.Entities.Tile tile = App.CurrentApp.tileService.findById(App.CurrentApp.tileService.getTileId(current.get_NavigationUri().ToString()));
                    if (tile != null && tile.id == this.customizedTile.id)
                    {
                        current.Delete();
                        this.createShellTile(this.customizedTile);
                    }
                }
            }
        }
    } 

and I have this errors:

'Microsoft.Phone.Shell.ShellTile.ActiveTiles.get': cannot explicitly call operator or accessor
'Microsoft.Phone.Shell.ShellTile.NavigationUri.get': cannot explicitly call operator or accessor
'System.Collections.Generic.IEnumerator<Microsoft.Phone.Shell.ShellTile>.Current.get': cannot explicitly call operator or accessor

I'm having the same error when I try to add or set from a property, and I looked on the web, but I couldn't find the solution.


回答1:


You're using the underlying method names. Instead of this:

ShellTile current = enumerator.get_Current();

You want:

ShellTile current = enumerator.Current;

etc. However, I would also suggest using a foreach loop instead of explicitly calling GetEnumerator etc:

private void refreshExistingShellTile()
{
    foreach (ShellTile current in ShellTile.ActiveTiles)
    {
        Uri uri = current.NavigationUri;
        if (uri != null && uri.ToString() != "/")
        {
            Black_n_Gold.Entities.Tile tile = App.CurrentApp.tileService
                .findById(App.CurrentApp.tileService.getTileId(uri.ToString());
            if (tile != null && tile.id == customizedTile.id)
            {
                current.Delete();
                createShellTile(customizedTile);
            }
        }
    }
}

Also note that .NET naming conventions would suggest that findById etc should be PascalCased:

  • FindById
  • GetTileId
  • CreateShellTile


来源:https://stackoverflow.com/questions/14185934/get-form-proterty-cannot-explicitly-call-operator-or-accessor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!