/// <summary> /// Gets the full downcast object by going through multi-class-inheritance classes. /// </summary> /// <param name="userType">The user type that has multi-class-inheritance.</param> /// <returns>Fully downcasted C# object.</returns> public static UserType GetDowncast(this UserType userType) { IMultiClassInheritance mci = userType as IMultiClassInheritance; while (mci != null) { userType = mci.DowncastParent as UserType; mci = userType as IMultiClassInheritance; } return(userType); }
/// <summary> /// Helper function for doing downcasting. /// </summary> /// <typeparam name="T">Type to do the cast to.</typeparam> /// <param name="userType">The user type to be downcasted.</param> private static T AsDowncast <T>(UserType userType) where T : UserType { while (userType != null) { T result = userType as T; if (result != null) { return(result); } IMultiClassInheritance mc = userType as IMultiClassInheritance; userType = mc?.DowncastParent; } return(null); }