//[DebuggerStepThrough] ////[DebuggerHidden] public object NewInstance(CompositeInstance compositeInstance, StateHolder stateHolder, UsesInstance uses) { var injectionContext = new InjectionContext(compositeInstance, uses, stateHolder); object mixin = this.injectedObjectBuilder.NewInstance(injectionContext); return(mixin); }
public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { Object result; RoleMapHolder.ROLE_MAPS.Value.Peek().TryGetRole <Object>(((RoleAttribute)model.InjectionScope).Name, targetType, out result); return(result); }
public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { Object result = null; if (targetType.IsAssignableFrom(typeof(CollectionsFactory))) { result = instance.StructureOwner.Application.CollectionsFactory; } else if (targetType.IsAssignableFrom(typeof(ApplicationSPI))) { result = instance.StructureOwner.Application; } else if (targetType.IsAssignableFrom(typeof(StructureServiceProviderSPI))) { result = this.GetStructureServiceProvider(instance, model, targetType); } else if (targetType.IsAssignableFrom(typeof(UsesProviderQuery))) { result = instance.UsesContainer; } else if (targetType.IsAssignableFrom(typeof(CompositeModel)) || targetType.IsAssignableFrom(typeof(ServiceCompositeModel))) { result = instance.ModelInfo.Model; } else if (targetType.IsAssignableFrom(typeof(CompositeInstance))) { result = instance; } else { result = this.ProvideNonStandardInjection(instance, model, targetType); } return(result); }
public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { InvocationInfo invocationInfo = instance.InvocationInfo; Object result; if (Object.Equals(typeof(MethodInfo), targetType)) { result = invocationInfo.CompositeMethod; } else if (Object.Equals(typeof(CompositeMethodModel), targetType)) { result = invocationInfo.FragmentMethodModel.CompositeMethod; } else if (typeof(AbstractFragmentMethodModel).IsAssignableFrom(targetType)) { result = invocationInfo.FragmentMethodModel; } else { AttributeHolder holder = instance.ModelInfo.CompositeMethodAttributeHolders[invocationInfo.FragmentMethodModel.CompositeMethod.MethodIndex]; if (typeof(Attribute).IsAssignableFrom(targetType)) { ListQuery <Attribute> list; holder.AllAttributes.TryFindInTypeDictionarySearchBottommostType(targetType, out list); result = list.FirstOrDefault(); } else // target type must be attribute holder { result = holder; } } return(result); }
public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { Object retVal; instance.Composites.TryGetValue(targetType, out retVal); return(retVal); }
// For mixins //[DebuggerStepThrough] ////[DebuggerHidden] public InjectionContext(CompositeInstance compositeInstance, UsesInstance uses, StateHolder state) { this.CompositeInstance = compositeInstance; this.ModuleInstance = compositeInstance.ModuleInstance; this.Uses = uses; this.State = state; this.Next = null; this.ProxyHandler = null; }
//[DebuggerStepThrough] ////[DebuggerHidden] public void NewMixins(CompositeInstance compositeInstance, UsesInstance uses, StateHolder stateHolder, object[] mixins) { int i = 0; foreach (MixinModel mixinModel in this.mixinModels) { object mixin = mixinModel.NewInstance(compositeInstance, stateHolder, uses); mixins[i++] = mixin; } }
//[DebuggerStepThrough] ////[DebuggerHidden] public object Invoke(object proxy, MethodInfo method, object[] args) { if (method.Name == "ToString") { return(this.owner.ServiceModel.ToString()); } CompositeInstance instance = this.owner.GetInstance(); return(instance.Invoke(proxy, method, args)); }
public T NewInstance() { StateHolder instanceState = this.state == null?this.transientModel.NewInitialState() : this.transientModel.NewState(this.state); this.transientModel.State.CheckConstraints(instanceState); CompositeInstance compositeInstance = this.transientModel.NewCompositeInstance(this.moduleInstance, this.uses ?? UsesInstance.NoUses, instanceState); return((T)compositeInstance.Proxy); }
public K PrototypeFor <K>() { // Instantiate given value type if (this.prototypeInstance == null) { this.prototypeInstance = this.transientModel.NewCompositeInstance(this.moduleInstance, this.Uses, this.State); } return((K)this.prototypeInstance.NewProxy(typeof(K))); }
public T Prototype() { // Instantiate proxy for given composite interface if (this.prototypeInstance == null) { this.prototypeInstance = this.transientModel.NewCompositeInstance(this.moduleInstance, this.Uses, this.State); } return((T)this.prototypeInstance.Proxy); }
public virtual CompositeInstance GetCompositeInstance(Object compositeOrFragment) { ArgumentValidator.ValidateNotNull("Composite or fragment", compositeOrFragment); CompositeInstance instance = null; this._compositeModelTypeSupport.Values.FirstOrDefault(support => support.TryGetInstanceFromCompositeOrFragment(compositeOrFragment, out instance)); if (instance == null) { throw new ArgumentException("Given argument " + compositeOrFragment + " is not valid composite or fragment."); } return(instance); }
public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { var scope = model.InjectionScope; Object result; if (typeof(CompositeState).IsAssignableFrom(targetType)) { result = instance.State; } else { var attribute = (StateAttribute)scope; var isCompositeProperty = typeof(CompositeProperty).IsAssignableFrom(targetType); var prop = this.FindSuitable <CompositeProperty, PropertyInfo>( instance.State.Properties.Values, attribute.DeclaringType, attribute.ElementName, GetActualTargetType <CompositeProperty>(targetType), cProp => cProp.ReflectionInfo, pInfo => pInfo.PropertyType ); if (prop != null) { result = isCompositeProperty ? prop : prop.PropertyValueAsObject; } else { var isCompositeEvent = typeof(CompositeEvent).IsAssignableFrom(targetType); var evt = this.FindSuitable <CompositeEvent, EventInfo>( instance.State.Events.Values, attribute.DeclaringType, attribute.ElementName, GetActualTargetType <CompositeEvent>(targetType), cEvent => cEvent.ReflectionInfo, eventInfo => eventInfo.EventHandlerType ); if (evt != null) { result = isCompositeEvent ? evt : evt.InvokeActionAsObject; } else { result = null; } } } return(result); }
public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { KeyedRoleMap roleMap = RoleMapHolder.INVOCATION_DATA.Value.RoleMap; Object result; if (roleMap.ThisHasRole(targetType)) { result = roleMap.Get <Object>(targetType); } else { FunctionInvocationDataAttribute attr = (FunctionInvocationDataAttribute)model.InjectionScope; result = attr.GetFactory(targetType).NewInvocationData(); roleMap.Set(result); } return(result); }
/// <summary> /// Gets reference to composite of given type. /// </summary> /// <param name="instance">The <see cref="CompositeInstance"/>.</param> /// <param name="compositeType">The type of the composite. If it is <see cref="Object"/>, then composite reference of one of the public types is returned.</param> /// <returns>The reference to composite of type <paramref name="compositeType"/>.</returns> /// <exception cref="NullReferenceException">If <paramref name="instance"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">If <paramref name="compositeType"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">If composite of given type is not found.</exception> public static Object GetCompositeForType(this CompositeInstance instance, Type compositeType) { ArgumentValidator.ValidateNotNull("Composite type", compositeType); Object result; if (Object.Equals(typeof(Object), compositeType)) { result = instance.Composites.Values.FirstOrDefault(composite => instance.ModelInfo.Model.PublicTypes.Any(pType => pType.GetGenericDefinitionIfContainsGenericParameters().IsAssignableFrom_IgnoreGenericArgumentsForGenericTypes(composite.GetType()))); } else { instance.Composites.TryGetValue(compositeType, out result); } if (result == null) { throw new ArgumentException("Did not found composites of type " + compositeType + "."); } return(result); }
public object ProvideInjection(InjectionContext context, InjectionAttribute attribute, Type fieldType) { object obj = context.Uses.UseForType(fieldType); if (obj != null) { return(obj); } ModuleInstance moduleInstance = context.ModuleInstance; TransientFinder compositeFinder = moduleInstance.FindCompositeModel(fieldType); if (compositeFinder.Model != null) { CompositeInstance compositeInstance = compositeFinder.Model.NewCompositeInstance(moduleInstance, context.Uses, context.State); context.Uses.Use(compositeInstance); return(compositeInstance.Proxy); } return(null); }
/** * <summary>Generates a single classification instance of the WSD problem for the given word of the given sentence. If the * word has not been labeled with sense tag yet, the method returns null. In the WSD problem, the system also * generates and stores all possible sense labels for the current instance. In this case, a classification * instance will not have all labels in the dataset, but some subset of it.</summary> * <param name="sentence">Input sentence.</param> * <param name="wordIndex">The index of the word in the sentence.</param> * <returns>Classification instance.</returns> */ public override Instance GenerateInstanceFromSentence(Sentence sentence, int wordIndex) { var possibleSynSets = ((AnnotatedSentence.AnnotatedSentence)sentence).ConstructSynSets(_wordNet, _fsm, wordIndex); var word = (AnnotatedWord)sentence.GetWord(wordIndex); var classLabel = word.GetSemantic(); if (classLabel == null || possibleSynSets.Count == 0) { return(null); } var current = new CompositeInstance(classLabel); var possibleClassLabels = new List <string>(); foreach (var synSet in possibleSynSets) { possibleClassLabels.Add(synSet.GetId()); } current.SetPossibleClassLabels(possibleClassLabels); AddAttributes(current, sentence, wordIndex); return(current); }
public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { return(_holder == null ? _holder2 : _holder); }
public virtual Boolean TryGetInstanceFromCompositeOrFragment(Object composite, out CompositeInstance instance) { var cType = composite.GetType(); var codeGenInfo = this._modelScopeSupport.CodeGenerationInfo; var result = cType.GetAssembly().GetCustomAttributes( ).OfType <Qi4CSGeneratedAssemblyAttribute>().Any(); if (result) { var field = composite.GetType() #if WINDOWS_PHONE_APP .GetTypeInfo().GetDeclaredField(codeGenInfo.CompositeInstanceFieldName) #else .GetField(codeGenInfo.CompositeInstanceFieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly) #endif ; result = field != null; if (result && codeGenInfo.CompositeInstanceFieldType.IsAssignableFrom(field.FieldType)) { instance = (CompositeInstance)field.GetValue(composite); } else { instance = null; } } else { instance = null; } return(result); }
//[DebuggerStepThrough] ////[DebuggerHidden] public object Invoke(MixinsInstance mixins, CompositeInstance compositeInstance, object proxy, MethodInfo method, object[] args, ModuleInstance moduleInstance) { return this.compositeMethodsModel.Invoke(mixins, proxy, method, args, moduleInstance); }
/// <summary> /// Gets reference to composite of given type, when type is known at compile time. /// </summary> /// <typeparam name="TComposite">The type of the composite referece.</typeparam> /// <param name="instance">The <see cref="CompositeInstance"/>.</param> /// <returns>The reference to composite of type <typeparamref name="TComposite"/>, when type is known at compile time.</returns> /// <exception cref="NullReferenceException">If <paramref name="instance"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">If composite of given type is not found.</exception> public static TComposite GetCompositeForType <TComposite>(this CompositeInstance instance) { return((TComposite)GetCompositeForType(instance, typeof(TComposite))); }
/// <summary> /// Creates a new instance of <see cref="CompositeModelInstantiationArgs"/>. /// </summary> /// <param name="instance">The <see cref="CompositeInstance"/> of the composite that was instantiated.</param> /// <exception cref="ArgumentNullException">If <paramref name="instance"/> is <c>null</c>.</exception> public CompositeModelInstantiationArgs(CompositeInstance instance) { ArgumentValidator.ValidateNotNull("Composite instance", instance); this._instance = instance; }
public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { return(((CompositeInstanceImpl)instance).CreateOrGetConcernInvocationBase(targetType)); }
/// <summary> /// Creates a new instance of <see cref="ServiceActivationArgs"/>. /// </summary> /// <param name="service">The <see cref="CompositeInstance"/> of the service composite.</param> /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <c>null</c>.</exception> public ServiceActivationArgs(CompositeInstance service) { ArgumentValidator.ValidateNotNull("Service", service); this._service = service; }
/** * <summary> Constructor for generating a new {@link DataSet} from given {@link File}.</summary> * * <param name="file">{@link File} to generate {@link DataSet} from.</param> */ public DataSet(string fileName) { var i = 0; _instances = new InstanceList.InstanceList(); _definition = new DataDefinition(); var input = new StreamReader(fileName); while (!input.EndOfStream) { var instanceText = input.ReadLine(); var attributes = instanceText.Split(","); if (i == 0) { for (var j = 0; j < attributes.Length - 1; j++) { try { double.Parse(attributes[j]); _definition.AddAttribute(AttributeType.CONTINUOUS); } catch (Exception) { _definition.AddAttribute(AttributeType.DISCRETE); } } } else { if (attributes.Length != _definition.AttributeCount() + 1) { continue; } } Instance.Instance instance; if (!attributes[attributes.Length - 1].Contains(";")) { instance = new Instance.Instance(attributes[attributes.Length - 1]); } else { var labels = attributes[attributes.Length - 1].Split(";"); instance = new CompositeInstance(labels); } for (var j = 0; j < attributes.Length - 1; j++) { switch (_definition.GetAttributeType(j)) { case AttributeType.CONTINUOUS: instance.AddAttribute(new ContinuousAttribute(double.Parse(attributes[j]))); break; case AttributeType.DISCRETE: instance.AddAttribute(new DiscreteAttribute(attributes[j])); break; } } if (instance.AttributeSize() == _definition.AttributeCount()) { _instances.Add(instance); } i++; } input.Close(); }
protected override SPI.Instance.StructureServiceProviderSPI GetStructureServiceProvider(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { return(((SingletonApplication)instance.StructureOwner).StructureServices); }
public object NewInstance(CompositeInstance compositeInstance, StateHolder stateHolder) { return this.NewInstance(compositeInstance, stateHolder, UsesInstance.NoUses); }
//[DebuggerStepThrough] ////[DebuggerHidden] public object NewInstance(CompositeInstance compositeInstance, StateHolder stateHolder, UsesInstance uses) { var injectionContext = new InjectionContext(compositeInstance, uses, stateHolder); object mixin = this.injectedObjectBuilder.NewInstance(injectionContext); return mixin; }
internal void InvokeAfterPassivation(CompositeInstance instance) { this.AfterPassivation.InvokeEventIfNotNull(evt => evt(this, new ServiceActivationArgs(instance))); }
protected abstract StructureServiceProviderSPI GetStructureServiceProvider(CompositeInstance instance, AbstractInjectableModel model, Type targetType);
public object NewInstance(CompositeInstance compositeInstance, StateHolder stateHolder) { return(this.NewInstance(compositeInstance, stateHolder, UsesInstance.NoUses)); }
protected virtual Object ProvideNonStandardInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType) { return(null); }
internal void InvokeCompositeInstantiated(CompositeInstance instance) { this.CompositeInstantiated.InvokeEventIfNotNull(evt => evt(this, new CompositeModelInstantiationArgs(instance))); }