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的依赖: < ...
随机推荐
- 不需要软件让Windows7变身WIFI热点
很简单,就是把一台装有windows 7操作系统,并配有无线网卡的电脑变成一台无线路由器或无线AP,以便在没有路由器的环境中实现多台无线终端(比如支持wifi的手机.电脑等设备)共享无线网络.那么我们 ...
- 关于ContentProvider的批量操作
今天看公司代码,发现在批量插入通话记录和联系人的时候,用了一个 ArrayList<ContentProviderOperation> ops = new ArrayList<Con ...
- C#的垃圾回收机制及弱引用
在上一篇中,讨论了字符串常量的拘留池和不可变性:对于字符串变量,没有这个特性(或其他DotNet的非托管资源),当我们使用完后就要手动回收,即将变量的值指向null(p=null),然而堆内存中,那个 ...
- OEL5.5安装Oracle 11gr2详解
虚拟机环境:Vmware Workstation 11.1.0 + Oracle Enterprise Linux 5.5 X86-641.物理机内存设置 最小:1GB 推荐:2GB或以上 检测内存大 ...
- windows下ipython的tab补全,只需安装pyreadline即可.
运行ipython提示缺失模块 在windows下安装readline失败. 根据提示访问 https://urllib3.readthedocs.org/en/latest/security.htm ...
- Codevs 1217 借教室 2012年NOIP全国联赛提高组
1217 借教室 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在大学期间,经常需要租借教 ...
- OpenCV(5)-图像掩码操作(卷积)-锐化
锐化概念 图像平滑过程是去除噪声的过程.图像的主要能量在低频部分,而噪声主要集中在高频部分.图像的边缘信息主要也在高频部分,在平滑处理后,将会丢不部分边缘信息.因此需要使用锐化技术来增强边缘. 平滑处 ...
- Vivado Launching SDK "Importing Hardware Specification" error的解决方法
解决方法是通过参考http://forum.digilentinc.com/topic/611-vivado-launching-sdk-importing-hardware-specificatio ...
- Entity SQL 初入
Entity SQL 是 ADO.NET 实体框架 提供的 SQL 类语言,用于支持 实体数据模型 (EDM).Entity SQL 可用于对象查询和使用 EntityClient 提供程序执行的查询 ...
- 多核处理器基础SMP&&BMP
多核处理器也称片上多核处理器(Chip Multi-Processor,CMP). 1.多核处理器的流行 多核出现前,商业化处理器都致力于单核处理器的发展,其性能已经发挥到极致,仅仅提高单核芯片的速度 ...