How to get/set a property of an interface that is not always implemented

How to get/set a property of an interface that is not always implemented

Content Index :

How to get/set a property of an interface that is not always implemented
Tag : chash , By : KT.
Date : November 25 2020, 07:22 PM

This might help you Apparently your ReadData method can't actually accept any type of repository. It is only able to handle a FileRepository. That's what it expects, and that's what it needs to do its job. Given that, that's what it should actually accept as its parameter, rather than an interface that doesn't actually provide a contract that is sufficient for it to do its job.
The entire point of having an interface is so that anyone using that interface can use it without caring what the implementation is. So if you do want to use the interface you need to include enough information in the interface's definition such that it provides every operation that anyone using the interface needs, otherwise you're better off just not using it at all (at least for that specific operation).

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How can an auto-implemented property having different access levels be described by an interface?

Tag : chash , By : eataix
Date : March 29 2020, 07:55 AM
Hope that helps This class property is what I'm trying to refactor into an interface. , I tested with the following:
class bla : Ibla {
    public int Blargh { get; protected internal set; }

interface Ibla {
    int Blargh { get; }

How to hide set method of an implemented property from an interface in C#?

Tag : chash , By : Zinovate
Date : March 29 2020, 07:55 AM
Does that help If you use the following interface the set method will be unavailable when classes are manipulated via the interface:
interface IMyInterface
   int property { get; }
class MyClass : IMyInterface
  int property { get; protected set; }

EF Code First implemented interface property

Tag : chash , By : Jack
Date : March 29 2020, 07:55 AM
it helps some times After reading Ladislav's answer, I decided to manually write the expression.
    public static void WithKeywords<TEntityType>(this EntityTypeConfiguration<TEntityType> entityTypeConfiguration)
        where TEntityType : EntityBase, IKeywordedEntity
        var rootExpression = Expression.Parameter(typeof (TEntityType));
        var expression = Expression.Property(rootExpression, "Keywords");

        entityTypeConfiguration.HasMany(Expression.Lambda<Func<TEntityType, ICollection<Keyword>>>(expression, rootExpression)).WithMany();

Getting attribute of a property where the property is from an implemented interface

Tag : chash , By : Sanoran
Date : March 29 2020, 07:55 AM
Any of those help This will give you the list of all custom attributes Bar applied to all properties in type of instance:
var attibutes = instance.GetType().GetInterfaces()
                    .SelectMany(i => i.GetProperties())
                        propertyInfo =>
                        propertyInfo.GetCustomAttributes(typeof (BarAttribute), false)

Cannot access implemented property (from interface)

Tag : chash , By : user119985
Date : March 29 2020, 07:55 AM
may help you . You have implemented these as explicit interface implementations, meaning you can only access them through a variable of the interface type - IEntityModifier.
Either do that:
if (((IEntityModifier)this).AutoDetachOnFinished)
bool AutoDetachOnFinished { get; set; }
bool Finished { get { return this.mFinished; } }
Related Posts Related QUESTIONS :
  • High availability
  • What to use for Messaging with C#
  • Accessing a Dictionary.Keys Key through a numeric index
  • ConfigurationManager.AppSettings Performance Concerns
  • What Are Some Good .NET Profilers?
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com