Exemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="type">
        /// The .NET type of this ContentInfo. Must implement IDisposable.
        /// </param>
        /// <param name="parseMethod">
        /// The parser method for this ContentInfo. Validity will be checked
        /// at runtime such that the return type of this method is assignable
        /// to the type of this ContentInfo.
        /// </param>
        /// <param name="idempotent">
        /// Whether or not a new object is created on every call of Load[T] for
        /// a given key.
        /// </param>
        public ContentInfo(Type type,
            ContentLoadDelegate parseMethod, Boolean idempotent)
        {
            Idempotent = idempotent;

            if (typeof(IDisposable).IsAssignableFrom(type) == false)
            {
                throw new ArgumentException(String.Format("Type '{0}' does not " +
                    "implement IDisposable.", type));
            }
            Type = type;

            if (type.IsAssignableFrom(parseMethod.Method.ReturnType) == false)
            {
                throw new ArgumentException(String.Format("ParseMethod for type '{0}' " +
                    "doesn't return something assignable to that type. Returns '{1}' instead.",
                    type,
                    parseMethod.Method.ReturnType));
            }
            ParseMethod = parseMethod;
        }
Exemplo n.º 2
0
 /// <summary>
 /// A simplified constructor for ContentInfo.
 /// </summary>
 /// <param name="type">
 /// The .NET type of this ContentInfo. Must implement IDisposable.
 /// </param>
 /// <param name="parseMethod">
 /// The parser method for this ContentInfo. Validity will be checked
 /// at runtime such that the return type of this method is assignable
 /// to the type of this ContentInfo.
 /// </param>
 /// <param name="idempotent">
 /// Whether or not a new object is created on every call of Load[T] for
 /// a given key.
 /// </param>
 public ContentInfo(Type type, ContentLoadDelegate parseMethod, Boolean idempotent)
     : this(type, null, parseMethod, idempotent)
 {
 }