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的依赖: < ...
随机推荐
- SQL Server游标+延迟执行简介
在项目测试中,我们可能会使用批量生成数据来测试程序的性能. 这里讲一个我遇到的问题,由于我们批量生成数据时基本上是瞬间完成,所以GETDATE()函数获得的时间基本上也是一样的,而我们又要求生成每条数 ...
- Ext.Net学习笔记07:Ext.Net DirectMethods用法详解
使用DirectMethods在JS中调用C#方法 我承认,这个标题有点噱头,其实应该是通过DirectMethods,在JS中通过异步调用的方式执行服务器端的方法. 来看一个例子吧: [Direct ...
- iOS开发——扫描二维码——工具类
(代码已测试好,空闲时间更新……)
- html表单 第四节
实例: <html> <head> <title>表单实例</title> </head> <body> <center& ...
- IOS 学习笔记 2015-04-15 Xcode 工程模板分类
一 Application类型 我们大部分呢的开发工作都是使用Application类型的模板创建IOS程序开始的,该类型包括5个模板1 Master-Detail-Application ...
- MIS框架开发计划
计划开发模块 缓存模块 全球化模块(时间转换.货币转换.语言切换.度量转换.时区转换) 用户模块 用户短消息模块 日志模块(系统日志.用户操作日志.安全审计日志) 权限模块 配置模块 事件模块(观察者 ...
- h5添加音乐
http://changziming.com/post-209.html 加入HTML代码,因为是绑定在每一页的右上方(或者其他位置),定位用了fixed,所以在页面底部/body之前加上html代码 ...
- AS3.0的动态类和密封类
动态类:生成的实例可以在运行时动态添加属性和方法.类名前有dynamic就是动态类 密封类:生成的实例不可以在运行时动态添加属性和方法
- yii2 安装
php版本必须是php5.4以上.记得配置php环境变量 1.下载https://github.com/yiisoft/yii2-app-advanced 2.php -r "readfil ...
- (转载)Delphi StringGrid常用属性和常用操作
Delphi StringGrid常用属性和常用操作 StringGrid组件用于建立显示字符串的网格,与电子表格相似.它可使表格中的字符串和相关对象操作简单化.StringGrid组件提供了许多可控 ...