Exemple #1
0
 public ServiceInstanceGenerator(IServiceHasFactoryChecker hasServiceFactoryChecker, IFactoryProvider factoryProvider, IFactoryInstanceCreator factoryInstanceCreator, IConstructorParametersGenerator constructorParametersGenerator, IConstructorInvoker constructorInvoker, IParametersValuesExtractor parametersValuesExtractor, IServiceConstructorProvider serviceConstructorProvider)
 {
     HasServiceFactoryChecker       = hasServiceFactoryChecker;
     FactoryProvider                = factoryProvider;
     FactoryInstanceCreator         = factoryInstanceCreator;
     ConstructorParametersGenerator = constructorParametersGenerator;
     ConstructorInvoker             = constructorInvoker;
     ParametersValuesExtractor      = parametersValuesExtractor;
     ServiceConstructorProvider     = serviceConstructorProvider;
 }
        public static IConstructorInvoker GetConstructorInvoker(ConstructorInfo constructorInfo)
        {
            if (!m_ConstructorInvokerDict.ContainsKey(constructorInfo)){
                IConstructorInvoker invoker = CreateConstructorInvoker(constructorInfo);
                m_ConstructorInvokerDict.Add(constructorInfo, invoker);
                return invoker;
            }

            return m_ConstructorInvokerDict[constructorInfo];
        }
 public ConstructorInstanceCreator(IConstructorInvoker constructorInvoker, IConstructorParametersGenerator parametersGenerator,
                                   IConstructorProvider constructorProvider, IConstructorInfoListGenerator constructorInfoListGenerator, IConstructorFinder constructorFinder,
                                   IConstructorListGenerator constructorListGenerator, IParametersValuesExtractor parametersValuesExtractor)
 {
     ConstructorInvoker           = constructorInvoker;
     ParametersGenerator          = parametersGenerator;
     ConstructorProvider          = constructorProvider;
     ConstructorInfoListGenerator = constructorInfoListGenerator;
     ConstructorFinder            = constructorFinder;
     ConstructorListGenerator     = constructorListGenerator;
     ParametersValuesExtractor    = parametersValuesExtractor;
 }
Exemple #4
0
        public ExecutionVisitor(Options options)
        {
            this.methodInvoker = new CachedMethodInvoker(this);
            this.propertyGetter = new CachedReflectionPropertyGetter(methodInvoker);
            this.constructorInvoker = new CachedConstructorInvoker(methodInvoker);
            this.typeResolver = new CachedTypeResolver();
            this.fieldGetter = new CachedReflectionFieldGetter(methodInvoker);

            GlobalScope = new JsObject();
            Global = new JsGlobal(this, options);
            GlobalScope.Prototype = Global as JsDictionaryObject;
            EnterScope(GlobalScope);
            CallStack = new Stack<string>();
        }
        public ExecutionVisitor(Options options, IScriptEngineContext context)
        {
            this.scriptEngineContext = context;
            this.methodInvoker = context.GetMethodInvoker(this);//new CachedMethodInvoker(this);
            this.propertyGetter = new CachedReflectionPropertyGetter(methodInvoker);
            this.constructorInvoker = new CachedConstructorInvoker(methodInvoker);
            this.typeResolver = context.GetTypeResolver();//new CachedTypeResolver();
            this.fieldGetter = new CachedReflectionFieldGetter(methodInvoker);
            _entitiyAccessor = new EntityAccessor();

            GlobalScope = new JsObject();
            Global = new JsGlobal(this, options);
            GlobalScope.Prototype = Global as JsDictionaryObject;
            EnterScope(GlobalScope);
            CallStack = new Stack<string>();
        }
Exemple #6
0
 public ObjectBuilder(IConstructorInvoker constructor, IArgumentBuilder argumentBuilder)
 {
     _constructor     = constructor;
     _argumentBuilder = argumentBuilder;
 }
Exemple #7
0
 public void OnDeserialization(object sender)
 {
     this.methodInvoker = new CachedMethodInvoker(this);
     this.propertyGetter = new CachedReflectionPropertyGetter(methodInvoker);
     this.constructorInvoker = new CachedConstructorInvoker(methodInvoker);
     this.typeResolver = new CachedTypeResolver();
     this.fieldGetter = new CachedReflectionFieldGetter(methodInvoker);
 }
Exemple #8
0
        public SimpleTypeConverterByConstructor(
            IEnumerable <IPropertyGetter> propertyGetters,
            IEnumerable <IConstructorDefaultValuePropertyGetter> defaultValuePropertyGetters,
            IConstructorInvoker <TDest> constructorInvoker)
        {
            if (propertyGetters == null)
            {
                throw new ArgumentNullException("propertyGetters");
            }
            if (defaultValuePropertyGetters == null)
            {
                throw new ArgumentNullException("defaultValuePropertyGetters");
            }
            if (constructorInvoker == null)
            {
                throw new ArgumentNullException("constructorInvoker");
            }

            // Ensure there are no null references in the property getter content
            var propertyGettersList = new List <IPropertyGetter>();

            foreach (var propertyGetter in propertyGetters)
            {
                if (propertyGetter == null)
                {
                    throw new ArgumentException("Null reference encountered in propertyGetters list");
                }
                if (!propertyGetter.SrcType.Equals(typeof(TSource)))
                {
                    throw new ArgumentException("Encountered invalid SrcType in propertyGetters list, must match type param TSource");
                }
                propertyGettersList.Add(propertyGetter);
            }
            var defaultValuePropertyGettersList = new List <IPropertyGetter>();

            foreach (var defaultValuePropertyGetter in defaultValuePropertyGetters)
            {
                if (defaultValuePropertyGetter == null)
                {
                    throw new ArgumentException("Null reference encountered in defaultValuePropertyGetters list");
                }
                if (defaultValuePropertyGetter.Constructor != constructorInvoker.Constructor)
                {
                    throw new ArgumentException("Invalid reference encountered in defaultValuePropertyGetters set, does not match specified constructor");
                }
                defaultValuePropertyGettersList.Add(defaultValuePropertyGetter);
            }

            // Combine the propertyGetters and defaultValuePropertyGetters into a single list that correspond to the constructor arguments
            // (ensuring that the property getters correspond to the constructor that's being targetted and that the numbers of property
            // getters is correct)
            var constructorParameters = constructorInvoker.Constructor.GetParameters();

            if ((propertyGettersList.Count + defaultValuePropertyGettersList.Count) != constructorParameters.Length)
            {
                throw new ArgumentException("Number of propertyGetters.Count must match constructor.GetParameters().Length");
            }
            var combinedPropertyGetters = new List <IPropertyGetter>();
            var propertyMappings        = new List <PropertyMappingDetails>();

            for (var index = 0; index < constructorParameters.Length; index++)
            {
                var constructorParameter       = constructorParameters[index];
                var defaultValuePropertyGetter = defaultValuePropertyGetters.FirstOrDefault(p => p.ArgumentName == constructorParameter.Name);
                if (defaultValuePropertyGetter != null)
                {
                    // There's no validation to perform here, the IConstructorDefaultValuePropertyGetter interface states that the TargetType
                    // will match the named constructor argument that it relates to
                    combinedPropertyGetters.Add(defaultValuePropertyGetter);
                    continue;
                }

                // If there was no default value property getter, then the first entry in the propertyGetters set should correspond to the
                // current constructor argument (since we keep removing the first item in that set when a match is found, this remains true
                // as we process multiple arguments)
                if (propertyGettersList.Count == 0)
                {
                    throw new ArgumentException("Unable to match a property getter to constructor argument \"" + constructorParameter.Name + "\"");
                }
                var propertyGetter = propertyGettersList[0];
                if (!constructorParameter.ParameterType.IsAssignableFrom(propertyGetter.TargetType))
                {
                    throw new ArgumentException("propertyGetter[" + index + "].TargetType is not assignable to corresponding constructor parameter type");
                }
                combinedPropertyGetters.Add(propertyGetter);
                propertyGettersList.RemoveAt(0);

                propertyMappings.Add(
                    new PropertyMappingDetails(
                        propertyGetter.Property,
                        constructorParameter.Name,
                        constructorParameter.ParameterType
                        )
                    );
            }

            _constructorInvoker = constructorInvoker;
            _propertyGetters    = combinedPropertyGetters;

            PropertyMappings = propertyMappings.AsReadOnly();
        }
 public IObjectBuilder CreateBuilder(IConstructorInvoker constructorInvoker, IArgumentBuilder argumentBuilder)
 {
     return(new ObjectBuilder(constructorInvoker, argumentBuilder));
 }