Пример #1
0
        /// <summary>
        /// Creates a FastClass for the specified target type.
        /// </summary>
        /// <param name="targetType">Type of the target.</param>
        /// <returns></returns>
        public static FastClass Create(Type targetType)
        {
            lock(fastClassCacheLock)
            {
                FastClass fastClass = null;
                if (!fastClassCache.TryGetValue(targetType, out fastClass))
                {
                    fastClass = new FastClass(targetType, fastClassId++);
                    fastClassCache[targetType] = fastClass;
                }

                return fastClass;
            }
        }
Пример #2
0
        /// <summary>
        /// Creates the capsule.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="fields">The fields.</param>
        /// <returns></returns>
        public static FastClass CreateCapsule(String name, params CapsuleField[] fields)
        {
            ModuleBuilder moduleBuilder = GetModuleBuilder();
            TypeBuilder   typeBuilder   = moduleBuilder.DefineType(
                name,
                TypeAttributes.Public |
                TypeAttributes.Class |
                TypeAttributes.AutoClass |
                TypeAttributes.AnsiClass |
                TypeAttributes.BeforeFieldInit |
                TypeAttributes.AutoLayout,
                typeof(object));

            foreach (CapsuleField field in fields)
            {
                typeBuilder.DefineField(
                    field.Name,
                    field.Type,
                    FieldAttributes.Public);
            }

            return(FastClass.Create(typeBuilder.CreateType()));
        }
Пример #3
0
 /// <summary>
 /// Creates the method.
 /// </summary>
 /// <param name="method">The method.</param>
 /// <returns></returns>
 public static FastMethod CreateMethod(MethodInfo method)
 {
     FastClass fastClass = Create(method.DeclaringType);
     return fastClass.GetMethod(method);
 }