/// <summary> /// Lists the methods. /// </summary> /// <param name="assemblyLocation">The assembly location.</param> /// <param name="assemblyName">Name of the assembly.</param> /// <param name="fullName">The full name.</param> /// <returns></returns> public ServiceConstructorList ListConstructors(string assemblyLocation, string assemblyName, string fullName) { var serviceMethodList = new ServiceConstructorList(); if (_assemblyLoader.TryLoadAssembly(assemblyLocation, assemblyName, out Assembly assembly)) { var type = assembly.GetType(fullName); var constructors = type.GetConstructors(); constructors.ToList().ForEach(info => { var serviceConstructor = new ServiceConstructor(); var parameterInfos = info.GetParameters().ToList(); parameterInfos.ForEach(parameterInfo => { var constructorParameter = new ConstructorParameter { DefaultValue = parameterInfo.DefaultValue?.ToString() ?? string.Empty, EmptyToNull = false, IsRequired = !parameterInfo.IsOptional, Name = parameterInfo.Name, TypeName = parameterInfo.ParameterType.AssemblyQualifiedName, ShortTypeName = parameterInfo.ParameterType.FullName, }; var returnType = parameterInfo.ParameterType; BuildParameter(returnType, constructorParameter); serviceConstructor.Parameters.Add(constructorParameter); }); serviceMethodList.Add(serviceConstructor); }); } return(serviceMethodList); }
public ConstructorParameter[] GetConstructorParameters(IResolutionArgument[] parameters) { int parameterCount = 0; var parameterList = parameters.OfType <ConstructorParameter, IResolutionArgument>(); for (int i = 0; i < parameterList.Length; i++) { parameterCount++; } var constructorParameters = new ConstructorParameter[parameterCount]; int currentParameterIndex = 0; for (int i = 0; i < parameters.Length; i++) { IResolutionArgument argument = parameters[i]; if (argument is ConstructorParameter) { constructorParameters[currentParameterIndex] = (ConstructorParameter)argument; currentParameterIndex++; } } return(constructorParameters); }
protected override bool MatchesCore(ConstructorParameter argument, ParameterInfo parameter) { ResolvedParameter rp = argument.Value as ResolvedParameter; Type type = rp != null ? rp.ParameterType : argument.Value.GetType(); ICollection <string> snippets; if (!this.snippetsByType.TryGetValue(type, out snippets)) { lock (_snippetsByTypeSynchObj) { if (!this.snippetsByType.TryGetValue(type, out snippets)) { snippets = new HashSet <string>(StringComparer.OrdinalIgnoreCase); InitializeSnippets(type, snippets); this.snippetsByType.Add(type, snippets); } } } return(snippets.Contains(parameter.Name)); }
public bool Matches(ConstructorParameter argument, ParameterInfo parameter) { Guard.AssertNotNull(argument, "argument"); Guard.AssertNotNull(parameter, "parameter"); return(this.conventions.Any(convention => convention.Matches(argument, parameter))); }
private static InjectionParameterValue[] GetParameterValues(ConstructorInfo ctor, IEnumerable <ConstructorParameter> constructorArguments, IParameterMatchingConventionsPolicy conventions) { ParameterInfo[] parameters = ctor.GetParameters(); object[] parameterValues = new object[parameters.Length]; // fill in the provided values and add the type of the parameter that the // ctor expects otherwise. unity will take care of resolving parameters that // are provided that way for (int i = 0; i < parameters.Length; i++) { ConstructorParameter argument = constructorArguments.FirstOrDefault(a => conventions.Matches(a, parameters[i])); if (argument != null) { Type parameterType = parameters[i].ParameterType; if (argument.Value is string && parameterType != typeof(string) && (parameterType.IsInterface || parameterType.IsClass)) { parameterValues[i] = new ResolvedParameter(parameterType, (string)argument.Value); } else { parameterValues[i] = argument.Value; } } else { parameterValues[i] = parameters[i].ParameterType; } } return(InjectionParameterValue.ToParameters(parameterValues).ToArray()); }
public override bool Matches(ConstructorParameter argument, ParameterInfo parameter) { Guard.AssertNotNull(argument, "argument"); Guard.AssertNotNull(argument.Value, "argument.Value"); Guard.AssertNotNull(parameter, "parameter"); return(this.MatchesCore(argument, parameter)); }
protected override bool MatchesCore(ConstructorParameter argument, ParameterInfo parameter) { if (parameter.ParameterType == typeof(string)) { return(parameter.Name.Contains("connectionString", StringComparison.OrdinalIgnoreCase)); } return(false); }
protected override bool MatchesCore(ConstructorParameter argument, ParameterInfo parameter) { if (!string.IsNullOrEmpty(argument.Name)) { return(string.Equals(argument.Name, parameter.Name, StringComparison.OrdinalIgnoreCase)); } return(false); }
/// <summary> /// 編輯 /// </summary> /// <returns></returns> public ActionResult ConstructorList(ConstructorParameter param) { param.KeyWord = HttpUtility.UrlDecode(param.KeyWord); return(View( new InternalDataTransferToView { List = ConstructorProvider.List(param), Data = param })); }
public StateConstructor(ConstructorInfo info) : this(info.DeclaringType) { var parameters = info.GetParameters(); _parameters = new ConstructorParameter[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { _parameters[i] = new ConstructorParameter(parameters[i]); _name += string.Format("{0} {1}{2}", _parameters[i].Type.Name, _parameters[i].ParameterName, i < parameters.Length - 1 ? ", " : ""); } _name += ")"; }
public void TestMethodPropertyPropertyMapped7() { IParameter parameter = ConstructorParameter.Create <MappedTestClass>(); TypeDefinition <ITestProperties> typeDefinition = new TypeDefinition <ITestProperties> ( parameter, new DefinitionImport(parameter) ); ITestProperties test = typeDefinition.Create(new MappedTestClass()); test.Property1 = 42; Assert.AreEqual(42, test.Property1); }
public object GetInstance(Type type, string key, params IResolutionArgument[] parameters) { object instance; //lol thanks stucturemap for your inconsistent API, I /love/ using reflection to call methods. try { ExplicitArgsExpression expression = null; if (parameters.OfType <ConstructorParameter, IResolutionArgument>().Length > 0) { ConstructorParameter parameter1 = parameters.OfType <ConstructorParameter, IResolutionArgument>()[0]; expression = container.With(parameter1.Name).EqualTo(parameter1.Value); if (parameters.Length > 1) { ConstructorParameter[] constructorArgs = parameters.OfType <ConstructorParameter, IResolutionArgument>(); for (int i = 1; i < constructorArgs.Length; i++) { expression.With(constructorArgs[i].Name).EqualTo(constructorArgs[i].Value); } } } MethodInfo method = typeof(ExplicitArgsExpression).GetMethods().Where( m => m.IsGenericMethod && m.Name == "GetInstance" && m.GetParameters().Count() == 1).First(); method = method.MakeGenericMethod(type); instance = expression != null ? method.Invoke(expression, new object[] { key }) : container.GetInstance(type, key); } catch (StructureMapException ex) { throw new RegistrationNotFoundException(type, key, ex); } if (instance == null) { throw new RegistrationNotFoundException(type, key); } return(instance); }
public ProcConstructor(ClassAST classAST, SectionProcRaw raw) { RetZType = ZLangBasicTypes.ZVOID; ASTClass = classAST; Raw = raw; NameBracketRaw = Raw.NamePart.GetNameBracket(); ConstructorContext = new ContextConstructor(ASTClass.ClassContext); ConstructorParameterList = new List <ConstructorParameter>(); foreach (var item in NameBracketRaw.Parameters) { ConstructorParameter cp = new ConstructorParameter(this, item); ConstructorParameterList.Add(cp); } Body = new StmtBlock(this, Raw.Body); }
public ClassConstructor(ConstructorInfo info, Type type) : this(type) { _type = new TypeInfo(info.DeclaringType); _name = string.Format("{0} (", info.DeclaringType.Name); var parameters = info.GetParameters(); _parameters = new ConstructorParameter[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { _parameters[i] = new ConstructorParameter(parameters[i]); _name += string.Format("{0} {1}{2}", _parameters[i].Type.Name, _parameters[i].ParameterName, i < parameters.Length - 1 ? ", " : ""); } _name += ")"; }
protected override bool MatchesCore(ConstructorParameter argument, ParameterInfo parameter) { if (string.Equals(argument.Name, parameter.Name, StringComparison.OrdinalIgnoreCase)) { Type parameterType = parameter.ParameterType; if (argument.Value is string && parameterType != typeof(string) && (parameterType.IsClass || parameter.ParameterType.IsInterface)) { return(true); } } return(false); }
/// <summary> /// Add another constructor parameter plan /// </summary> /// <param name="index">Index of the constructor parameter</param> /// <param name="bp">Plan used to construct the parameter</param> public void AddConstructorPlan(int index, IBuildPlan bp) { if (bp == null) { throw new ArgumentNullException("bp"); } if (index < 0 || index >= Constructor.GetParameters().Length) { throw new ArgumentOutOfRangeException("index"); } _parameters[index] = new ConstructorParameter { BuildPlan = bp, ServiceType = Constructor.GetParameters()[index].ParameterType }; }
public ActionResult AjaxConstructorDelete(ConstructorParameter param) { var result = new JsonNetResult(); var r = new GeneralResponse(); try { r.Code = ConstructorProvider.Delete(param).ToString(Section.Get.Common.Culture); } catch (Exception ex) { Log.Error(ex.Message, ex); r.Code = "-11"; } result.Data = r; return(result); }
public ActionResult ConstructorEdit(ConstructorParameter param) { if ((0L < param.Entity.Id)) { param.Entity = ConstructorProvider.GetRecordById(param); } //取承包商的承包工程類別清單 param.Entity.ConsDetailType = ConstructorProvider.GetConstructorConType(param.Entity.Id); return(View(new InternalDataTransferToView { List = ConstructorProvider.GetAllConType(), //取工程類別總清單 //ConstructorProvider.GetDetail(param), Data = param })); }
public virtual bool Matches(ConstructorParameter argument, ParameterInfo parameter) { Guard.AssertNotNull(argument, "argument"); Guard.AssertNotNull(argument.Value, "argument.Value"); Guard.AssertNotNull(parameter, "parameter"); ResolvedParameter rp = argument.Value as ResolvedParameter; Type argumentValueType = rp != null ? rp.ParameterType : argument.Value.GetType(); if (argument.Value != null && parameter.ParameterType.IsAssignableFrom(argumentValueType)) { return(this.MatchesCore(argument, parameter)); } return(false); }
public ActionResult AjaxConstructorEdit(ConstructorParameter param) { var result = new JsonNetResult(); var r = new GeneralResponse(); try { r.Code = (0L < param.Entity.Id ? ConstructorProvider.Update(param) : ConstructorProvider.Create(param)).ToString(Section.Get.Common.Culture); } catch (Exception ex) { Log.Error(ex.Message, ex); r.Code = "-11" + ex.Message; } result.Data = r; return(result); }
public void LinkedMethodsReturnValueTest7() { CustomImplentation implementation = new CustomImplentation(); ConstructorParameter parameter = ConstructorParameter.Create <BoolContainer>("container"); TypeDefinition <ITestMethods> typeDefinition = new TypeDefinition <ITestMethods>( parameter, new LinkedMethodsReturnValue(nameof(ITestMethods.OutAndRef)) .MappedMethod(implementation, nameof(CustomImplentation.OutAndRef)) .Action <BoolContainer>(container => container.Value = true, parameter)); BoolContainer boolContainer = new BoolContainer(); ITestMethods instance = typeDefinition.Create(boolContainer); BoolContainer boolContainer2 = new BoolContainer(); typeDefinition.Create(boolContainer2); string text2 = "wetwt"; instance.OutAndRef(out string _, ref text2, 5); Assert.IsTrue(boolContainer.Value); Assert.IsFalse(boolContainer2.Value); }
// ---------------------------------------------------- #region // Public Methods public AnimationInstancingSystem(ConstructorParameter data) { this._animationMeshes = data.AnimationMeshes; // 最大アニメーション数分のバッファを確保 int maxAnimationNum = this._animationMeshes.Length; this._sendBuffers = new SendBuffers[maxAnimationNum]; this._animationLengthList = new NativeArray <float>(maxAnimationNum, Allocator.Persistent); // バッファの初期化及び各アニメーションの再生時間を保持 int animLengthID = Shader.PropertyToID("_Length"); for (int i = 0; i < maxAnimationNum; ++i) { this._sendBuffers[i] = new SendBuffers(); this._animationLengthList[i] = this._animationMeshes[i].AnimationMaterial.GetFloat(animLengthID); } this._maxAnimationType = Enum.GetNames(typeof(AnimationType)).Length; this._playDataBufferID = Shader.PropertyToID("_PlayDataBuffer"); }
public object GetInstance(Type type, params IResolutionArgument[] parameters) { ExplicitArgsExpression expression = null; if (parameters.OfType <ConstructorParameter, IResolutionArgument>().Length > 0) { ConstructorParameter parameter1 = parameters.OfType <ConstructorParameter, IResolutionArgument>()[0]; expression = container.With(parameter1.Name).EqualTo(parameter1.Value); if (parameters.Length > 1) { ConstructorParameter[] constructorArgs = parameters.OfType <ConstructorParameter, IResolutionArgument>(); for (int i = 1; i < constructorArgs.Length; i++) { expression.With(constructorArgs[i].Name).EqualTo(constructorArgs[i].Value); } } } return(expression != null?expression.GetInstance(type) : container.GetInstance(type)); }
/// <exception cref="InvalidOperationException">If instance cannot be created.</exception> private object Create(TypeInformation information) { Dictionary <ConstructorInfo, List <ConstructorParameter> > constructors = new Dictionary <ConstructorInfo, List <ConstructorParameter> >(); ConstructorInfo[] publicConstructors = information.InstanceType.GetConstructors(); if (publicConstructors.Length == 0) { throw new InvalidOperationException(information.InstanceType.FullName + " do not have any public constructors."); } foreach (var constructor in publicConstructors) { constructors.Add(constructor, new List <ConstructorParameter>()); foreach (var parameter in constructor.GetParameters()) { ConstructorParameter constructorParameter = new ConstructorParameter { Parameter = parameter }; constructors[constructor].Add(constructorParameter); TypeInformation typeInfo; lock (_instances) if (!_instances.TryGetValue(parameter.ParameterType, out typeInfo)) { continue; } // this constructor wont work, but check what parameters we are missing. try { constructorParameter.Instance = typeInfo.Instance ?? Create(typeInfo); } catch (InvalidOperationException err) { throw new InvalidOperationException( "Failed to create '" + typeInfo.InterfaceType.FullName + "' that '" + information.InterfaceType + "' is dependent off. Check inner exception for more details.", err); } } // check if all parameters was found. bool allFound = true; foreach (var parameter in constructors[constructor]) { if (parameter.Instance != null) { continue; } allFound = false; break; } if (!allFound) { continue; } // now create instance. information.ConstructorArguments = new object[constructors[constructor].Count]; int index = 0; foreach (var parameter in constructors[constructor]) { information.ConstructorArguments[index++] = parameter.Instance; } return(Activator.CreateInstance(information.InstanceType, information.ConstructorArguments)); } StringBuilder sb = new StringBuilder(); sb.AppendLine("Failed to create '" + information.InstanceType.FullName + "', due to missing constructorparamters."); foreach (var pair in constructors) { sb.Append(pair.Key + " are missing: "); foreach (var parameter in pair.Value) { if (parameter.Instance == null) { sb.Append(parameter.Parameter.Name + ", "); } } sb.Length -= 2; sb.AppendLine(); } throw new InvalidOperationException(sb.ToString()); }
protected abstract bool MatchesCore(ConstructorParameter argument, ParameterInfo parameter);
/// <summary> /// Add another constructor parameter plan /// </summary> /// <param name="index">Index of the constructor parameter</param> /// <param name="bp">Plan used to construct the parameter</param> public void AddConstructorPlan(int index, IBuildPlan bp) { if (bp == null) throw new ArgumentNullException("bp"); if (index < 0 || index >= Constructor.GetParameters().Length) throw new ArgumentOutOfRangeException("index"); _parameters[index] = new ConstructorParameter { BuildPlan = bp, ServiceType = Constructor.GetParameters()[index].ParameterType }; }
public void NavigateToDetails(ConstructorParameter parameter) { _navigationService.NavigateTo(ViewModelLocator.FoodDetails, new[] { parameter }); }