public static IMvxViewModel ReflectionGetViewModel(this IMvxView view)
        {
            var propertyInfo = view?.GetType().GetProperty("ViewModel");

            return (IMvxViewModel) propertyInfo?.GetGetMethod().Invoke(view, new object[] { });
        }
Example #2
0
 public static string GetName(this IPlayer player)
 {
     return player?.GetType().Name;
 }
Example #3
0
		static public string SensorObjectToString(this object Obj)
		{
			return
				(Obj as string) ??
				Obj?.GetType()?.ToString();
		}
Example #4
0
 public static bool HasProperty(this object obj, string propertyName)
 {
     return obj?.GetType().GetRuntimeProperty(propertyName) != null;
 }
Example #5
0
 public static object ValueByName(this object obj, string propertyName)
     => obj?.GetType().GetRuntimeProperty(propertyName).GetValue(obj);
Example #6
0
 /// <summary>
 /// Gets the type of the specified reference, or null if it is null.
 /// </summary>
 /// <param name="reference">The reference we interested in retrieving the type (may be null).</param>
 /// <returns>
 /// The type of the specified reference, or null if the reference is null.
 /// </returns>
 public static Type GetTypeWithoutThrowingException(this object reference)
 {
     return reference?.GetType();
 }
Example #7
0
 /// <summary>
 /// Gets a runtime type information out of the provided instance.
 /// </summary>
 /// <param name="obj">The object.</param>
 /// <returns>A dynamic type information for the provided object.</returns>
 public static IRuntimeTypeInfo GetRuntimeTypeInfo(this object obj)
 {
     return obj?.GetType().AsRuntimeTypeInfo();
 }
Example #8
0
 /// <summary>
 /// Dynamically gets the property value.
 /// </summary>
 /// <param name="obj">The object.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <returns>The property value.</returns>
 /// <remarks>If the object passed is <c>null</c>, then <see cref="Undefined.Value"/> is returned.</remarks>
 public static object TryGetPropertyValue(this object obj, string propertyName)
 {
     var dynamicType = obj?.GetType().AsRuntimeTypeInfo();
     return dynamicType?.TryGetValue(obj, propertyName);
 }