Examples of errors detected by the V3051 diagnostic.


V3051. An excessive type cast or check. The object is already of the same type.


Xamarin.Forms

V3051 An excessive type cast. The object is already of the 'FormsPivot' type. Xamarin.Forms.Platform.UAP TabbedPageRenderer.cs 73


public FormsPivot Control { get; private set; }

Brush ITitleProvider.BarBackgroundBrush
{
  set { (Control as FormsPivot).ToolbarBackground = value; }
}

Similar errors can be found in some other places:

  • V3051 An excessive type cast. The object is already of the 'FormsPivot' type. Xamarin.Forms.Platform.UAP TabbedPageRenderer.cs 78
  • V3051 An excessive type cast. The object is already of the 'FormsPivot' type. Xamarin.Forms.Platform.UAP TabbedPageRenderer.cs 282
  • V3051 An excessive type cast. The object is already of the 'FormsPivot' type. Xamarin.Forms.Platform.WinRT.Phone TabbedPageRenderer.cs 175
  • And 2 additional diagnostic messages.

Old NASA World Wind (C#)

V3051 An excessive type cast. The object is already of the 'IWidget' type. PanelWidget.cs 749


protected IWidgetCollection m_ChildWidgets =
                            new WidgetCollection();

public interface IWidgetCollection
{
  ....
  IWidget this[int index] {get;set;}
  ....
}

public void Render(DrawArgs drawArgs)
{
 ....
 for(int index = m_ChildWidgets.Count-1; index>=0; index--)
 {
   IWidget currentChildWidget =
            m_ChildWidgets[index] as IWidget; // <=
   ....
 }
 ....
}

Similar errors can be found in some other places:

  • V3051 An excessive type cast. The object is already of the 'IWidget' type. FormWidget.cs 1174
  • V3051 An excessive type cast. The object is already of the 'IWidget' type. RootWidget.cs 80
  • V3051 An excessive type cast. The object is already of the 'IWidget' type. RootWidget.cs 219
  • And 27 additional diagnostic messages.

Mono

V3051 An excessive type cast. The object is already of the 'MimeXmlBinding' type. SampleGenerator.cs 232


public string GenerateHttpGetMessage (Port port,
                                      OperationBinding obin,
                                      Operation oper,
                                      OperationMessage msg)
{
  ....
  MimeXmlBinding mxb =
    (MimeXmlBinding) obin.Output
                         .Extensions
                         .Find (typeof(MimeXmlBinding))
      as MimeXmlBinding;
  if (mxb == null) return req;
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++, and C#

goto PVS-Studio;
On our website we use a cookie to collect information of a technical nature.
If you do not agree, please leave the site. Learn More →
Do not show again