Пример #1
0
        internal static TSchema GetInstance <TSchema>() where TSchema : ObjectSchema, new()
        {
            ObjectSchema.SchemaConstructorDelegate schemaConstructor = () => Activator.CreateInstance <TSchema>();
            ObjectSchema instanceImpl = ObjectSchema.GetInstanceImpl(typeof(TSchema), schemaConstructor);

            return((TSchema)((object)instanceImpl));
        }
Пример #2
0
 internal static ObjectSchema GetInstance(Type schemaType)
 {
     if (null == schemaType)
     {
         throw new ArgumentNullException("schemaType");
     }
     if (!typeof(ObjectSchema).GetTypeInfo().IsAssignableFrom(schemaType.GetTypeInfo()))
     {
         throw new ArgumentException(string.Format("Invalid ObjectSchema Input Type: {0}", schemaType), "schemaType");
     }
     if (!ReflectionHelper.HasParameterlessConstructor(schemaType))
     {
         throw new ArgumentException(string.Format("Input type does not have a parameterless constructor: {0}", schemaType), "schemaType");
     }
     ObjectSchema.SchemaConstructorDelegate schemaConstructor = () => (ObjectSchema)Activator.CreateInstance(schemaType);
     return(ObjectSchema.GetInstanceImpl(schemaType, schemaConstructor));
 }
Пример #3
0
        private static ObjectSchema GetInstanceImpl(Type schemaType, ObjectSchema.SchemaConstructorDelegate schemaConstructor)
        {
            ObjectSchema result;

            if (!ObjectSchema.Instances.TryGetValue(schemaType, out result))
            {
                lock (ObjectSchema.InstancesLock)
                {
                    if (!ObjectSchema.Instances.TryGetValue(schemaType, out result))
                    {
                        ObjectSchema objectSchema = schemaConstructor();
                        ObjectSchema.Instances = new Dictionary <Type, ObjectSchema>(ObjectSchema.Instances)
                        {
                            {
                                schemaType,
                                objectSchema
                            }
                        };
                        result = objectSchema;
                    }
                }
            }
            return(result);
        }