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的依赖: < ...
随机推荐
- 什么是CGI(Common Gateway Interface)?
参考: 1.Python CGI编程 2.十分钟搞懂CGI 3.CGI Made Really Easy
- 利用php获取图片完整Exif信息类 获取图片详细完整信息类
<?php /** * @Author: TonyLevid * @Copyright: TonyLevid.com * @Name: Image Exif Class * @Version: ...
- Oracle的硬解析和软解析
提到软解析(soft prase)和硬解析(hard prase),就不能不说一下Oracle对sql的处理过程.当你发出一条sql语句交付Oracle,在执行和获取结果前,Oracle对此sql将进 ...
- php 常用五种模式
/* 设计模式之单例模式 $_instance 必须声明为静态的私有变量 构造函数必须声明为私有,防止外部程序 new 类从而失去单例模式的意义 getInstance() 方法必须设置为公有的,必须 ...
- [DevExpress]DxValidationProvider分享
前些日子从研究所临时调回公司,帮忙做另外一个项目的控件验证工作,其实内容非常的简单,就是将用户即将提交至服务器的数据先做一个本地验证,以达到减少服务器压力.提高用户体验的目的. 附上一张图片 这是官方 ...
- js与uri中location关系
//获取域名host = window.location.host;host2=document.domain; //获取页面完整地址url = window.location.href; docum ...
- PHP中,JS和CSS优化工具Minify的使用方法
为减少HTTP请求,我们往往需要合并和压缩多个JS和CSS文件,下面记录下网上关于实现这个功能的PHP源码以及开源项目Minify的使用方法 一.实现合并和压缩多个JS和CSS文件的代码请参考 1.一 ...
- php 接收二进制流转换成图片
php 接收二进制流转换成图片,图片类imageUpload.php如下: <?php /** * 图片类 * @author http://blog.csdn.net/haiqiao_2010 ...
- c# winform 隐藏tabcontrol标签
Apperarance 属性:Faltbuttons SizeMode属性:Fixed 各个TabPage的Text :空 ItemSize : Width=0;Height=1;
- MyEclipse配置多个WEB容器
MyEclipse支持多个同版本WEB容器同时运行 打开 然后按下图操作 咱们就得到了 下面需要配置新增加WEB容器的启动路径,在新增加的WEB容器上点击右键,选择箭头指向的菜单 打开的窗口如图,可以 ...