System.Reflection.TypeInfo.IsAssignableFrom C# (CSharp) Method

IsAssignableFrom() public method

public IsAssignableFrom ( TypeInfo typeInfo ) : bool
typeInfo TypeInfo
return bool
		public virtual bool IsAssignableFrom (TypeInfo typeInfo)
		{
			return IsAssignableFrom (typeInfo.AsType ());
		}
	}

Usage Example

Esempio n. 1
0
        /// <summary>
        ///   Copies the value of all fields from one <see cref="object"/> to another.
        /// </summary>
        internal static void CopyTo <T>(this T from, T to) where T : class
        {
            // Find base type of both compilations
            TypeInfo fromType = from.GetType().GetTypeInfo();
            TypeInfo toType   = to.GetType().GetTypeInfo();
            Type     baseType;

            if (fromType.IsAssignableFrom(toType))
            {
                // ToCompilation inherits FromCompilation
                baseType = fromType.AsType();
            }
            else if (toType.IsAssignableFrom(fromType))
            {
                // FromCompilation inherits ToCompilation
                baseType = toType.AsType();
            }
            else
            {
                // No common type: find first common type
                baseType = FindCommonType(fromType.AsType(), toType.AsType());
            }

            // Copy fields from one compilation to the other
            foreach (FieldInfo field in baseType.GetAllFields())
            {
                if (field.IsStatic)
                {
                    continue;
                }

                field.SetValue(to, field.GetValue(from));
            }
        }
All Usage Examples Of System.Reflection.TypeInfo::IsAssignableFrom