/// <summary> /// Used by compiler and full-reflect. /// </summary> internal DPropertyDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes) : base(declaringType, memberAttributes) { Debug.Assert(declaringType != null); this._getterStub = null; // to be generated on demand this._setterStub = null; // to be generated on demand }
public UserDefinedTypeExporter(System.Type type) { RealTypeName = UserDefinedTypeSupport.GetTypeName(type); RealType = type; var fields = UserDefinedTypeSupport.GetFields(RealType); var properties = UserDefinedTypeSupport.GetProperties(RealType); var count = fields.Count + properties.Count; Names = new string[count]; Getters = new GetterDelegate[count]; int i = 0; while (i < fields.Count) { var fieldData = fields[i]; Names[i] = fieldData.Name; Getters[i] = CreateGetter(type, fieldData.Member); ++i; } while (i < count) { var propertyData = properties[i - fields.Count]; Names[i] = propertyData.Name; Getters[i] = CreateGetter(type, propertyData.Member); ++i; } }
/// <summary> /// CCtor /// </summary> static DataContractResolverStrategy() { string[] assemblyName = typeof(Object).Assembly.FullName.Split(','); assemblyName[0] = DataContractAssemblyName; Assembly assembly = Assembly.Load(String.Join(",", assemblyName)); DataContractType = assembly.GetType(DataContractTypeName); DataMemberType = assembly.GetType(DataMemberTypeName); IgnoreDataMemberType = assembly.GetType(IgnoreDataMemberTypeName); if (DataContractType != null) { PropertyInfo property = DataContractType.GetProperty("Name", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy); DataContractNameGetter = DynamicMethodGenerator.GetPropertyGetter(property); property = DataContractType.GetProperty("Namespace", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy); DataContractNamespaceGetter = DynamicMethodGenerator.GetPropertyGetter(property); } if (DataContractResolverStrategy.DataMemberType != null) { PropertyInfo property = DataMemberType.GetProperty("Name", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy); DataMemberNameGetter = DynamicMethodGenerator.GetPropertyGetter(property); } }
public void SetLogLimits(GetterDelegate minGetter, GetterDelegate maxGetter) { Normalizer = (block, f) => { float min = minGetter(block); float max = maxGetter(block); return(MathHelper.Clamp(MathHelper.InterpLogInv(f, min, max), 0, 1)); }; Denormalizer = (block, f) => { float min = minGetter(block); float max = maxGetter(block); return(MathHelper.Clamp(MathHelper.InterpLog(f, min, max), min, max)); }; }
public void SetLimits(GetterDelegate minGetter, GetterDelegate maxGetter) { Normalizer = (block, f) => { float min = minGetter(block); float max = maxGetter(block); return(MathHelper.Clamp((f - min) / (max - min), 0, 1)); }; Denormalizer = (block, f) => { float min = minGetter(block); float max = maxGetter(block); return(MathHelper.Clamp(min + f * (max - min), min, max)); }; }
public void SetDualLogLimits(GetterDelegate minGetter, GetterDelegate maxGetter, float centerBand) { Normalizer = (block, f) => { float min = minGetter(block); float max = maxGetter(block); return(DualLogNormalizer(block, f, min, max, centerBand)); }; Denormalizer = (block, f) => { float min = minGetter(block); float max = maxGetter(block); return(DualLogDenormalizer(block, f, min, max, centerBand)); }; }
public ReducerSection(IActivator activator, ITypeRequest subReducer, Expression <StateSubSectionSelectionDelegate <TState, TSectionType> > sectionSelector) { m_sectionSelector = sectionSelector; m_sectionReducer = activator.Get <IReducer <TSectionType> >(subReducer); MemberExpression memberExpression = (MemberExpression)sectionSelector.Body; PropertyInfo propertyInfo = (PropertyInfo)memberExpression.Member; if (!propertyInfo.CanWrite || !propertyInfo.CanRead) { throw new NotAccessableSubSectionProperty($"The property {propertyInfo.Name} is being used as a Sub Section reducer however it is an invalid target. Any property used *MUST* be both to be able to be read and written to."); } m_getValue = (GetterDelegate)Delegate.CreateDelegate(typeof(GetterDelegate), propertyInfo.GetMethod); m_setValue = (SetterDelegate)Delegate.CreateDelegate(typeof(SetterDelegate), propertyInfo.SetMethod); }
internal static MbxPropertyDefinition ProxyAddressFromStringPropertyDefinition(string name, MbxPropertyDefinition rawPropertyDefinition, bool multivalued = false) { GetterDelegate getterDelegate = delegate(IPropertyBag propertyBag) { if (propertyBag[rawPropertyDefinition] != null) { return(ProxyAddress.Parse((string)propertyBag[rawPropertyDefinition])); } return(null); }; SetterDelegate setterDelegate = delegate(object value, IPropertyBag propertyBag) { propertyBag[rawPropertyDefinition] = ((ProxyAddress)value).ToString(); }; GetterDelegate getterDelegate2 = delegate(IPropertyBag propertyBag) { MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[rawPropertyDefinition]; MultiValuedProperty <ProxyAddress> multiValuedProperty2 = new MultiValuedProperty <ProxyAddress>(); foreach (string proxyAddressString in multiValuedProperty) { multiValuedProperty2.Add(ProxyAddress.Parse(proxyAddressString)); } return(multiValuedProperty2); }; SetterDelegate setterDelegate2 = delegate(object value, IPropertyBag propertyBag) { MultiValuedProperty <ProxyAddress> multiValuedProperty = (MultiValuedProperty <ProxyAddress>)value; MultiValuedProperty <string> multiValuedProperty2 = (MultiValuedProperty <string>)propertyBag[rawPropertyDefinition]; for (int i = multiValuedProperty2.Count - 1; i >= 0; i--) { if (!string.IsNullOrEmpty(multiValuedProperty2[i])) { multiValuedProperty2.RemoveAt(i); } } foreach (ProxyAddress proxyAddress in multiValuedProperty) { multiValuedProperty2.Add(proxyAddress.ToString()); } }; return(new MbxPropertyDefinition(name, PropTag.Null, ExchangeObjectVersion.Exchange2003, typeof(ProxyAddress), (multivalued ? PropertyDefinitionFlags.MultiValued : PropertyDefinitionFlags.None) | PropertyDefinitionFlags.Calculated, multivalued ? null : null, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, new MbxPropertyDefinition[] { rawPropertyDefinition }, multivalued ? getterDelegate2 : getterDelegate, multivalued ? setterDelegate2 : setterDelegate)); }
internal static ADPropertyDefinition Int64BitfieldProperty(string name, int shift, int length, ADPropertyDefinition fieldProperty, PropertyDefinitionConstraint constraint) { object defaultValue = 0L; GetterDelegate getterDelegate = delegate(IPropertyBag bag) { object obj = null; if (!(bag as ADPropertyBag).TryGetField(fieldProperty, ref obj)) { return(defaultValue); } if (obj == null) { return(defaultValue); } long num = (long)obj; long num2 = (1L << length) - 1L; return(num2 & num >> shift); }; SetterDelegate setterDelegate = delegate(object value, IPropertyBag bag) { long num = (long)bag[fieldProperty]; long num2 = (1L << length) - 1L; long num3 = (long)value; num &= ~(num2 << shift); num |= (num3 & num2) << shift; bag[fieldProperty] = num; }; PropertyDefinitionConstraint[] readConstraints; if (constraint == null) { readConstraints = PropertyDefinitionConstraint.None; } else { readConstraints = new PropertyDefinitionConstraint[] { constraint }; } return(new ADPropertyDefinition(name, fieldProperty.VersionAdded, typeof(long), null, ADPropertyDefinitionFlags.Calculated, defaultValue, readConstraints, PropertyDefinitionConstraint.None, new ADPropertyDefinition[] { fieldProperty }, null, getterDelegate, setterDelegate, null, null)); }
public static bool InsertBySortId <T>(IList <T> list, T value, GetterDelegate <T, int> compareResult) { var index = BinsearchFromRightIndex(list, compareResult); if (index == -1) { list.Add(value); return(true); } else if (compareResult(list[index]) == 0) { return(false); } else { list.Insert(index, value); return(true); } }
internal static MbxPropertyDefinition Int32FromNullableInt32PropertyDefinition(string name, MbxPropertyDefinition rawPropertyDefinition, bool multivalued = false) { GetterDelegate getterDelegate = (IPropertyBag propertyBag) => (propertyBag[rawPropertyDefinition] == null) ? 0 : ((int)propertyBag[rawPropertyDefinition]); SetterDelegate setterDelegate = delegate(object value, IPropertyBag propertyBag) { propertyBag[rawPropertyDefinition] = (((int?)value) ?? 0); }; GetterDelegate getterDelegate2 = delegate(IPropertyBag propertyBag) { MultiValuedProperty <int> multiValuedProperty = (MultiValuedProperty <int>)propertyBag[rawPropertyDefinition]; MultiValuedProperty <int> multiValuedProperty2 = new MultiValuedProperty <int>(); foreach (int value in multiValuedProperty) { int?num = new int?(value); if (num != null) { multiValuedProperty2.Add(num.Value); } } return(multiValuedProperty2); }; SetterDelegate setterDelegate2 = delegate(object value, IPropertyBag propertyBag) { MultiValuedProperty <int> multiValuedProperty = (MultiValuedProperty <int>)value; MultiValuedProperty <int> multiValuedProperty2 = (MultiValuedProperty <int>)propertyBag[rawPropertyDefinition]; for (int i = multiValuedProperty2.Count - 1; i >= 0; i--) { multiValuedProperty2.RemoveAt(i); } foreach (int item in multiValuedProperty) { multiValuedProperty2.Add(item); } }; return(new MbxPropertyDefinition(name, PropTag.Null, ExchangeObjectVersion.Exchange2003, typeof(int), (multivalued ? PropertyDefinitionFlags.MultiValued : PropertyDefinitionFlags.None) | PropertyDefinitionFlags.Calculated, multivalued ? null : 0, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, new MbxPropertyDefinition[] { rawPropertyDefinition }, multivalued ? getterDelegate2 : getterDelegate, multivalued ? setterDelegate2 : setterDelegate)); }
public Animation(Object instance, string _propertyName, T Target, T step) { propertyName = _propertyName; AnimatedInstance = instance; PropertyInfo pi = instance.GetType().GetProperty(propertyName); getValue = (GetterDelegate)Delegate.CreateDelegate(typeof(GetterDelegate), instance, pi.GetGetMethod()); setValue = (SetterDelegate)Delegate.CreateDelegate(typeof(SetterDelegate), instance, pi.GetSetMethod()); TargetValue = Target; T value = getValue(); initialValue = value; Type t = typeof(T); if (t.IsPrimitive) { Step = (T)Convert.ChangeType(step, t); zero = (T)Convert.ChangeType(0, t); } else { Step = (T)Activator.CreateInstance(typeof(T), new Object[] { step }); zero = (T)Activator.CreateInstance(typeof(T), 0f); } T test = (T)Operator.SubtractAlternative(value, TargetValue); if (Operator.LessThan(test, zero)) { if (Operator.LessThan(Step, zero)) { Step = Operator.Negate(Step); } } else if (Operator.GreaterThan(Step, zero)) { Step = Operator.Negate(Step); } }
public AValueSync(string valueId, string fieldName, bool save = true) : base(typeof(TScript), valueId, save) { Type type = typeof(TScript); FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { _getter = GenerateGetter(field); _setter = GenerateSetter(field); DefaultValueAttribute defaultAtt = field.GetCustomAttribute <DefaultValueAttribute>(); _defaultValue = defaultAtt != null ? (TValue)defaultAtt.Value : default(TValue); traceLog("default value: " + _defaultValue, condition: defaultAtt != null); RegisterSetDefaultValue(); return; } throw new ArgumentException(fieldName + " does not match any instance field of " + type.Name); }
/// <param name="valueId">Identifier for the value</param> /// <param name="save">Save the value to disk.</param> public AValueSync(string valueId, GetterDelegate getter, SetterDelegate setter, bool save = true, TValue defaultValue = default(TValue)) : base(typeof(TScript), valueId, save) { _defaultValue = defaultValue; _getter = getter; _setter = setter; RegisterSetDefaultValue(); #if DEBUG if (typeof(TValue) == typeof(StringBuilder)) { _getter = script => { TValue value = getter(script); if (value == null) { alwaysLog("Returning null StringBuilder", Logger.severity.FATAL); } return(value); } } ; #endif }
internal RegistryPropertyDefinition(string name, Type type, PropertyDefinitionFlags flags, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints, ProviderPropertyDefinition[] supportingProperties, CustomFilterBuilderDelegate customFilterBuilderDelegate, GetterDelegate getterDelegate, SetterDelegate setterDelegate) : base(name, ExchangeObjectVersion.Exchange2003, type, (defaultValue != null) ? (flags | PropertyDefinitionFlags.PersistDefaultValue) : flags, defaultValue, readConstraints, writeConstraints, supportingProperties, customFilterBuilderDelegate, getterDelegate, setterDelegate) { }
/// <summary> /// Used by type population. /// </summary> internal DPhpFieldDesc(DTypeDesc/*!*/ declaringType, PhpMemberAttributes memberAttributes, GetterDelegate getterStub, SetterDelegate setterStub) : base(declaringType, memberAttributes) { Debug.Assert(declaringType != null && (getterStub != null || setterStub != null)); this._getterStub = getterStub; this._setterStub = setterStub; }
public ProviderPropertyDefinition(string name, ExchangeObjectVersion versionAdded, Type type, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints, ProviderPropertyDefinition[] supportingProperties, CustomFilterBuilderDelegate customFilterBuilderDelegate, GetterDelegate getterDelegate, SetterDelegate setterDelegate) : base(name, type) { if (supportingProperties == null) { throw new ArgumentNullException("supportingProperties"); } if (readConstraints == null) { throw new ArgumentNullException("readConstraints"); } if (writeConstraints == null) { throw new ArgumentNullException("writeConstraints"); } if (name == null) { throw new ArgumentNullException("name"); } if (type == null) { throw new ArgumentNullException("type"); } if (versionAdded == null) { throw new ArgumentNullException("versionAdded"); } if (defaultValue != null && !ReflectionHelper.IsInstanceOfType(defaultValue, type)) { throw new ArgumentException(DataStrings.ExceptionDefaultTypeMismatch.ToString(), "defaultValue (" + name + ")"); } if (type == typeof(bool) && defaultValue != null) { defaultValue = BoxedConstants.GetBool((bool)defaultValue); } this.defaultValue = defaultValue; this.customFilterBuilderDelegate = customFilterBuilderDelegate; this.versionAdded = versionAdded; if (readConstraints.Length < 1) { this.readOnlyReadConstraints = ProviderPropertyDefinition.EmptyConstraint.Collection; } else { this.readOnlyReadConstraints = new ReadOnlyCollection <PropertyDefinitionConstraint>(readConstraints); } if (writeConstraints.Length < 1 && readConstraints.Length < 1) { this.allStaticConstraints = PropertyDefinitionConstraint.None; this.readOnlyAllConstraints = ProviderPropertyDefinition.EmptyConstraint.Collection; } else { this.allStaticConstraints = new PropertyDefinitionConstraint[readConstraints.Length + writeConstraints.Length]; Array.Copy(writeConstraints, this.allStaticConstraints, writeConstraints.Length); Array.Copy(readConstraints, 0, this.allStaticConstraints, writeConstraints.Length, readConstraints.Length); this.readOnlyAllConstraints = new ReadOnlyCollection <PropertyDefinitionConstraint>(this.allStaticConstraints); } this.getterDelegate = getterDelegate; this.setterDelegate = setterDelegate; if (supportingProperties.Length < 1) { this.supportingProperties = ProviderPropertyDefinition.EmptyCollection; } else { this.supportingProperties = new ReadOnlyCollection <ProviderPropertyDefinition>(supportingProperties); } List <CollectionPropertyDefinitionConstraint> list = new List <CollectionPropertyDefinitionConstraint>(); List <CollectionPropertyDefinitionConstraint> list2 = new List <CollectionPropertyDefinitionConstraint>(); for (int i = 0; i < writeConstraints.Length; i++) { CollectionPropertyDefinitionConstraint collectionPropertyDefinitionConstraint = writeConstraints[i] as CollectionPropertyDefinitionConstraint; if (collectionPropertyDefinitionConstraint != null) { list.Add(collectionPropertyDefinitionConstraint); } } for (int j = 0; j < readConstraints.Length; j++) { CollectionPropertyDefinitionConstraint collectionPropertyDefinitionConstraint2 = readConstraints[j] as CollectionPropertyDefinitionConstraint; if (collectionPropertyDefinitionConstraint2 != null) { list.Add(collectionPropertyDefinitionConstraint2); list2.Add(collectionPropertyDefinitionConstraint2); } } if (list.Count < 1) { this.allStaticCollectionConstraints = ProviderPropertyDefinition.EmptyCollectionConstraint.Array; this.readOnlyAllCollectionConstraints = ProviderPropertyDefinition.EmptyCollectionConstraint.Collection; } else { this.allStaticCollectionConstraints = list.ToArray(); this.readOnlyAllCollectionConstraints = new ReadOnlyCollection <CollectionPropertyDefinitionConstraint>(this.allStaticCollectionConstraints); } if (list2.Count < 1) { this.readOnlyReadCollectionConstraints = ProviderPropertyDefinition.EmptyCollectionConstraint.Collection; } else { this.readOnlyReadCollectionConstraints = new ReadOnlyCollection <CollectionPropertyDefinitionConstraint>(list2.ToArray()); } this.readOnlyDependentProperties = ProviderPropertyDefinition.EmptyCollection; if (this.supportingProperties.Count == 0) { this.dependentProperties = new List <ProviderPropertyDefinition>(); } foreach (ProviderPropertyDefinition providerPropertyDefinition in supportingProperties) { if (providerPropertyDefinition.IsCalculated) { throw new ArgumentException(string.Format("The calculated property '{0}' cannot depend on another calculated property '{1}'", base.Name, providerPropertyDefinition.Name), "supportingProperties"); } if (this.VersionAdded.IsOlderThan(providerPropertyDefinition.VersionAdded)) { throw new ArgumentException(string.Format("The calculated property '{0}' cannot depend on the newer property '{1}'", base.Name, providerPropertyDefinition.Name), "supportingProperties"); } providerPropertyDefinition.AddDependency(this); } if (defaultValue != null && defaultValue != string.Empty) { PropertyValidationError propertyValidationError = this.ValidateValue(defaultValue, false); if (propertyValidationError != null) { throw new ArgumentException(propertyValidationError.Description, "defaultValue"); } } }
/// <inheritdoc /> protected override IProjection CreateProjection(GetterDelegate leftGetter, GetterDelegate rightGetter, SetterDelegate leftSetter, SetterDelegate rightSetter) { return(new EqualityCheckProjection(leftGetter, rightGetter, leftSetter, rightSetter)); }
/// <summary> /// Initializes a new instance of the <see cref="AccessorMetadata"/> class. /// </summary> /// <param name="getter">Getter delegate.</param> /// <param name="setter">Setter delegate.</param> public AccessorMetadata(GetterDelegate getter, SetterDelegate setter) { this.getter = getter; this.setter = setter; }
internal Accessors(GetterDelegate getter, SetterDelegate setter) { Getter = getter; Setter = setter; }
public AccessorMetadata(GetterDelegate getter, SetterDelegate setter) { this.getter = getter; this.setter = setter; }
/// <summary> /// Constructor. /// </summary> /// <param name="property"><see cref="System.Reflection.PropertyInfo"/> to wrap.</param> internal ImmediateProperty([NotNull] PropertyInfo property) : base(property) { Debug.Assert(!IsIndexed(property), $"Cannot initialize an {nameof(ImmediateProperty)} with an indexed property."); // General property info PropertyInfo = property; PropertyType = property.PropertyType; #if SUPPORTS_LAZY _propertyImmediateType = new Lazy <ImmediateType>(() => TypeAccessor.Get(PropertyType)); #endif // ReSharper disable once AssignNullToNotNullAttribute, Justification: A property is always declared inside a type. DeclaringType = property.DeclaringType; CanRead = property.CanRead; CanWrite = property.CanWrite; // Getter / Setter _getter = ConfigureGetter(); _setter = ConfigureSetter(); #region Local functions GetterDelegate ConfigureGetter() { GetterDelegate getter = null; MethodInfo getMethod = property.GetGetMethod(true); if (getMethod != null) { getter = DelegatesFactory.CreateGetter(property, getMethod); } if (getter is null) { return(target => throw new ArgumentException($"No getter for property {Name}.")); } return(getter); } SetterDelegate ConfigureSetter() { SetterDelegate setter = null; MethodInfo setMethod = property.GetSetMethod(true); if (setMethod != null) { setter = DelegatesFactory.CreateSetter(property, setMethod); } if (setter is null) { return((target, value) => throw new ArgumentException($"No setter for property {Name}.")); } return(setter); } #endregion }
/// <summary> /// Creates a new instance of <see cref="EqualityCheckProjection"/> /// </summary> public EqualityCheckProjection(GetterDelegate leftGetter, GetterDelegate rightGetter, SetterDelegate leftSetter, SetterDelegate rightSetter) : base(leftGetter, rightGetter, leftSetter, rightSetter) { }
/// <summary> /// 二分查找对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <param name="comparer"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public static T Binsearch <T>(this T[] array, GetterDelegate <int, int> comparer, int start, int end) { int index = BinsearchIndex(comparer, start, end); return(index == -1 ? default(T) : array[index]); }
/// <summary> /// Gets a delegate which determines if the property or field should not be serialized based upon its value. /// </summary> /// <param name="member"></param> /// <returns>if has a value equivalent to the DefaultValueAttribute or has a property named XXXSpecified which determines visibility</returns> /// <remarks> /// This is useful when default values need not be serialized. /// Under these situations XmlSerializer ignores properties based upon value: /// - DefaultValue: http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultvalueattribute.aspx /// - Specified Properies: http://msdn.microsoft.com/en-us/library/bb402199.aspx /// - ShouldSerialize Methods: http://msdn.microsoft.com/en-us/library/53b8022e.aspx /// </remarks> public override ValueIgnoredDelegate GetValueIgnoredCallback(MemberInfo member) { Type objType = member.ReflectedType ?? member.DeclaringType; // look up specified property to see if exists GetterDelegate specifiedPropertyGetter = null; PropertyInfo specProp = objType.GetProperty(member.Name + SpecifiedSuffix, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); // ensure is correct return type if (specProp != null && specProp.PropertyType == typeof(bool)) { specifiedPropertyGetter = DynamicMethodGenerator.GetPropertyGetter(specProp); } // look up specified property to see if exists ProxyDelegate shouldSerializeProxy = null; MethodInfo shouldSerialize = objType.GetMethod(ShouldSerializePrefix + member.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); // ensure is correct return type if (shouldSerialize != null && shouldSerialize.ReturnType == typeof(bool) && shouldSerialize.GetParameters().Length == 0) { shouldSerializeProxy = DynamicMethodGenerator.GetMethodProxy(shouldSerialize); } // to be most efficient must create a different delegate for each of 8 combinations so not performing extra work DefaultValueAttribute defaultAttr = TypeCoercionUtility.GetAttribute <DefaultValueAttribute>(member); if (defaultAttr == null) { if (specifiedPropertyGetter == null) { if (shouldSerializeProxy == null) { // situation 1: only need to check if equal to null return(delegate(object target, object value) { return (value == null); }); } // situation 2: create a delegate which simply calls the should serialize method return(delegate(object target, object value) { return (value == null) || Object.Equals(false, shouldSerializeProxy(target)); }); } if (shouldSerializeProxy == null) { // situation 3: create a delegate which simply calls the specified property return(delegate(object target, object value) { return (value == null) || Object.Equals(false, specifiedPropertyGetter(target)); }); } // situation 4: create a delegate which calls both the specified property and the should serialize method return(delegate(object target, object value) { return (value == null) || Object.Equals(false, shouldSerializeProxy(target)) || Object.Equals(false, specifiedPropertyGetter(target)); }); } // extract default value since cannot change (is constant in attribute) object defaultValue = defaultAttr.Value; if (specifiedPropertyGetter == null) { if (shouldSerializeProxy == null) { // situation 5: create a specific delegate which only has to compare the default value to the current value return(delegate(object target, object value) { return (value == null) || Object.Equals(defaultValue, value); }); } // situation 6: create a specific delegate which both compares to default value and calls should serialize method return(delegate(object target, object value) { return (value == null) || Object.Equals(defaultValue, value) || Object.Equals(false, shouldSerializeProxy(target)); }); } if (shouldSerializeProxy == null) { // situation 7: create a specific delegate which both compares to default value and checks specified property return(delegate(object target, object value) { return (value == null) || Object.Equals(defaultValue, value) || Object.Equals(false, specifiedPropertyGetter(target)); }); } // situation 8: create a combined delegate which checks all states return(delegate(object target, object value) { return (value == null) || Object.Equals(defaultValue, value) || Object.Equals(false, shouldSerializeProxy(target)) || Object.Equals(false, specifiedPropertyGetter(target)); }); }
public static T Binsearch <T>(IList <T> list, GetterDelegate <T, int> compareResult) { int index = BinsearchIndex(list, compareResult); return(index == -1 ? default(T) : list[index]); }
// Token: 0x06000ED1 RID: 3793 RVA: 0x00047124 File Offset: 0x00045324 internal MServPropertyDefinition(string name, Type type, PropertyDefinitionFlags flags, object defaultValue, ProviderPropertyDefinition[] supportingProperties, GetterDelegate getterDelegate = null, SetterDelegate setterDelegate = null) : this(name, ExchangeObjectVersion.Exchange2003, type, flags, defaultValue, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, supportingProperties, getterDelegate, setterDelegate) { }
public StructValue(SetterDelegate setMethod, GetterDelegate getMethod) { SetMethod = setMethod; GetMethod = getMethod; }
// Token: 0x06000ED2 RID: 3794 RVA: 0x00047154 File Offset: 0x00045354 internal MServPropertyDefinition(string name, ExchangeObjectVersion versionAdded, Type type, PropertyDefinitionFlags flags, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints, ProviderPropertyDefinition[] supportingProperties, GetterDelegate getterDelegate, SetterDelegate setterDelegate) : base(name, versionAdded, type, flags, defaultValue, readConstraints, writeConstraints, supportingProperties, null, getterDelegate, setterDelegate) { }
private StructGetter(PropertyInfo property) : base(property) { this.getter = (GetterDelegate)Delegate.CreateDelegate(typeof(GetterDelegate), property.GetMethod, throwOnBindFailure: true); }
/// <summary> /// Initializes a new instance of <see cref="PropertyAccessor"/>. /// </summary> /// <param name="propertyInfo">The property info of the property</param> /// <param name="containingType">The containing type of the property.</param> public PropertyAccessor(PropertyInfo propertyInfo, Type containingType) { _propertyInfo = propertyInfo; _setter = CreateSetter(propertyInfo, containingType); _getter = CreateGetter(propertyInfo, containingType); }
/// <summary> /// Synchronize a value that is not directly tied to a terminal control. The value will be synchronized every time it changes. /// </summary> /// <param name="valueId">Identifier for the value</param> /// <param name="getter">Method to get the value from a script</param> /// <param name="setter">Method to set the value in a script</param> /// <param name="save">Save the value to disk</param> /// <param name="defaultValue">The default value to use. The value in the script will be set to defaultValue by ValueSync.</param> public ValueSync(string valueId, GetterDelegate getter, SetterDelegate setter, bool save = true, TValue defaultValue = default(TValue)) : base(valueId, getter, setter, save, defaultValue) { }
public static int BinsearchFromLeftIndex <T>(IList <T> list, GetterDelegate <T, int> compareResult) { return(BinsearchFromRightIndex(list, compareResult, 0, list.Count)); }
internal static ADPropertyDefinition Int32BitfieldProperty(string name, int shift, int length, ADPropertyDefinition fieldProperty, PropertyDefinitionConstraint constraint) { object defaultValue = 0; GetterDelegate getterDelegate = delegate(IPropertyBag bag) { object obj = null; if (!(bag as ADPropertyBag).TryGetField(fieldProperty, ref obj)) { return(defaultValue); } if (obj == null) { return(defaultValue); } int num = (int)obj; int num2 = (1 << length) - 1; return(num2 & num >> shift); }; SetterDelegate setterDelegate = delegate(object value, IPropertyBag bag) { int num = (int)bag[fieldProperty]; int num2 = (1 << length) - 1; int num3 = (int)value; num &= ~(num2 << shift); num |= (num3 & num2) << shift; bag[fieldProperty] = num; }; CustomFilterBuilderDelegate customFilterBuilderDelegate = delegate(SinglePropertyFilter filter) { ComparisonFilter comparisonFilter = filter as ComparisonFilter; if (comparisonFilter == null || comparisonFilter.ComparisonOperator != ComparisonOperator.Equal) { throw new ADFilterException(DirectoryStrings.ExceptionUnsupportedFilterForProperty(filter.Property.Name, filter.GetType(), typeof(ComparisonFilter))); } int num = (int)comparisonFilter.PropertyValue; int num2 = (1 << length) - 1; uint num3 = (uint)((uint)(num & num2) << shift); uint num4 = (uint)((uint)(~(uint)num & num2) << shift); QueryFilter queryFilter = new NotFilter(new BitMaskOrFilter(fieldProperty, (ulong)num4)); if (num != 0) { return(new AndFilter(new QueryFilter[] { new BitMaskAndFilter(fieldProperty, (ulong)num3), queryFilter })); } return(queryFilter); }; PropertyDefinitionConstraint[] readConstraints; if (constraint == null) { readConstraints = PropertyDefinitionConstraint.None; } else { readConstraints = new PropertyDefinitionConstraint[] { constraint }; } return(new ADPropertyDefinition(name, fieldProperty.VersionAdded, typeof(int), null, ADPropertyDefinitionFlags.Calculated, defaultValue, readConstraints, PropertyDefinitionConstraint.None, new ADPropertyDefinition[] { fieldProperty }, customFilterBuilderDelegate, getterDelegate, setterDelegate, null, null)); }
/// <summary> /// Used by type population. /// </summary> internal RuntimePhpProperty(DTypeDesc /*!*/ declaringType, GetterDelegate getterStub, SetterDelegate setterStub) : base(declaringType, PhpMemberAttributes.Public) { this._getterStub = getterStub; this._setterStub = setterStub; }
/// <summary> /// Used by type population. /// </summary> internal RuntimePhpProperty(DTypeDesc/*!*/ declaringType, GetterDelegate getterStub, SetterDelegate setterStub) : base(declaringType, PhpMemberAttributes.Public) { this._getterStub = getterStub; this._setterStub = setterStub; }