public static Expression <Func <string> > GetExpression([NotNull] string typeFullName, [NotNull] string property) { try { // ReSharper disable once AssignNullToNotNullAttribute return(Expression.Lambda <Func <string> >(Expression.Property(null, ExtendedType.FindType(typeFullName), property))); } catch { return(null); } }
/// <summary> /// Overrides the default binder, firstly by using a cache of <see cref="Type"/>s based on the assembly name and type name, /// speeding up type binding, but also allowing easy overrides using /// <see cref="WebApplications.Utilities.Serialization.ExtendedSerializationBinder.MapType"/>. /// </summary> /// <param name="assemblyName"> /// Specifies the <see cref="System.Reflection.Assembly"/> name of the serialized object. /// </param> /// <param name="typeName"> /// Specifies the <see cref="System.Type"/> name of the serialized object. /// </param> /// <returns>The mapped type.</returns> /// <exception cref="OverflowException"> /// The type map contains the <see cref="int.MaxValue">maximum</see> number of elements. /// </exception> /// <seealso cref="System.Reflection.Assembly"/> /// <seealso cref="System.Reflection.AssemblyName"/> public override Type BindToType(string assemblyName, string typeName) { if (assemblyName == null) { throw new ArgumentNullException(nameof(assemblyName)); } if (typeName == null) { throw new ArgumentNullException(nameof(typeName)); } return(_typeMap.GetOrAdd( Reflection.SimplifiedTypeFullName(new[] { typeName, assemblyName }.JoinNotNullOrWhiteSpace(",")), n => ExtendedType.FindType(n, false, true))); }
public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data) { if (data == null) { return(null); } string typeName = (string)data; // ReSharper disable ExceptionNotDocumented Type result = ExtendedType.FindType(typeName, false, true); // ReSharper restore ExceptionNotDocumented if (result == null) { throw new ArgumentException( // ReSharper disable once AssignNullToNotNullAttribute string.Format(Resources.SimplifiedTypeNameConverter_ConvertFrom_Unknown_Type, typeName), nameof(data)); } return(result); }