What is the reason to hide a method with a new keyword when only base.method was returned?

I found the following code snippet in the DbSet class for EntityFramework:

public new Type GetType()
{
  return base.GetType();
}

I have no idea why the base method is hidden, all base classes have a method implemented by the calling base.

This is object.GetType():

[SecuritySafeCritical]
[__DynamicallyInvokable]
[MethodImpl(MethodImplOptions.InternalCall)]
public extern Type GetType();

This is in class DbQuery:

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public new Type GetType()
{
  return base.GetType();
}

And this is in class DbSet( DbSet<TEntity> : DbQuery<TEntity>):

/// <inheritdoc />
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
[EditorBrowsable(EditorBrowsableState.Never)]
public new Type GetType()
{
  return base.GetType();
}

Why or when do you use the keyword newand then invoke the base implementation?

+6
source share
2 answers

Consider the alternatives.

  • Do not redefine or add anything

    Problem: There is no code for applying attributes.

  • Just override it

    : GetType .

, new base.

, [EditorBrowsable(EditorBrowsableState.Never)], ? - , GetType ElementType intellisense.

+3

, , , - . , , .

+1

All Articles