Automatic Code Generation-->Implement Interface
https://msdn.microsoft.com/en-us/library/hk90416s(v=vs.110).aspx
VS中自带的只能提示,一个类继承自某一个接口。
由VS为类生成接口所要求的方法
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel; namespace BusinessServiceContracts
{
[ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")]
public interface IServiceA
{
[OperationContract]
string Operation1();
[OperationContract]
string Operation2();
}
}
public class ServiceA : IServiceA, IAdmin
{ }
现有代码如上
把鼠标的光标点在IServiceA的第一个字母I前面

这个时候会发现I字母线面有一个蓝色的下划线
让鼠标悬停在蓝色的下划线上,会出现一个小图标,单击一下


根据需要选择其中一个,来自动生成代码
实现接口IServiceA
using System;
using System.Collections.Generic;
using System.Text;
using BusinessServiceContracts; namespace BusinessServices
{
public class ServiceA : IServiceA, IAdmin
{ public string Operation1()
{
throw new NotImplementedException();
} public string Operation2()
{
throw new NotImplementedException();
}
} }
显示实现接口IServiceA
using System;
using System.Collections.Generic;
using System.Text;
using BusinessServiceContracts; namespace BusinessServices
{
public class ServiceA : IServiceA, IAdmin
{ string IServiceA.Operation1()
{
throw new NotImplementedException();
} string IServiceA.Operation2()
{
throw new NotImplementedException();
}
} }
第一种,实现接口,是public 方法
第二种,显示实现接口,方法直接完全限定了
显示接口和隐式接口的区别:
https://msdn.microsoft.com/en-us/library/ms173157.aspx
隐式实现的话实现的方法属于实现的类的,可以直接通过类的对象访问,
显式实现的话方法是属于接口的,可以看成是寄托在类中实现的,访问这些方法时要先把对象转换成接口对象,然后通过接口对象调用,
interface ICalculate
{
void Add();
void Substract();
}
class Math : ICalculate
{
void ICalculate.Add()
{
throw new NotImplementedException();
} void ICalculate.Substract()
{
throw new NotImplementedException();
}
}
调用方式
Math类型的实例是无法访问Add方法的
只有接口类型的实例,才可以访问Add方法。 即,需要把Math类型的实例先转换ICalculate才会用到
Math math = new Math();
ICalculate iMath = new Math();
iMath.Add();
安装了Resharper之后,上面的功能会被屏蔽
Resharper提示了错误之后,鼠标点击在错误的位置,左侧会出现一个红色灯泡
点击灯泡之后,选择Implementing missing members

Automatic Code Generation-->Implement Interface的更多相关文章
- 如何在 PhpStorm 使用 Code Generation?
實務上開發專案時,有一些程式碼會不斷的出現,這時可靠 PhpStorm 的 Code Generation 幫我們產生這些 code snippet,除此之外,我們也可以將自己的 code snipp ...
- TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement.
我今天写程序的时候遇到的问题,开始完成功能后没发觉.当再次部署程序更新时候,出的错误,通过firebug发现提示是TypeError: 'stepUp' called on an object tha ...
- Code Generation and T4 Text Templates
Code Generation and T4 Text Templates Code Generation and T4 Text Templates
- Object constraint language for code generation from activity models
一.基本信息 标题:Object Constraint Language for Code Generation from Activity Models 时间:2018 出版源:Informatio ...
- 【Spark】Spark性能优化之Whole-stage code generation
一.技术背景 Spark1.x版本中执行SQL语句,使用的是一种最经典,最流行的查询求职策略,该策略主要基于 Volcano Iterator Model(火山迭代模型).一个查询会包含多个Opera ...
- Orchard Core 文档翻译 (二)代码生成模板 Code Generation Templates
Code Generation Templates 翻译原文:https://www.cnblogs.com/Qbit/p/9746457.html转载请注明出处 Orchard Core Templ ...
- Spark SQL includes a cost-based optimizer, columnar storage and code generation to make queries fast.
https://spark.apache.org/sql/ Performance & Scalability Spark SQL includes a cost-based optimize ...
- Maven项目:@Override is not allowed when implement interface method
今天新建一个maven项目实现接口方法的时候报错编译不通过@Override is not allowed when implement interface method,要配置pom文件的compi ...
- ajax上传图片报错TypeError: 'append' called on an object that does not implement interface Fo
使用FormData时报错:TypeError: 'append' called on an object that does not implement interface FormData 解决办 ...
- 记一次antlr错误:ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.2ANTLR
场景:重构spark 2.1版本的sql语法.因此 需要使用antlr: 前期准备:idea安装了antlr插件(antlr的4.7.2版本) 因此在maven工程中添加了antlr的依赖: < ...
随机推荐
- C# 类是怎么执行的?
C# 类是怎么执行的? public class Person{ static person(){} //不写,默认也有个空的 public person(){}//不写,默认也有个空的 public ...
- 用Android-X86和VirtualBox打造高性能Android开发环境
不知道有多少Android开发着对Android虚拟机的那悲剧的性能有意见,反正我的看法是:那速度实在是太坑爹了! 为什么Android虚拟机比iOS和WP7的虚拟机要慢很多呢?原因如下: 1. An ...
- Spring中整合Titles
在<Spriing实战(第三版)>这本书中,有一个使用titles的例子,但是这是一个不完整的例子.那么要参照起来就比较难了,于是找到了下面这篇博客. 在Spring中使用tiles2 ( ...
- SQL Server系统表sysobjects介绍与使用(转)
SQL Server系统表sysobjects介绍与使用 关于SQL Server数据库的一切信息都保存在它的系统表格里.我怀疑你是否花过比较多的时间来检查系统表格,因为你总是忙于用户表格.但是,你可 ...
- UIView的frame和bounds区别
UIView的frame和bounds区别 iOS中,大家肯定对view和frame都不陌生,我们设置view在父view中的位置和大小时,只需要设置frame就可以了. 可能大家也有查过网上的一些资 ...
- java新手笔记8 包
1.main函数 public class MainParam { //考察main 方法的参数 args //运行时可以传入参数 参数类型 String public static void mai ...
- Redis单机版以及集群版的安装搭建以及使用
1,redis单机版 1.1 安装redis n 版本说明 本教程使用redis3.0版本.3.0版本主要增加了redis集群功能. 安装的前提条件: 需要安装gcc:yum install g ...
- 在远程服务器上完成本地设备的程序烧写和调试(基于vivado ,SDK软件)
在使用vivado和SDK进行设计开发的时候,通常需要登录到远程服务器上进行,但是会遇到一个问题就是,所使用的开发板通常是连接在自己的电脑上(local-PC),那要怎么才能让运行在服务器上的设计软件 ...
- Docker命令使用详解
其中<>括起来的参数为必选, []括起来为可选 docker -exec -i -t 3f407013d8c0 /bin/bash 进入容器 docker version查看dock ...
- 【转】Ext JS xtype
原文:Ext 中xtype一览 基本组件: xtype Class 描述 button Ext.Button 按钮 splitbutton Ext.SplitButton 带下拉菜单的按钮 cyc ...