internal ReflectionProperty(PropertyInfo property) { this.PropertyInfo = property; Attributes = this.PropertyInfo.GetCustomAttributes(true).OfType <Attribute>().ToList(); Name = this.PropertyInfo.Name; PropertyType = PropertyInfo.PropertyType; if (property.PropertyType.GetTypeInfo().IsGenericType) { this.GenericTypeDefinition = property.PropertyType.GetGenericTypeDefinition(); this.GenericTypeArguments = property.PropertyType.GetGenericArguments(); } var method = this.PropertyInfo.GetGetMethod() ?? this.PropertyInfo.GetGetMethod(true); if (method != null) { HasGet = true; getHandler = DelegateFactory.CreateGet(property); } method = this.PropertyInfo.GetSetMethod() ?? this.PropertyInfo.GetSetMethod(true); if (method != null) { HasSet = true; setHandler = DelegateFactory.CreateSet(property); } }
public AccessorBase(Type baseType, FieldInfo field, Processor <TField> processor) { this.processor = processor; var targetExp = Expression.Parameter(typeof(object), "target"); var valueType = typeof(TField); var fieldType = field.FieldType; //if (fieldType.IsArray) // fieldType = fieldType.GetElementType(); var valueExp = Expression.Parameter(valueType, "value"); var valueConvExp = (Expression)valueExp; if (fieldType != valueType) { valueConvExp = Expression.Convert(valueExp, fieldType); } var conversion = Expression.Convert(targetExp, baseType); var fieldExp = Expression.Field(conversion, field); var assignExp = Expression.Assign(fieldExp, valueConvExp); var fieldConvExp = (Expression)fieldExp; if (fieldType != valueType) { fieldConvExp = Expression.Convert(fieldExp, valueType); } getter = Expression.Lambda <GetDelegate <TField> >(fieldConvExp, targetExp).Compile(); setter = Expression.Lambda <SetDelegate <TField> >(assignExp, targetExp, valueExp).Compile(); }
/// <summary> /// Helper to set and update key collections. /// </summary> /// <param name="context">Application context object</param> /// <param name="args">Root node for updating collection</param> /// <param name="functor">Callback supplied by caller, that will be invoked once for each "key", with whatever value method /// finds for specified key</param> /// <param name="exclusionArgs">Contains a list of node names that are excluded when looking for the "source" for values /// for keys specified</param> public static void Set( ApplicationContext context, Node args, SetDelegate functor, params string [] exclusionArgs) { // Retrieving source. var source = Source(context, args, exclusionArgs); // Iterating through each result of expression. foreach (var idxKey in Iterate <string> (context, args)) { // Making sure collection key is not "hidden" key if (!args.Name.StartsWithEx(".") && (idxKey.StartsWithEx("_") || idxKey.StartsWithEx("."))) { throw new LambdaException( string.Format("Tried to update protected key in [{0}], key name was '{1}' ", args.Name, idxKey), args, context); } // Checking exclusion arguments. if (exclusionArgs.Any(ix => ix == idxKey)) { continue; } // Checking if this is deletion of item, or setting item, before invoking functor callback functor(idxKey, source); } }
public void myCallback(WindData wd) { wsqData = wd; //System.Console.WriteLine(((double[])wd.data)[0]); sd = new SetDelegate(SetCb); this.cbRequest.Invoke(sd); this.cbFuncList.Invoke(sd); this.dataGridView1.Invoke(sd); }
/// <summary> /// Initializes a new instance of the <see cref="CustomValueContainer"/> class. /// </summary> /// <param name="valueType">Type of the value.</param> /// <param name="getter">The value getter.</param> /// <param name="setter">The value setter.</param> public CustomValueContainer(Type valueType, GetDelegate getter, SetDelegate setter) : base(null, valueType) { if (getter == null || setter == null) { throw new ArgumentNullException(); } _getter = getter; _setter = setter; }
/// <summary> /// Initializes a new instance of the <see cref="CustomValueContainer"/> class. /// </summary> /// <param name="valueType">Type of the value.</param> /// <param name="getter">The value getter.</param> /// <param name="setter">The value setter.</param> /// <param name="attributes">The custom type attributes used to override the value editor logic or appearance (eg. instance of <see cref="LimitAttribute"/>).</param> public CustomValueContainer(ScriptType valueType, GetDelegate getter, SetDelegate setter, object[] attributes = null) : base(ScriptMemberInfo.Null, valueType) { if (getter == null || setter == null) { throw new ArgumentNullException(); } _getter = getter; _setter = setter; _attributes = attributes; }
public void Set(C c) { if (_c != null && _c.InvokeRequired) { SetDelegate <C> d = new SetDelegate <C>(Set); _f.Invoke(d, c); } else { _c = c; } }
public void myCallback(WindData wd) { if (wd.errorCode == 0) { wsqData = wd; sd = new SetDelegate(drawLines); sd1 = new SetDelegate(doBreakThrough); sd2 = new SetDelegate(updatePrice); this.pictureBox1.Invoke(sd); this.richTextBox1.Invoke(sd1); this.label6.Invoke(sd2); } }
/// <summary>新食物上色</summary> private void NewFood(string Text) { if (this.InvokeRequired) { SetDelegate d = new SetDelegate(NewFood); this.Invoke(d, Text); } else { Button b = (Button)flowLayoutPanel1.Controls[Text]; b.BackColor = Color.Yellow; } }
/// <summary>新蛇头变色</summary> private void ChangeColor(string Text) { if (this.InvokeRequired) { SetDelegate d = new SetDelegate(ChangeColor); this.Invoke(d, Text); } else { Button b = (Button)flowLayoutPanel1.Controls[Text]; b.BackColor = Color.Green; } }
IEnumerator WinAnimation(bool guardsOrSpies) { SetActive(true); _winText.gameObject.SetActive(true); _starSprite.gameObject.SetActive(true); RectTransform winnerTrans = _guardSprite.rectTransform; if (guardsOrSpies) { _guardSprite.gameObject.SetActive(true); _spySprite.gameObject.SetActive(false); _winText.text = "Guards\nWin!"; } else { winnerTrans = _spySprite.rectTransform; _spySprite.gameObject.SetActive(true); _guardSprite.gameObject.SetActive(false); _winText.text = "Spies\nWin!"; } StartCoroutine(FadeOutBackground(1)); // Initialize positions Vector2 initialPos = winnerTrans.localPosition; RectTransform starTrans = _starSprite.rectTransform; Vector2 starSize = starTrans.sizeDelta; starTrans.sizeDelta = new Vector2(0, 0); winnerTrans.localPosition = new Vector2(0, Screen.height / 2 + winnerTrans.sizeDelta.y / 2.0f); // Smoothly animate drop down for winnerTrans GetDelegate <Vector2> getter = () => { return(winnerTrans.localPosition); }; SetDelegate <Vector2> setter = v => { winnerTrans.localPosition = v; }; yield return(StartCoroutine(SmoothVector2Lerp(getter, setter, winnerTrans.localPosition, initialPos, 2.0f))); // Spin the star simultaneously StartCoroutine(SpinStar(20.0f)); // Smoothly animate star reveal getter = () => { return(starTrans.sizeDelta); }; setter = v => { starTrans.sizeDelta = v; }; yield return(StartCoroutine(SmoothVector2Lerp(getter, setter, starTrans.sizeDelta, starSize, 4.0f))); // Reveal Win Text yield return(StartCoroutine(RevealWinText(1))); StartCoroutine(LeaveRoom()); yield return(null); }
IEnumerator SmoothVector2Lerp(GetDelegate <Vector2> getter, SetDelegate <Vector2> setter, Vector2 initial, Vector2 final, float speed) { setter(initial); Vector2 yVelocity = final - initial; float magnitude = yVelocity.magnitude; yVelocity = yVelocity.normalized; Vector2 overShotFinal = final + (yVelocity * magnitude * 0.1f); while (true) { Vector2 newVec = Vector2.Lerp(getter(), overShotFinal, Time.deltaTime * speed); Vector2 checkDireciton = (final - newVec).normalized; if (checkDireciton != yVelocity) { newVec = final; setter(newVec); break; } setter(newVec); yield return(new WaitForEndOfFrame()); } yield return(null); }
public SetPropertyCommand(SetDelegate del, bool value) { _del = del; _value = value; }
/// <param name="getter"></param> /// <param name="setter"> if null, Variable is readonly. </param> public VariableFunc(GetDelegate getter, SetDelegate setter) { get = getter; set = setter; Readonly = set == null; }
/// <param name="getter"></param> /// <param name="setter"> if null, Variable is readonly. </param> public VariableFunc(GetDelegate getter, SetDelegate setter) { get = getter; set = setter; Readonly = set == null; }
public void myCallback(WindData wd) { if (wd.errorCode == 0) { wsqData = wd; sd = new SetDelegate(drawLines); sd1 = new SetDelegate(doBreakThrough); sd2 = new SetDelegate(updatePrice); this.pictureBox1.Invoke(sd); this.richTextBox1.Invoke(sd1); this.label6.Invoke(sd2); } }
/// <summary> /// Initializes a new instance of the <see cref="CustomValueContainer"/> class. /// </summary> /// <param name="valueType">Type of the value.</param> /// <param name="initialValue">The initial value.</param> /// <param name="getter">The value getter.</param> /// <param name="setter">The value setter.</param> /// <param name="attributes">The custom type attributes used to override the value editor logic or appearance (eg. instance of <see cref="LimitAttribute"/>).</param> public CustomValueContainer(ScriptType valueType, object initialValue, GetDelegate getter, SetDelegate setter, object[] attributes = null) : this(valueType, getter, setter, attributes) { Add(initialValue); }
/// <summary> /// Initializes a new instance of the <see cref="CustomValueContainer"/> class. /// </summary> /// <param name="valueType">Type of the value.</param> /// <param name="initialValue">The initial value.</param> /// <param name="getter">The value getter.</param> /// <param name="setter">The value setter.</param> public CustomValueContainer(Type valueType, object initialValue, GetDelegate getter, SetDelegate setter) : this(valueType, getter, setter) { Add(initialValue); }
public void Setup() { _instance = new T(); var setter = ModelAccess <T> .GetSetter(_memberExpression); _setBool = setter.GetDelegate <bool>(); _setBoolNullable = setter.GetDelegate <bool?>(); _setChar = setter.GetDelegate <char>(); _setCharNullable = setter.GetDelegate <char?>(); _setSByte = setter.GetDelegate <sbyte>(); _setSByteNullable = setter.GetDelegate <sbyte?>(); _setByte = setter.GetDelegate <byte>(); _setByteNullable = setter.GetDelegate <byte?>(); _setShort = setter.GetDelegate <short>(); _setShortNullable = setter.GetDelegate <short?>(); _setUShort = setter.GetDelegate <ushort>(); _setUShortNullable = setter.GetDelegate <ushort?>(); _setInt = setter.GetDelegate <int>(); _setIntNullable = setter.GetDelegate <int?>(); _setUInt = setter.GetDelegate <uint>(); _setUIntNullable = setter.GetDelegate <uint?>(); _setLong = setter.GetDelegate <long>(); _setLongNullable = setter.GetDelegate <long?>(); _setULong = setter.GetDelegate <ulong>(); _setULongNullable = setter.GetDelegate <ulong?>(); _setFloat = setter.GetDelegate <float>(); _setFloatNullable = setter.GetDelegate <float?>(); _setDouble = setter.GetDelegate <double>(); _setDoubleNullable = setter.GetDelegate <double?>(); _setDecimal = setter.GetDelegate <decimal>(); _setDecimalNullable = setter.GetDelegate <decimal?>(); _setDateTime = setter.GetDelegate <DateTime>(); _setDateTimeNullable = setter.GetDelegate <DateTime?>(); _setObject = setter.GetDelegate <object>(); _setString = setter.GetDelegate <string>(); _setEnum = setter.GetDelegate <TestEnum>(); _setEnumNullable = setter.GetDelegate <TestEnum?>(); _testValueBool = ConvertSafe <P, bool>(_testValue); _testValueBoolNullable = ConvertSafe <P, bool?>(_testValue); _testValueChar = ConvertSafe <P, char>(_testValue); _testValueCharNullable = ConvertSafe <P, char?>(_testValue); _testValueSByte = ConvertSafe <P, sbyte>(_testValue); _testValueSByteNullable = ConvertSafe <P, sbyte?>(_testValue); _testValueByte = ConvertSafe <P, byte>(_testValue); _testValueByteNullable = ConvertSafe <P, byte?>(_testValue); _testValueShort = ConvertSafe <P, short>(_testValue); _testValueShortNullable = ConvertSafe <P, short?>(_testValue); _testValueUShort = ConvertSafe <P, ushort>(_testValue); _testValueUShortNullable = ConvertSafe <P, ushort?>(_testValue); _testValueInt = ConvertSafe <P, int>(_testValue); _testValueIntNullable = ConvertSafe <P, int?>(_testValue); _testValueUInt = ConvertSafe <P, uint>(_testValue); _testValueUIntNullable = ConvertSafe <P, uint?>(_testValue); _testValueLong = ConvertSafe <P, long>(_testValue); _testValueLongNullable = ConvertSafe <P, long?>(_testValue); _testValueULong = ConvertSafe <P, ulong>(_testValue); _testValueULongNullable = ConvertSafe <P, ulong?>(_testValue); _testValueFloat = ConvertSafe <P, float>(_testValue); _testValueFloatNullable = ConvertSafe <P, float?>(_testValue); _testValueDouble = ConvertSafe <P, double>(_testValue); _testValueDoubleNullable = ConvertSafe <P, double?>(_testValue); _testValueDecimal = ConvertSafe <P, decimal>(_testValue); _testValueDecimalNullable = ConvertSafe <P, decimal?>(_testValue); _testValueDateTime = ConvertSafe <P, DateTime>(_testValue); _testValueDateTimeNullable = ConvertSafe <P, DateTime?>(_testValue); _testValueObject = ConvertSafe <P, object>(_testValue); _testValueString = ConvertSafe <P, string>(_testValue); _testValueEnum = ConvertSafe <P, TestEnum>(_testValue); _testValueEnumNullable = ConvertSafe <P, TestEnum?>(_testValue); _provider = CultureInfo.InvariantCulture; }
public ByRefFieldWriter(DataSerializer dataSerializer, SetDelegate set, GetDelegate get) { _set = set; _get = get; _dataSerializer = dataSerializer; }
/// <summary> /// constructor. /// </summary> public Property(GetDelegate <TV> get, SetDelegate <TV> set) { _get = get; _set = set; }