---
title: "Interface detection reflection"  
description: "Interface detection reflection"  
author: "Anonymous User"  
published: 2014-03-26  
updated: 2014-03-26  
canonical: https://www.mindstick.com/forum/1994/interface-detection-reflection  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Interface detection reflection

I have this code in my C# [module](https://www.mindstick.com/blog/11796/prestashop-one-page-checkout-module-make-checkout-faster):

if ([customer](https://www.mindstick.com/articles/325839/how-to-improve-your-business-level-of-customer-service) is IBuyer) { customer.WaiveServiceFee(); }

This compiles fine, as long as customer is an object that implements IBuyer. But the whole idea of using the conditional is to test whether the customer object implemented IBuyer. If it hasn't, I get a [compile](https://www.mindstick.com/forum/2316/how-to-views-compile-in-mvc)-time error that customer does not contain a [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat) for WaiveServiceFee (WaiveServiceFee is [method](https://www.mindstick.com/forum/166/webservice-method) that [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) from IBuyer [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp)--it, of course, is not part of the customer [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)).

I'm not familiar [enough](https://answers.mindstick.com/qa/48601/who-is-the-writer-of-the-one-life-is-not-enough) with C# to know how I can apply the logic above to call WaiveServiceFee at run-time and also make the [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) compilable?

Thank you.

## Replies

### Reply by Pravesh Singh

Hi Ankita,\

Use as operator instead:

var buyer = customer as IBuyer;

if(buyer != null)

buyer.WaiveServiceFee();

If customer doesn't implement IBuyer, then buyer will be null.You can easily check whether the value is null or not and call your method if it's not null.After the assignment buyer will be considered as IBuyer in compile-time so you will be able to call your method without a compile-time error.


---

Original Source: https://www.mindstick.com/forum/1994/interface-detection-reflection

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
