コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextMetadata"/> class.
        /// </summary>
        /// <param name="clazz">
        /// The class annotated with <see cref="ForElementAttribute"/>.
        /// </param>
        /// <param name="list">
        /// The list of the instance field marked with the annotation
        /// <see cref="ForTextAttribute"/>. The type of the field must be
        /// <see cref="string"/>.
        /// </param>
        public TextMetadata(
            Type clazz, IEnumerable <FieldInfo> list)
            : base(clazz)
        {
            var size = list.Count();

            Debug.Assert(size == 1, $"{size}");
            var textField   = list.First();
            var type        = textField.FieldType;
            var sugarcoater = StringSugarcoaters.Of(type);

            Reflector = new Reflector <string>(
                textField.SetValue, type, sugarcoater);
        }
コード例 #2
0
 /// <summary>
 /// Gets the attribute name of each member (that is either field or
 /// method) in the specified collection with the specified function,
 /// and associates the attribute name with a <see cref="Reflector{T}"/>
 /// object using the specified Action.
 /// </summary>
 /// <typeparam name="T">
 /// The type of the field/method information.
 /// </typeparam>
 /// <param name="all">
 /// The collection of the field/method.
 /// </param>
 /// <param name="getAnnotation">
 /// The function mapping of a field/method to the attribute name.
 /// </param>
 /// <param name="getType">
 /// The function mapping of a field/method to the type.
 /// </param>
 /// <param name="toInjector">
 /// The function that returns the injector associated with the
 /// specified type.
 /// </param>
 /// <param name="put">
 /// <see cref="ReflectorMap{K,V}.Put(K, Reflector{V})"/>.
 /// </param>
 private static void Scan <T>(
     IEnumerable <T> all,
     Func <T, XmlQualifiedName> getAnnotation,
     Func <T, Type> getType,
     Func <T, Injector> toInjector,
     Action <XmlQualifiedName, Reflector <string> > put)
     where T : MemberInfo
 {
     foreach (var m in all)
     {
         var name        = getAnnotation(m);
         var type        = getType(m);
         var sugarcoater = StringSugarcoaters.Of(type);
         var reflector   = new Reflector <string>(
             toInjector(m), type, sugarcoater);
         put(name, reflector);
     }
 }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextMetadata"/> class.
        /// </summary>
        /// <param name="clazz">
        /// The class annotated with <see cref="ForElementAttribute"/>.
        /// </param>
        /// <param name="list">
        /// The list of the instance method marked with the annotation <see
        /// cref="FromTextAttribute"/>. The return type of the method must be
        /// <c>void</c> and the method has the single parameter whose
        /// type is <see cref="string"/>.
        /// </param>
        public TextMetadata(
            Type clazz, IEnumerable <MethodInfo> list)
            : base(clazz)
        {
            var size = list.Count();

            Debug.Assert(size == 1, $"{size}");
            var textMethod = list.First();
            var returnType = textMethod.ReturnType;

            Debug.Assert(returnType.Equals(Types.Void), $"{returnType}");
            var parameters = textMethod.GetParameters();
            var length     = parameters.Length;

            Debug.Assert(length == 1, $"{length}");
            var type        = parameters[0].ParameterType;
            var sugarcoater = StringSugarcoaters.Of(type);

            Reflector = new Reflector <string>(
                (i, t) => textMethod.Invoke(i, new[] { t }),
                type,
                sugarcoater);
        }