Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IHaveChildren {
- string ParentType { get; }
- int ParentId { get; }
- List<IChild> GetChildren()
- }
- public interface IHaveChildren {
- string ParentType { get; }
- int ParentId { get; }
- }
- public static class HaveChildrenExtension {
- public static List<IChild> GetChildren( this IHaveChildren ) {
- //logic to get children by parent type and id
- //shared for all classes implementing IHaveChildren
- }
- }
- public interface INode {
- INode Root { get; }
- List<INode> GetChildren( );
- }
- public interface IChildNode : INode {
- INode Parent { get; }
- }
- public static class NodeExtensions {
- public INode GetParent( this INode node ) {
- // If the node implements the new interface, call it directly.
- var childNode = node as IChildNode;
- if( !object.ReferenceEquals( childNode, null ) )
- return childNode.Parent;
- // Otherwise, fall back on a default implementation.
- return FindParent( node, node.Root );
- }
- }
- public interface ILongMethod {
- public bool LongMethod( string s, double d, int i, object o, ... );
- }
- ...
- public static LongMethodExtensions {
- public bool LongMethod( this ILongMethod lm, string s, double d ) {
- lm.LongMethod( s, d, 0, null );
- }
- ...
- }
- IInterface variable = new ImplementingClass();
- public interface IHaveChildren
- {
- string ParentType { get; }
- int ParentId { get; }
- }
- public interface IChildIterator
- {
- IEnumerable<IChild> GetChildren();
- }
- public void DefaultChildIterator : IChildIterator
- {
- private readonly IHaveChildren _parent;
- public DefaultChildIterator(IHaveChildren parent)
- {
- _parent = parent;
- }
- public IEnumerable<IChild> GetChildren()
- {
- // default child iterator impl
- }
- }
- public class Node : IHaveChildren, IChildIterator
- {
- // *snip*
- public IEnumerable<IChild> GetChildren()
- {
- return new DefaultChildIterator(this).GetChildren();
- }
- }
- ((IFirst)this).AmbigousMethod()
- namespace Model
- {
- class Person
- {
- public string Title { get; set; }
- public string FirstName { get; set; }
- public string Surname { get; set; }
- }
- }
- namespace View
- {
- static class PersonExtensions
- {
- public static string FullName(this Model.Person p)
- {
- return p.Title + " " + p.FirstName + " " + p.Surname;
- }
- public static string FormalName(this Model.Person p)
- {
- return p.Title + " " + p.FirstName[0] + ". " + p.Surname;
- }
- }
- }
- public static List<long> GetIds<T>(this List<T> original){
- List<long> ret = new List<long>();
- if (original == null)
- return ret;
- try
- {
- foreach (T t in original)
- {
- IIDable idable = (IIDable)t;
- ret.Add(idable.getId());
- }
- return ret;
- }
- catch (Exception)
- {
- throw new Exception("Class calling this extension must implement IIDable interface");
- }
Add Comment
Please, Sign In to add comment