code-reuse

Expression generated based on interface

浪子不回头ぞ 提交于 2019-12-11 03:39:43
问题 I'm geting the exception Unable to cast the type 'MySomeTypeThatImplementsISomeInterfaceAndIsPassedAs[T]ToTheClass' to type 'ISomeInterface'. LINQ to Entities only supports casting Entity Data Model primitive types. my repository looks like public interface IRepository<T> { IQueryable<T> Get(System.Linq.Expressions.Expression<System.Func<T, bool>> Query); } Also, I have the service class public abstract class FinanceServiceBase<TAccount, TParcel, TPayment> where TAccount : IAccount where

how to reuse android alertdialog

北城余情 提交于 2019-12-10 18:48:00
问题 I want to reuse the code for alertDialog and put it in another java file as function call . But "this" cannot be used to replace the "MyActivity.this"? How to pass it as a parameter? Best if the code is generic. AlertDialog alertDialog = new AlertDialog.Builder(MyActivity.this).create(); alertDialog.setTitle("Alert"); alertDialog.setMessage("Alert message to be shown"); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() { public void onClick

Demonstrate first-class functions in this simple example [closed]

这一生的挚爱 提交于 2019-12-10 17:45:55
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . Please demonstrate first-class functions (or some other functional programming concept) for code reuse for a beginner using these two overlapping Clojure functions. Basically, simplify the code block below using

Reusable jquery ajax requests

旧城冷巷雨未停 提交于 2019-12-10 16:17:52
问题 I am developing a web application using asp.net mvc... I am listing out the details of Clients,Staff,Reports via ajax requests using jquery... What i am doing is writing seperate functions(jquery ajax requests) for each actions (ie) view,add,edit,Delete ... //Clients function getClients(currentPage) { $.ajax({ url: "Clients/GetClients", data: { 'currentPage': (currentPage + 1), 'pageSize': 5 }, contentType: "application/json; charset=utf-8", global: false, async: false, dataType: "json",

How do you ensure code is reused correctly? [closed]

回眸只為那壹抹淺笑 提交于 2019-12-10 14:11:43
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Frequently when we introduce a new feature into an application we may produce artifacts, such as useful methods or classes that could be reused in other areas of our applications. These artifacts are not necessarily documented as functional requirements as they are usually a

How to simplify/reuse this exception handling code

痞子三分冷 提交于 2019-12-10 13:59:29
问题 I tend to write code like the following a lot: BufferedWriter w = null; // Or any other object that throws exceptions and needs to be closed try { w = new BufferedWriter(new FileWriter(file)); // Do something with w } catch (IOException e) { e.printStackTrace(); } finally { if (w != null) { try { w.close(); } catch (IOException e) { e.printStackTrace(); } } } It usually involves an object that throws exceptions and needs to be closed, and that closing it may also throw an exception. I was

How to reuse Core VBA functions (UDFs) across projects, but not show them in cell insert function

一笑奈何 提交于 2019-12-10 13:11:47
问题 I have an Addin with "core" functions and subs that I want to reference and use in different Addins or VBA projects. Because of the code reuse and single update principles. For example, a function, that filters collection members based on criteria and returns a sub-collection. The code itself is not an issue here. Public Function listNamesContaining(ByVal NamesInput As Names, ByVal ContainsCriteria As String) As Collection Dim NameMember As Name Set listNamesContaining = New Collection For

How to fake a library (GDI to Xamarin.Forms) across namespaces and platforms such as reusing Color struct

无人久伴 提交于 2019-12-10 11:54:24
问题 Im attempting to reuse legacy Windows GDI code in Xamarin without modifying the legacy GDI code (except using #if). In this specific case I need to use Color from Xamrin.Forms wrapped in my own color struct. I get the error cannot convert as posted in the question header above. This is the legacy code that is not to be modified (or very little) #if WINDOWS using System.Drawing; using System.Drawing.Drawing2D; using System.Data; using System.Windows.Forms; #else //if Xamarin using FakeGDI; /

How to avoid repeated code?

。_饼干妹妹 提交于 2019-12-10 00:47:29
问题 I'm still quite new to programming and I noticed that I'm repeating code: protected void FillTradeSetups() { DBUtil DB = new DBUtil(); DataTable dtTradeSetups; dtTradeSetups = DB.GetTradeSetups(); ddlSetups.DataValueField = "tradeSetupId"; ddlSetups.DataSource = dtTradeSetups; ddlSetups.DataBind(); } protected void FillTimeFrames() { DBUtil DB = new DBUtil(); DataTable dtTimeFrames; dtTimeFrames = DB.GetTimeFrames(); ddlTimeFrames.DataValueField = "tfCode"; ddlTimeFrames.DataSource =

AngularJS + Karma: reuse a mock service when unit testing directives or controllers

匆匆过客 提交于 2019-12-09 10:51:39
问题 I'm working with AngularJS + Karma. configService manages the settings of my app (e.g. the background-color, wether it's on debug mode, general permissions...). It loads initial data with $http. I wrote the test successfully for the service but my directives and controllers use it. When I write the unit tests for directives, I have to mock the service. I know I can do: spyOn(configService, 'getBackgroundColor').andCallFake(function (params) { return "red"; }); but the service has 25+ methods