internal Field(FieldInfo fieldInfo) : base(fieldInfo) { if (!typeof(TDeclaringType).IsAssignableFrom(fieldInfo.DeclaringType)) { throw new ArgumentException("TDeclaringType is not assignable from the DeclaringType of the fieldInfo", "fieldInfo"); } if (!typeof(TFieldType).IsAssignableFrom(fieldInfo.FieldType)) { throw new ArgumentException("TFieldType is not assignable from the FieldType of the fieldInfo", "fieldInfo"); } _fieldInfo = fieldInfo; _fieldType = new Lazy <ITypeCrawler>(() => TypeCrawler.Get(fieldInfo.FieldType)); _getValueLooselyTypedExpression = new Lazy <Expression <Func <object, object> > >(() => ExpressionFactory.CreateGetValueFuncExpression(fieldInfo)); _setValueLooselyTypedExpression = new Lazy <Expression <Action <object, object> > >(() => ExpressionFactory.CreateSetValueFuncExpression(fieldInfo)); _getValueStronglyTypedExpression = new Lazy <Expression <Func <TDeclaringType, TFieldType> > >(() => ExpressionFactory.CreateGetValueFuncExpression <TDeclaringType, TFieldType>(fieldInfo)); _setValueStronglyTypedExpression = new Lazy <Expression <Action <TDeclaringType, TFieldType> > >(() => ExpressionFactory.CreateSetValueFuncExpression <TDeclaringType, TFieldType>(fieldInfo)); _getValueLooselyTyped = new Lazy <Func <object, object> >(() => _getValueLooselyTypedExpression.Value.Compile()); _setValueLooselyTyped = new Lazy <Action <object, object> >(() => _setValueLooselyTypedExpression.Value.Compile()); _getValueStronglyTyped = new Lazy <Func <TDeclaringType, TFieldType> >(() => _getValueStronglyTypedExpression.Value.Compile()); _setValueStronglyTyped = new Lazy <Action <TDeclaringType, TFieldType> >(() => _setValueStronglyTypedExpression.Value.Compile()); }
internal Property(PropertyInfo propertyInfo) : base(propertyInfo) { if (!typeof(TDeclaringType).IsAssignableFrom(propertyInfo.DeclaringType)) { throw new ArgumentException("TDeclaringType is not assignable from the DeclaringType of the propertyInfo", "propertyInfo"); } if (!typeof(TPropertyType).IsAssignableFrom(propertyInfo.PropertyType)) { throw new ArgumentException("TPropertyType is not assignable from the PropertyType of the propertyInfo", "propertyInfo"); } _propertyInfo = propertyInfo; _getMethod = new Lazy <MethodInfo>(() => propertyInfo.GetGetMethod(true)); _setMethod = new Lazy <MethodInfo>(() => propertyInfo.GetSetMethod(true)); _isPublic = new Lazy <bool>(propertyInfo.IsPublic); _propertyType = new Lazy <ITypeCrawler>(() => TypeCrawler.Get(propertyInfo.PropertyType)); _getValueLooselyTypedExpression = new Lazy <Expression <Func <object, object> > >(() => ExpressionFactory.CreateGetValueFuncExpression(propertyInfo)); _setValueLooselyTypedExpression = new Lazy <Expression <Action <object, object> > >(() => ExpressionFactory.CreateSetValueFuncExpression(propertyInfo)); _getValueStronglyTypedExpression = new Lazy <Expression <Func <TDeclaringType, TPropertyType> > >(() => ExpressionFactory.CreateGetValueFuncExpression <TDeclaringType, TPropertyType>(propertyInfo)); _setValueStronglyTypedExpression = new Lazy <Expression <Action <TDeclaringType, TPropertyType> > >(() => ExpressionFactory.CreateSetValueFuncExpression <TDeclaringType, TPropertyType>(propertyInfo)); _getValueLooselyTyped = new Lazy <Func <object, object> >(() => _getValueLooselyTypedExpression.Value.Compile()); _setValueLooselyTyped = new Lazy <Action <object, object> >(() => _setValueLooselyTypedExpression.Value.Compile()); _getValueStronglyTyped = new Lazy <Func <TDeclaringType, TPropertyType> >(() => _getValueStronglyTypedExpression.Value.Compile()); _setValueStronglyTyped = new Lazy <Action <TDeclaringType, TPropertyType> >(() => _setValueStronglyTypedExpression.Value.Compile()); }
internal Member(MemberInfo memberInfo) { _declaringType = new Lazy <ITypeCrawler>(() => TypeCrawler.Get(memberInfo.DeclaringType)); }
internal Constructor(ConstructorInfo constructorInfo) : base(constructorInfo) { if (constructorInfo == null) { throw new ArgumentNullException("constructorInfo"); } _constructorInfo = constructorInfo; _invokeExpression = new Lazy <Expression <Func <object[], object> > >(() => ExpressionFactory.CreateConstructorFuncExpression(constructorInfo)); _invoke = new Lazy <Func <object[], object> >(() => _invokeExpression.Value.Compile()); _parameters = new Lazy <ITypeCrawler[]>(() => constructorInfo.GetParameters().Select(p => TypeCrawler.Get(p.ParameterType)).ToArray()); }