public ObjectResolver(IServiceLocator services, BindingRegistry binders, IBindingLogger logger) { _services = services; _binders = binders; _logger = logger; _propertySetter = binders.PropertySetter; }
public ReflectObjectProperties(object toReflect) { ReflectedObject = toReflect; ReflectedType = toReflect.GetType(); var thisType = this.GetType(); var setters = cache.GetOrAdd(thisType, (_) => { return(GetOwnSettableProperties().Select(ownProperty => { IPropertySetter propertySetter = null; var bindingFlags = GetBindingFlags(ownProperty); var isAction = FuncActionPropertyCheck(ownProperty.PropertyType); if (isAction.HasValue && !FuncActionPropertyIsProperty(ownProperty)) { propertySetter = new MethodSetter(ownProperty, isAction.Value, bindingFlags, ReflectedType); } else { propertySetter = new PropertySetter(ownProperty, bindingFlags, ReflectedType); } return propertySetter; }).ToList()); }); setters.ForEach(setter => setter.Set(this, ReflectedObject)); }
public void ShouldSetPropertyValue() { var targetType = typeof(SampleClassWithInjectionProperties); var targetProperty = targetType.GetProperty("SomeProperty"); Assert.IsNotNull(targetProperty); // Configure the target var instance = new SampleClassWithInjectionProperties(); // This is the service that should be assigned // to the SomeProperty property object service = new SampleClass(); // Initialize the container var container = new ServiceContainer(); container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "LinFu*.dll"); IPropertySetter setter = container.GetService <IPropertySetter>(); Assert.IsNotNull(setter); setter.Set(instance, targetProperty, service); Assert.IsNotNull(instance.SomeProperty); Assert.AreSame(service, instance.SomeProperty); }
private Option CreateOptionFromProperty(PropertyInfo property) { OptionAttribute optionAttribute = GetOptionAttribute(property); IPropertySetter propertySetter = _propertySetterRegistry.GetPropertySetter(property.PropertyType); return(Option.Create(optionAttribute, property, propertySetter)); }
/// <summary> /// /// </summary> /// <param name="factory"></param> /// <param name="properties"> /// { /// "name":"厦门空间库", /// "server":"192.168.1.166", /// "database":"orcl", /// "port":1521, /// "username":"******", /// "encrypted":0, /// "password":"******" /// } /// <paramref name="checkMetaValid">是否检测连接元数据的有效性</paramref> /// </param> public DMEOracleDS(IDMEDataSourceFactory factory, IPropertySetter properties, Boolean checkMetaValid = false) : base(factory, properties, checkMetaValid) { if (checkMetaValid) { Check(properties); } }
private static IPropertySetter RGB() { IPropertySetter ipro = (IPropertySetter) new PropertySetter(); DESHelper.AddParameter(ipro, "InternalName", "Standard"); return(ipro); }
/// <summary> /// add Transition on IAMTimelineComp /// 设置推出进入效果 /// </summary> public static int SetTransition(ref IAMTimeline m_pTimeline, IAMTimelineComp pComp, Guid EffectGUID, string Direction, long StartTime, long EndTime, Property[] parArr) { int hr; IAMTimelineObj pTransObj; IAMTimelineTransable pTransable = (IAMTimelineTransable)pComp; hr = m_pTimeline.CreateEmptyNode(out pTransObj, TimelineMajorType.Transition); hr = pTransable.TransAdd(pTransObj); pTransObj.SetStartStop(StartTime, EndTime); hr = pTransObj.SetSubObjectGUID(EffectGUID); IPropertySetter ipro = (IPropertySetter) new PropertySetter(); if (parArr != null && parArr.Length > 0) { foreach (Property pro in parArr) { DESHelper.AddParameter(ipro, pro.Name, pro.Value); } } DESHelper.AddParameter(ipro, "Duration", EndTime / DESConsts.UNITS - StartTime / DESConsts.UNITS); hr = pTransObj.SetPropertySetter(ipro); //Set transition Direction if (Direction.ToLower() == "true") { IAMTimelineTrans pTrans = (IAMTimelineTrans)pTransObj; pTrans.SetSwapInputs(true); } return(hr); }
public static TableEntityToPocoConverter <TOutput> Create() { IPropertySetter <TOutput, string> partitionKeySetter = GetSetter <string>("PartitionKey"); IPropertySetter <TOutput, string> rowKeySetter = GetSetter <string>("RowKey"); IPropertySetter <TOutput, DateTimeOffset> timestampSetter = GetSetter <DateTimeOffset>("Timestamp"); IPropertySetter <TOutput, string> eTagSetter = GetSetter <string>("ETag"); Dictionary <string, IPropertySetter <TOutput, EntityProperty> > otherPropertySetters = new Dictionary <string, IPropertySetter <TOutput, EntityProperty> >(); PropertyInfo[] properties = typeof(TOutput).GetProperties(BindingFlags.Instance | BindingFlags.Public); Debug.Assert(properties != null); foreach (PropertyInfo property in properties) { Debug.Assert(property != null); if (TableClient.IsSystemProperty(property.Name) || !property.CanWrite || property.GetIndexParameters().Length != 0 || !property.HasPublicSetMethod()) { continue; } IPropertySetter <TOutput, EntityProperty> otherPropertySetter = GetOtherSetter(property); otherPropertySetters.Add(property.Name, otherPropertySetter); } return(new TableEntityToPocoConverter <TOutput>(partitionKeySetter, rowKeySetter, timestampSetter, eTagSetter, otherPropertySetters)); }
protected override bool Check(IPropertySetter properties) { // 检测数据源需要的参数 if (null == base._propertySetter) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, "连接属性为空"); } //this.name = (string)_propertySetter.GetProperty(nameof(this.name)); //if (string.IsNullOrEmpty(this.name)) //{ // throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL_INIT, $"缺失连接属性[{nameof(this.name)}]"); //} if (!_propertySetter.IsExist(nameof(this.server))) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"缺失连接属性[{nameof(this.server)}]"); } this.server = (string)_propertySetter.GetProperty(nameof(this.server)); if (string.IsNullOrEmpty(this.server)) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"连接属性[{nameof(this.server)}]不能为空"); } if (!_propertySetter.IsExist(nameof(this.dataBase))) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"缺失连接属性[{nameof(this.dataBase)}]"); } this.dataBase = (string)_propertySetter.GetProperty(nameof(this.dataBase)); if (string.IsNullOrEmpty(this.dataBase)) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"连接属性[{nameof(this.dataBase)}]不能为空"); } if (!_propertySetter.IsExist(nameof(this.port))) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"缺失连接属性[{nameof(this.port)}]"); } this.port = (int)_propertySetter.GetProperty(nameof(this.port)); if (!_propertySetter.IsExist(nameof(this.userName))) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"缺失连接属性[{nameof(this.userName)}]"); } this.userName = (string)_propertySetter.GetProperty(nameof(this.userName)); if (string.IsNullOrEmpty(this.userName)) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"连接属性[{nameof(this.userName)}]不能为空"); } if (!_propertySetter.IsExist(nameof(this.encrypted))) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"缺失连接属性[{nameof(this.encrypted)}]"); } this.encrypted = (int)_propertySetter.GetProperty(nameof(this.encrypted)); if (!_propertySetter.IsExist(nameof(this.password))) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"缺失连接属性[{nameof(this.password)}]"); } this.password = (string)_propertySetter.GetProperty(nameof(this.password)); if (string.IsNullOrEmpty(this.password)) { throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, $"连接属性[{nameof(this.password)}]不能为空"); } return(true); }
private static IPropertySetter <TOutput, EntityProperty> GetOtherSetterGeneric <TProperty>(PropertyInfo property) { IConverter <EntityProperty, TProperty> converter = EntityPropertyToTConverterFactory.Create <TProperty>(); IPropertySetter <TOutput, TProperty> propertySetter = PropertyAccessorFactory <TOutput> .CreateSetter <TProperty>(property); return(new ConverterPropertySetter <TOutput, TProperty, EntityProperty>(converter, propertySetter)); }
/// <summary> /// It can be a ClassPointer, a MemberComponentId, or a TypePointer. /// /// </summary> /// <returns></returns> private IClass getActionExecuter() { IPropertySetter sp = ActionMethod as IPropertySetter; if (sp != null) { MemberComponentIdCustom c = sp.SetProperty.Holder as MemberComponentIdCustom; if (c != null) { return(c.Pointer); } return(sp.SetProperty.Holder); } else { IObjectIdentity mp = ActionMethod.IdentityOwner; IMemberPointer p = ActionMethod as IMemberPointer; if (p != null) { return(p.Holder); } MemberComponentIdCustom mcc = mp as MemberComponentIdCustom; if (mcc != null) { return(mcc.Pointer); } MemberComponentId mmc = mp as MemberComponentId; if (mmc != null) { return(mmc); } p = mp as IMemberPointer; if (p != null) { return(p.Holder); } IObjectPointer op = mp as IObjectPointer; IClass co = mp as IClass; while (co == null && op != null) { op = op.Owner; co = op as IClass; p = op as IMemberPointer; if (p != null) { return(p.Holder); } } if (co != null) { return(co); } else { throw new DesignerException("Cannot find holder for Action [{0}]", ActionId); } } }
public DynamicBuilder( IInstanceFactory <T> instanceFactory = null, IPropertySetter propertySetter = null, IMemberSelector memberSelector = null) { InstanceFactory = instanceFactory ?? new ConstructorInstanceFactory <T>(); PropertySetter = propertySetter ?? new PropertySetter(); MemberSelector = memberSelector ?? new MemberSelector(); _properties = new ReadOnlyCollection <PropertyInfo>(MemberSelector.SelectProperties(typeof(T)).ToList()); }
/// <summary> /// Insert a transition into a transitionable object /// </summary> /// <param name="timeline"></param> /// <param name="transable"></param> /// <param name="offset"></param> /// <param name="duration"></param> /// <param name="transitionDefinition"></param> /// <param name="swapInputs"></param> /// <returns></returns> internal static IAMTimelineObj InsertTransition(IAMTimeline timeline, IAMTimelineTransable transable, string name, double offset, double duration, TransitionDefinition transitionDefinition, bool swapInputs) { int hr = 0; IAMTimelineObj transitionObj; long unitsStart = ToUnits(offset); long unitsEnd = ToUnits(offset + duration); hr = timeline.CreateEmptyNode(out transitionObj, TimelineMajorType.Transition); DESError.ThrowExceptionForHR(hr); name = string.IsNullOrEmpty(name) ? "transition" : name; if (swapInputs) { hr = transitionObj.SetUserName(string.Format("{0} (swapped inputs)", name)); DESError.ThrowExceptionForHR(hr); } else { hr = transitionObj.SetUserName(name); DESError.ThrowExceptionForHR(hr); } hr = transitionObj.SetSubObjectGUID(transitionDefinition.TransitionId); DESError.ThrowExceptionForHR(hr); hr = transitionObj.SetStartStop(unitsStart, unitsEnd); DESError.ThrowExceptionForHR(hr); IAMTimelineTrans trans1 = transitionObj as IAMTimelineTrans; if (swapInputs) { hr = trans1.SetSwapInputs(true); DESError.ThrowExceptionForHR(hr); } if (transitionDefinition.Parameters.Count > 0) { IPropertySetter setter1 = (IPropertySetter) new PropertySetter(); PopulatePropertySetter(setter1, transitionDefinition.Parameters); hr = transitionObj.SetPropertySetter(setter1); DESError.ThrowExceptionForHR(hr); } hr = transable.TransAdd(transitionObj); DESError.ThrowExceptionForHR(hr); return(transitionObj); }
public void SetValue_IfInstanceIsNull_Throws() { // Arrange IPropertySetter <Poco, PocoProperty> product = CreateProductUnderTest <Poco, PocoProperty>( typeof(Poco).GetProperty("Value")); Poco instance = null; PocoProperty value = new PocoProperty(); // Act & Assert ExceptionAssert.ThrowsArgumentNull(() => product.SetValue(ref instance, value), "instance"); }
public void Create_ReturnsInstance() { // Arrange PropertyInfo property = typeof(Poco).GetProperty("Value"); // Act IPropertySetter <Poco, PocoProperty> setter = ClassPropertySetter <Poco, PocoProperty> .Create(property); // Assert Assert.NotNull(setter); }
public void CreateSetter_IfClass_ReturnsInstance() { // Arrange PropertyInfo propertyInfo = typeof(Poco).GetProperty("Value"); // Act IPropertySetter <Poco, string> manager = PropertyAccessorFactory <Poco> .CreateSetter <string>(propertyInfo); // Assert Assert.NotNull(manager); }
private static IPropertySetter Amber() { IPropertySetter ipro = (IPropertySetter) new PropertySetter(); DESHelper.AddParameter(ipro, "InternalName", "Standard"); //DESHelper.AddParameter(ipro, "Desaturate", "true"); DESHelper.AddParameter(ipro, "Red", "0.1"); DESHelper.AddParameter(ipro, "Magenta", "0.09"); DESHelper.AddParameter(ipro, "Yellow", "0.25"); //DESHelper.AddParameter(ipro, "contrast", "1.0"); return(ipro); }
/// <summary> /// Set Text Color Transition /// </summary> public static int SetColor(IAMTimelineObj pSource1Obj, Color srcColor) { int hr = 0; hr = pSource1Obj.SetSubObjectGUID(DESConsts.GUID_TR_ColorSource); IPropertySetter ipro = (IPropertySetter) new PropertySetter(); DESHelper.AddParameter(ipro, "Color", srcColor.ToArgb()); pSource1Obj.SetPropertySetter(ipro); return(hr); }
public MessageParser( ITagToPropertyMapper tagToPropertyMapper, IPropertySetter compositeSetter, IValidator validators, MessageParserOptions options ) { _propertyMapper = tagToPropertyMapper ?? throw new ArgumentNullException(nameof(tagToPropertyMapper)); _compositeSetter = compositeSetter ?? throw new ArgumentNullException(nameof(compositeSetter)); _validators = validators ?? throw new ArgumentNullException(nameof(validators)); _options = options ?? throw new ArgumentNullException(nameof(options)); _messageContext = new FixMessageContext(); }
private void TestPropSet() { int hr; IPropertySetter pVal = (IPropertySetter) new PropertySetter(); IPropertySetter pVal2; hr = m_pVideoGroupObj.SetPropertySetter(pVal); DESError.ThrowExceptionForHR(hr); hr = m_pVideoGroupObj.GetPropertySetter(out pVal2); DESError.ThrowExceptionForHR(hr); Debug.Assert(pVal == pVal2, "PropertySetter"); }
public TypePopulator(IFixtureConfiguration configuration, IConstraintHelper helper, ITypePropertySelector propertySelector, IPropertySetter setter, ITypeFieldSelector fieldSelector, IFieldSetter fieldSetter) { _configuration = configuration; _helper = helper; _propertySelector = propertySelector; _setter = setter; _fieldSelector = fieldSelector; _fieldSetter = fieldSetter; }
public TOutput Convert(ITableEntity input) { if (input == null) { return(default(TOutput)); } TOutput result = new TOutput(); if (_partitionKeySetter != null) { _partitionKeySetter.SetValue(ref result, input.PartitionKey); } if (_rowKeySetter != null) { _rowKeySetter.SetValue(ref result, input.RowKey); } if (_timestampSetter != null) { _timestampSetter.SetValue(ref result, input.Timestamp); } IDictionary <string, EntityProperty> properties = input.WriteEntity(operationContext: null); if (properties != null) { foreach (KeyValuePair <string, IPropertySetter <TOutput, EntityProperty> > pair in _otherPropertySetters) { string propertyName = pair.Key; if (properties.ContainsKey(propertyName)) { IPropertySetter <TOutput, EntityProperty> setter = pair.Value; Debug.Assert(setter != null); EntityProperty propertyValue = properties[propertyName]; setter.SetValue(ref result, propertyValue); } } } if (_eTagSetter != null) { _eTagSetter.SetValue(ref result, input.ETag); } return(result); }
private TableEntityToPocoConverter( IPropertySetter <TOutput, string> partitionKeySetter, IPropertySetter <TOutput, string> rowKeySetter, IPropertySetter <TOutput, DateTimeOffset> timestampSetter, IPropertySetter <TOutput, string> eTagSetter, IReadOnlyDictionary <string, IPropertySetter <TOutput, EntityProperty> > otherPropertySetters) { Debug.Assert(otherPropertySetters != null); _partitionKeySetter = partitionKeySetter; _rowKeySetter = rowKeySetter; _timestampSetter = timestampSetter; _eTagSetter = eTagSetter; _otherPropertySetters = otherPropertySetters; }
public void SetValue_IfPrivateProperty_UpdatesValue() { // Arrange IPropertySetter <Poco, PocoProperty> product = CreateProductUnderTest <Poco, PocoProperty>( typeof(Poco).GetProperty("PrivateValue", BindingFlags.NonPublic | BindingFlags.Instance)); Poco instance = new Poco(); PocoProperty expected = new PocoProperty(); // Act product.SetValue(ref instance, expected); // Assert PocoProperty actual = instance.PrivateValueAsPublic; Assert.Same(expected, actual); }
public void SetValue_UpdatesValue() { // Arrange IPropertySetter <Poco, PocoProperty> product = CreateProductUnderTest <Poco, PocoProperty>( typeof(Poco).GetProperty("Value")); Poco instance = new Poco(); PocoProperty expected = new PocoProperty(); // Act product.SetValue(ref instance, expected); // Assert PocoProperty actual = instance.Value; Assert.Same(expected, actual); }
public void SetValue(string name, string propertyName, object value, IPropertySetter setter) { if (DBNull.Value.Equals(value)) { value = null; } if (setter != null) { setter.Set(this.store[name].DataObject, value); return; } PropertyInfo property = this.store[name].Type.GetProperty(propertyName); object value2 = LanguagePrimitives.ConvertTo(value, property.PropertyType); property.SetValue(this.store[name].DataObject, value2, null); }
/// <summary> /// Add Parameter to Effect /// </summary> public static void AddParameter(IPropertySetter ipro, string parName, object parValue) { DexterParam param; DexterValue[] value; param = new DexterParam(); value = new DexterValue[1]; param.Name = parName; param.dispID = 0; param.nValues = 1; value[0].v = parValue; value[0].rt = 0; value[0].dwInterp = Dexterf.Jump; ipro.AddProp(param, value); }
public ConverterPropertySetter(IConverter <TConvertedProperty, TProperty> converter, IPropertySetter <TReflected, TProperty> propertySetter) { if (converter == null) { throw new ArgumentNullException("converter"); } if (propertySetter == null) { throw new ArgumentNullException("propertySetter"); } _converter = converter; _propertySetter = propertySetter; }
/// <summary> /// 实现画中画颜色偏移 /// </summary> /// <param name="m_pTimeline"></param> /// <param name="pComp"></param> /// <param name="StartTime"></param> /// <param name="EndTime"></param> /// <returns></returns> public static int SetAlpha(ref IAMTimeline m_pTimeline, IAMTimelineComp pComp, long StartTime, long EndTime) { int hr = 0; IAMTimelineObj pTransObj; hr = m_pTimeline.CreateEmptyNode(out pTransObj, TimelineMajorType.Effect); IAMTimelineEffectable aEffectable = (IAMTimelineEffectable)pComp; pTransObj.SetStartStop(StartTime, EndTime); pTransObj.SetSubObjectGUID(DESConsts.GUID_EF_Alpha); aEffectable.EffectInsBefore(pTransObj, -1); IPropertySetter ipro = (IPropertySetter) new PropertySetter(); DESHelper.AddParameter(ipro, "alpha", 255); hr = pTransObj.SetPropertySetter(ipro); return(hr); }
/// <summary> /// Set Sign Color on IAMTimelineComp /// </summary> public static int SetPixelate(ref IAMTimeline m_pTimeline, IAMTimelineComp pComp, long StartTime, long EndTime, int Zoom) { int hr = 0; IAMTimelineObj pTransObj; hr = m_pTimeline.CreateEmptyNode(out pTransObj, TimelineMajorType.Effect); IAMTimelineEffectable aEffectable = (IAMTimelineEffectable)pComp; pTransObj.SetStartStop(StartTime, EndTime); pTransObj.SetSubObjectGUID(new Guid("F67BBA3B-1980-48CB-92BB-CC826BF458E6")); aEffectable.EffectInsBefore(pTransObj, -1); IPropertySetter ipro = (IPropertySetter) new PropertySetter(); DESHelper.AddParameter(ipro, "A2VRatio", Zoom.ToString()); hr = pTransObj.SetPropertySetter(ipro); return(hr); }
private void MakeChange(SyncSession session, IPropertySetter setter, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { setter.SetValue(session, mapping, srcValues, targetObj); }
///<summary> ///Gets the <b>current</b> value of this property ///</summary> public override object GetCurrentValue(IPropertySetter iPropSetter, Part p) { // ignore iPropSetter, just use it's current value return int.Parse((string) Value); // return int (this should in fact be determined dynamically) }