public void Should_Find_Dynamic_Member() { dynamic obj = new Dynamic(); obj.Functionality = "Test"; Assert.IsNotNull(obj.Functionality); }
public void Should_Set_Value_Dynamic_Member() { dynamic obj = new Dynamic(); obj.TestDescription = "New Test"; Assert.AreEqual("New Test", obj.TestDescription); }
public void Should_Match_Dynamic_Member_Value() { dynamic obj = new Dynamic(); obj.Functionality = "Test"; Assert.AreEqual("Test",obj.Functionality); }
private static void ClearControls(Dynamic dyn) { if (dyn.Controls.Count <= 0) return; Control tmp = dyn.Controls[0]; ActiveEvents.Instance.RemoveListener(tmp); dyn.ClearControls(); }
public void Should_Set_Value_Of_Existing_Dynamic_Member() { dynamic obj = new Dynamic(); obj.TestDescription = "New Test"; obj.TestDescription = "Same Test again"; Assert.AreEqual("Same Test again", obj.TestDescription); }
public void Should_Return_Empty_List_If_There_Is_No_Members() { dynamic propertyBag = new Dynamic(); IEnumerable<string> memberList = propertyBag.GetStaticMemberNames(); //Wrap IEnumerable in a list to simplify Assert List<string> propertyList = new List<string>(memberList); Assert.IsNotNull(propertyList); Assert.AreEqual(0, propertyList.Count); }
public void Should_Return_Empty_List() { //DynamicPerson object has a static Name Property dynamic propertyBag = new Dynamic(); IEnumerable<string> memberList = propertyBag.GetAllMemberNames(); //Wrap IEnumerable in a list to simplify Assert List<string> propertyList = new List<string>(memberList); Assert.IsNotNull(propertyList); Assert.AreEqual(0, propertyList.Count); }
public void Should_Return_List_With_Member_If_There_Is_Dynamic_Member() { //DynamicPerson object has a static Name Property dynamic propertyBag = new Dynamic(); propertyBag.Age = 27; IEnumerable<string> memberList = propertyBag.GetAllMemberNames(); //Wrap IEnumerable in a list to simplify Assert List<string> propertyList = new List<string>(memberList); Assert.IsNotNull(propertyList); Assert.AreEqual("Age", propertyList[0]); Assert.AreEqual(1, propertyList.Count); }
protected void dyn_Reload(object sender, Dynamic.ReloadEventArgs e) { // Notice that this loading mechanism uses the Ra-Brix // PluginLoader, while you if you use only Ra-Ajax should // use Page.LoadControl but due to the nature of this // website, which is a Ra-Brix application we need to // load our UserControls as ActiveModules. You would // probably use, in a pure Ra-Ajax solution, // Page.LoadControl and it would work perfectly well // none the less ... System.Web.UI.Control ctrl = PluginLoader.Instance.LoadControl(e.Key); dyn.Controls.Add(ctrl); }
//--------------------------------------------------------------------- public static void ChangeParameters(Dynamic.IParameters parameters) { B_MAX = new Ecoregions.AuxParm<int>(PlugIn.ModelCore.Ecoregions); // Fill in B_MAX array foreach (IEcoregion ecoregion in PlugIn.ModelCore.Ecoregions) { if(ActiveSiteCount[ecoregion] > 0) { int largest_B_MAX_Spp = 0; foreach (ISpecies species in PlugIn.ModelCore.Species) { largest_B_MAX_Spp = Math.Max(largest_B_MAX_Spp, SpeciesData.B_MAX_Spp[species][ecoregion]); //PlugIn.ModelCore.Log.WriteLine("B_MAX={0}. species={1}, ecoregion={2}", largest_B_MAX_Spp, species.Name, ecoregion.Name); } B_MAX[ecoregion] = largest_B_MAX_Spp; } } }
public Task(Types type, Vec3 position, DynamicType entityType) { this.type = type; this.position = position; this.entityType = entityType; this.entity = null; this.wanderRadius = float.NaN; this.wanderDistance = float.NaN; this.wanderJitter = float.NaN; }
/// <summary> /// Initializes a decimal constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(BigDecimal value) { this.value = new Decimal(value); }
private void LoadOneControl(Dynamic.ReloadEventArgs e, Dynamic dynamic, string key) { Control ctrl = PluginLoader.Instance.LoadControl(key); if (e.FirstReload) { ctrl.Init += delegate { IModule module = ctrl as IModule; if (module != null) { module.InitialLoading(_initializingParameter); } }; } dynamic.Controls.Add(ctrl); }
/// <summary> /// Initializes a boolean constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(bool value) { this.value = Boolean.FromBool(value); }
/// <summary> /// Initializes a date-time constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(DateTime value) { this.value = new Date(value); }
public virtual bool Use(Dynamic ent) { return(true); }
/// <summary> /// Initializes a big integer constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(BigInteger value) { this.value = new Long(value); }
/// <summary> /// Provides the implementation for operations that invoke an object. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as invoking an object or a delegate. /// </summary> /// <param name="binder">Provides information about the invoke operation.</param> /// <param name="args">The arguments that are passed to the object during the invoke operation. For example, for the sampleObject(100) operation, where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, <paramref name="args"/>[0] is equal to 100.</param> /// <param name="result">The result of the object invocation.</param> /// <returns> /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown. /// </returns> public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { IEnumerable <KeyValuePair <string, object> > tDict = null; object target = null; result = null; //Setup Properties as dictionary if (binder.CallInfo.ArgumentNames.Any()) { if (binder.CallInfo.ArgumentNames.Count + 1 == binder.CallInfo.ArgumentCount) { target = args.First(); tDict = binder.CallInfo.ArgumentNames .Zip(args.Skip(1), (key, value) => new { key, value }) .ToDictionary(k => k.key, v => v.value); } else { throw new RuntimeBinderException("InvokeSetAll requires first parameter to be target unamed, and all other parameters to be named."); } } else if (args.Length == 2) { target = args[0]; if (args[1] is IEnumerable <KeyValuePair <string, object> > ) { tDict = (IEnumerable <KeyValuePair <string, object> >)args[1]; } else if (args[1] is IEnumerable && args[1].GetType().GetTypeInfo().IsGenericType ) { var tEnumerableArg = (IEnumerable)args[1]; var tInterface = tEnumerableArg.GetType().GetTypeInfo().GetInterfaces().FirstOrDefault(it => it.Name == "IEnumerable`1"); if (tInterface != null) { var tParamTypes = tInterface.GetTypeInfo().GetGenericArguments(); if (tParamTypes.Length == 1 && tParamTypes[0].GetGenericTypeDefinition() == typeof(Tuple <,>)) { tDict = tEnumerableArg.Cast <dynamic>().ToDictionary(k => (string)k.Item1, v => (object)v.Item2); } } } else if (Util.IsAnonymousType(args[1])) { var keyDict = new Dictionary <string, object>(); foreach (var tProp in args[1].GetType().GetTypeInfo().GetProperties()) { keyDict[tProp.Name] = Dynamic.InvokeGet(args[1], tProp.Name); } tDict = keyDict; } } //Invoke all properties if (target != null && tDict != null) { foreach (var tPair in tDict) { Dynamic.InvokeSetChain(target, tPair.Key, tPair.Value); } result = target; return(true); } return(false); }
// Token: 0x06000062 RID: 98 RVA: 0x00004588 File Offset: 0x00003588 public static T CreateApi <T>(string name, string method) { IntPtr notMatchAddress; return((T)((object)Marshal.GetDelegateForFunctionPointer(Dynamic.GetProcAddress(Dynamic.GetInternalModuleBaseAddr(name, notMatchAddress), method), typeof(T)))); }
public void TestInvokePrivateMethodAcrossAssemblyBoundries() { var tTest = new PublicType(); Assert.That(Dynamic.InvokeMember(tTest, "PrivateMethod", 3), Is.True); }
public void TestInvokeInternalTypeMethodAcrossAssemblyBoundries() { var tTest = PublicType.InternalInstance; Assert.That(Dynamic.InvokeMember(tTest, "InternalMethod", 3), Is.True); }
public void TestInvokePrivateMethod() { var tTest = new TestWithPrivateMethod(); Assert.That(Dynamic.InvokeMember(tTest, "Test"), Is.EqualTo(3)); }
/// <summary> /// Initializes a floatting-point constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(double value) { this.value = new Float(value); }
/// <summary> /// Initializes a rational constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(Rational32 value) { this.value = new Rational(value); }
protected void sampleDyn_Reload(object sender, Dynamic.ReloadEventArgs e) { System.Web.UI.Control ctrl = PluginLoader.Instance.LoadControl(e.Key); ctrl.ID = "smpl" + e.Key.GetHashCode().ToString().Replace("-", ""); if (e.FirstReload) { ctrl.Init += delegate { IModule module = ctrl as IModule; if (module != null) { module.InitialLoading(new Node()); } }; } sampleDyn.Controls.Add(ctrl); }
public void ArgumentCasting() { var callRef = Dynamic.ConstructorCallerFromDelegate <TestClassRefCtor>(); var constructor = typeof(TestClass).GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(TestClassRefCtor).GetMethod("Invoke").GetParameters().Select(x => x.ParameterType).ToArray(), null); var callRef_0 = Dynamic.ConstructorCallerFromDelegate <TestClassRefCtor_0>(constructor); var callRef_1 = Dynamic.ConstructorCallerFromDelegate <TestClassRefCtor_1>(constructor); var callRef_2 = Dynamic.ConstructorCallerFromDelegate <TestClassRefCtor_2>(constructor); var callRef_3 = Dynamic.ConstructorCallerFromDelegate <TestClassRefCtor_3>(constructor); var callRef_4 = Dynamic.ConstructorCallerFromDelegate <TestClassRefCtor_4>(constructor); int c = 3; string d = "4"; var testVar = callRef("1", 2, ref c, ref d); Assert.AreEqual(testVar.test, 10); Assert.AreEqual(3, c); Assert.AreEqual("-1", d); c = 3; d = "4"; testVar = callRef_0("1", 2, ref c, ref d); Assert.AreEqual(testVar.test, 10); Assert.AreEqual(3, c); Assert.AreEqual("-1", d); c = 3; d = "4"; testVar = callRef_1("1", 2, ref c, ref d); Assert.AreEqual(testVar.test, 10); Assert.AreEqual(3, c); Assert.AreEqual("-1", d); object ctest = c; object dtest = d; c = 3; d = "4"; ctest = c; testVar = callRef_2("1", 2, ref ctest, ref d); c = (int)ctest; Assert.AreEqual(testVar.test, 10); Assert.AreEqual(3, c); Assert.AreEqual("-1", d); c = 3; d = "4"; dtest = d; testVar = callRef_3("1", 2, ref c, ref dtest); d = (string)dtest; Assert.AreEqual(testVar.test, 10); Assert.AreEqual(3, c); Assert.AreEqual("-1", d); c = 3; d = "4"; ctest = c; dtest = d; testVar = callRef_4("1", 2, ref ctest, ref dtest); c = (int)ctest; d = (string)dtest; Assert.AreEqual(testVar.test, 10); Assert.AreEqual(3, c); Assert.AreEqual("-1", d); }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnTick()"/>.</summary> protected override void OnTick() { base.OnTick(); if (force != 0) { foreach (MapObject obj in ObjectsInRegion) { if (obj.IsSetDeleted) { continue; } //impulse if (impulsePerSecond != 0) { PhysicsModel objPhysicsModel = obj.PhysicsModel; if (objPhysicsModel != null) { foreach (Body body in objPhysicsModel.Bodies) { if (body.Static) { continue; } EngineRandom random = World.Instance.Random; float distanceCoef = GetDistanceCoefficient(body.Position); float randomCoef = 1.0f + random.NextFloatCenter() * .1f; float v = impulsePerSecond * force * distanceCoef * randomCoef * TickDelta; Vec3 point = new Vec3( random.NextFloat() * .1f, random.NextFloat() * .1f, random.NextFloat() * .1f); body.AddForce(ForceType.GlobalAtLocalPos, TickDelta, Rotation * new Vec3(v, 0, 0), point); } } } if (InfluenceType != null || DamagePerSecond != 0) { Dynamic dynamic = obj as Dynamic; if (dynamic != null) { float distanceCoef = GetDistanceCoefficient(obj.Position); if (InfluenceType != null) { dynamic.AddInfluence(InfluenceType, InfluenceTimePerSecond * distanceCoef * TickDelta, true); } if (DamagePerSecond != 0) { dynamic.DoDamage(null, obj.Position, null, DamagePerSecond * distanceCoef * TickDelta, false); } } } } } }
/// <summary> /// Visit a method call expression /// </summary> /// <param name="expCall"></param> /// <returns></returns> protected EToken VisitMethodCallExpression(MethodCallExpression expCall) { List <EToken> args = (from p in expCall.Arguments select this.VisitExpression(p, expCall)).ToList(); EToken expCallTargetExpression; if (expCall.Object == null) { // Here we should use FullName of declaring type, but a bug in Dynamic.Linq.Core prevents // usage of full namespaces and uses shortcut aliases only. // TODO: El tipo ExpressionType.Unbox aquà es incorrecto, deberÃa ser null expCallTargetExpression = new EToken(expCall.Method?.DeclaringType?.Name, ExpressionType.Unbox, null); } else { // Métodos en objetos expCallTargetExpression = this.VisitExpression(expCall.Object, expCall); } bool canMaterializeMethodCall = args.All((i) => i.Type == ExpressionType.Constant) && (expCallTargetExpression.Type == ExpressionType.Constant || expCallTargetExpression.Type == ExpressionType.Unbox); if (canMaterializeMethodCall) { List <object> methodCallUnboxedArgs = new List <object>(); // Grab all arguments and remove them from the dictionary foreach (var arg in args) { methodCallUnboxedArgs.Add(this.PopArgument(arg.Text)); } object expCallResult; if (expCall.Object == null) { expCallResult = Dynamic.InvokeMember( InvokeContext.CreateStatic(expCall.Method?.DeclaringType), expCall.Method.Name, methodCallUnboxedArgs.ToArray()); } else { expCallResult = Dynamic.InvokeMember( this.PopArgument(expCallTargetExpression.Text), expCall.Method.Name, methodCallUnboxedArgs.ToArray()); } return(this.CheckMaterializationResult(expCallResult, expCall.Method.ReturnType)); } // If this method is LinqKit's Invoke() then we can do this ASAP because Dynamic.Linq.Core won't swallow complex method calls // We asume that the coder is looking for lazy evaluation if (expCall.Method.Name == "Invoke" && expCall.Method?.DeclaringType?.FullName.Contains("LinqKit") == true) { var targetOfInvoke = expCall.Arguments.First() as MethodCallExpression; var argumentsOfTargetInvoke = new List <object>(); foreach (var arg in targetOfInvoke.Arguments) { if (arg is ConstantExpression constant) { argumentsOfTargetInvoke.Add(constant.Value); } } // Materialize it! Currently only works with static calls var materializedTargetOfInvoke = Dynamic.InvokeMember( InvokeContext.CreateStatic(targetOfInvoke.Method?.DeclaringType), targetOfInvoke.Method.Name, argumentsOfTargetInvoke.ToArray()) as LambdaExpression; var result = this.VisitLambdaExpression(materializedTargetOfInvoke); // Replace the target source arguments for (int x = 0; x < materializedTargetOfInvoke.Parameters.Count; x++) { var expArg = materializedTargetOfInvoke.Parameters[x]; var externalArg = args[x + 1]; this.Parameters.Remove(expArg.Name); this.TempParameters.Remove(expArg.Name); result.Text = result.Text.Replace($"[{expArg.Name}]", externalArg.Text); } return(result); } return(new EToken($"{expCallTargetExpression}.{expCall.Method.Name}({args.StringJoinObject(", ")})", expCall.NodeType, expCall.Method.ReturnType)); }
public override bool Interact(Dynamic activator) { (activator as VBCharacter).TakeItem(this); return(base.Interact(activator)); }
public T GetIndexAs <T> (object o, int index) { Stats.Increment(StatsCounter.GetIndexBinderInvoked); Stats.Increment(StatsCounter.GetIndexBinder_Int_Invoked); // get accessor for value type T var accessor = o as IDynamicAccessor <T>; if (accessor != null) { return(accessor.GetIndex(index)); } // fallback on object accessor and cast it to T var untypedAccessor = o as IDynamicAccessorUntyped; if (untypedAccessor != null) { object value = untypedAccessor.GetIndex(index); // convert value to T if (value == null) { return(default(T)); } else if (value is T) { return((T)value); } else if (Dynamic.IsUndefined(value)) { return(Dynamic.GetUndefinedValue <T>()); } else { return(PlayScript.Dynamic.ConvertValue <T>(value)); } } var l = o as IList <T>; if (l != null) { return(l [index]); } var l2 = o as IList; if (l2 != null) { if (index >= l2.Count) { return(default(T)); } var ro = l2 [index]; if (ro is T) { return((T)ro); } else { return(Dynamic.ConvertValue <T>(ro)); } } var d = o as IDictionary <int, T>; if (d != null) { var ro = d[index]; if (ro is T) { return((T)ro); } else { return(Dynamic.ConvertValue <T>(ro)); } } var d2 = o as IDictionary; if (d2 != null) { var ro = d2[index]; if (ro is T) { return((T)ro); } else { return(Dynamic.ConvertValue <T>(ro)); } } return(Dynamic.GetUndefinedValue <T>()); }
private bool TryInitializeCtor(Type devType, IDictionary <string, dynamic> node, out object constructedObject) { //Find best suitable constructor, sort parameter list and create instance. Constructor parameters begin with [a-z] var constructors = FindSuitableConstructors(devType, node.Where(x => Char.IsLower(x.Key, 0)).Select(x => x.Key)); if (constructors.Count != 1) { constructedObject = null; return(false); } var ctor = constructors[0]; var sortedParams = new Dictionary <string, object>(); foreach (var ctorParam in ctor.GetParameters()) { if (typeof(IPeripheral).IsAssignableFrom(ctorParam.ParameterType) && ctorParam.ParameterType != typeof(Machine) && !ctorParam.ParameterType.IsArray) { var info = deviceList.SingleOrDefault(di => di.Name == node[ctorParam.Name]); if (info != null) { sortedParams.Add(ctorParam.Name, info.Peripheral); } else { // required peripheral is not yet created, so we need to defer the construction constructedObject = null; return(true); } } else if (node.ContainsKey(ctorParam.Name)) { var temp = GenerateObject(node[ctorParam.Name], ctorParam.ParameterType); //HACK: The reason of the following line is described at the top of this class. if (ctorParam.ParameterType.IsPrimitive || ctorParam.ParameterType.IsEnum || Nullable.GetUnderlyingType(ctorParam.ParameterType) != null || temp != null) { sortedParams.Add(ctorParam.Name, temp); } else { // required peripheral is not yet created, so we need to defer the construction constructedObject = null; return(true); } } else if (ctorParam.ParameterType == typeof(Machine)) { sortedParams.Add(ctorParam.Name, machine); } else { sortedParams.Add(ctorParam.Name, ctorParam.DefaultValue); } } var paramsArray = sortedParams.Values.ToArray(); try { constructedObject = Dynamic.InvokeConstructor(devType, paramsArray); } catch (ConstructionException) { constructedObject = null; return(false); } catch (Exception e) { throw new ConstructionException(String.Format("Could not create object of type {0}.", devType.Name), e); } return(true); }
public T GetIndexAs <T> (object o, string key) { Stats.Increment(StatsCounter.GetIndexBinderInvoked); Stats.Increment(StatsCounter.GetIndexBinder_Key_Invoked); // get accessor for value type T var accessor = o as IDynamicAccessor <T>; if (accessor != null) { if (key != mLastKey) { mLastHint = 0; } mLastKey = key; return(accessor.GetMember(key, ref mLastHint)); } // fallback on object accessor and cast it to T var untypedAccessor = o as IDynamicAccessorUntyped; if (untypedAccessor != null) { if (key != mLastKey) { mLastHint = 0; } mLastKey = key; object value = untypedAccessor.GetMember(key, ref mLastHint); if (value == null) { return(default(T)); } if (value is T) { return((T)value); } else { return(PlayScript.Dynamic.ConvertValue <T>(value)); } } // handle dictionaries var dict = o as IDictionary; if (dict != null) { Stats.Increment(StatsCounter.GetIndexBinder_Key_Dictionary_Invoked); var ro = dict[key]; if (ro is T) { return((T)ro); } else { return(Dynamic.ConvertValue <T>(ro)); } } // fallback on getmemberbinder to do the hard work Stats.Increment(StatsCounter.GetIndexBinder_Key_Property_Invoked); // create a get member binder here if (mGetMember == null) { mGetMember = new PSGetMember(key); } // get member value return(mGetMember.GetNamedMember <T>(o, key)); }
/// <summary> /// Initializes a string constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(string value) { this.value = new String(value); }
public void PermutationWithDups(string value, int numberOfPermutations) { var result = Dynamic.AllPermutationsWithDups(value); Assert.AreEqual(result.Count, numberOfPermutations); }
/// <summary> /// Initializes a complex constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(Complex64 value) { this.value = new Complex(value); }
public void WaysOfChange(int value, int expectedResult) { var result = Dynamic.MakeChange(value); Assert.AreEqual(expectedResult, result); }
protected void dynamic_LoadControls(object sender, Dynamic.ReloadEventArgs e) { Dynamic dynamic = sender as Dynamic; if (dynamic == null) return; string key = e.Key; if (key.Contains("|")) { if (e.FirstReload) { string[] keys = key.Split('|'); key = keys[keys.Length - 1]; LoadOneControl(e, dynamic, key); } else { // Need to loop through all keys... string[] keys = key.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string idxKey in keys) { LoadOneControl(e, dynamic, idxKey); } } } else { LoadOneControl(e, dynamic, key); } }
public static void ChangeParameters(Dynamic.IParameters parameters) { ANPP_MAX_Spp = parameters.MaxANPP; B_MAX_Spp = parameters.MaxBiomass; }
public Task(Types type, float wanderRadius, float wanderDistance, float wanderJitter) { this.type = type; this.position = new Vec3(float.NaN, float.NaN, float.NaN); this.entityType = null; this.entity = null; this.wanderRadius = wanderRadius; this.wanderDistance = wanderDistance; this.wanderJitter = wanderJitter; }
/// <summary> /// Starts crescendo dynamic over the range of the specified number of beats. /// </summary> /// <param name="totalBeats">Total number of beats overwhich to gradually increase volume.</param> /// <param name="endDynamic">Desired volume when crescendo is complete.</param> /// <remarks> /// Current <see cref="Dynamic"/> is the starting dynamic which should be less than <paramref name="endDynamic"/>. /// </remarks> public void SetCrescendoDynamic(int totalBeats, Dynamic endDynamic) { // TODO: implement crescendo dynamic }
public Task(Types type, Dynamic entity) { this.type = type; this.position = new Vec3(float.NaN, float.NaN, float.NaN); this.entityType = null; this.entity = entity; this.wanderRadius = float.NaN; this.wanderDistance = float.NaN; this.wanderJitter = float.NaN; }
public override int Read(FileStream stream) { dynamics.Empty(); int bytesRead = base.Read(stream); uint offset = 0; Dynamic currDynamic; while (offset < bytesRead) { currDynamic = new Dynamic(); currDynamic.Tag = (DynamicTag)ByteConverter.ToUInt32(data, offset + 0); currDynamic.Val_Ptr = ByteConverter.ToUInt32(data, offset + 4); dynamics.Add(currDynamic); offset += header.EntrySize; } return dynamics.Count; }
public static void AddFields(Dynamic.SerializableDictionary<string, Field> fields, TCM.Fields.ItemFields tcmItemFields, int linkLevels, bool resolveWidthAndHeight, Dynamic.MergeAction mergeAction, BuildManager manager) { foreach (TCM.Fields.ItemField tcmItemField in tcmItemFields) { try { if (fields.ContainsKey(tcmItemField.Name)) { if (mergeAction.Equals(Dynamic.MergeAction.Skip)) { continue; } Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight); if (mergeAction.Equals(Dynamic.MergeAction.Replace)) { fields.Remove(f.Name); fields.Add(f.Name, f); } else { Field existingField = fields[f.Name]; switch (existingField.FieldType) { case FieldType.ComponentLink: case FieldType.MultiMediaLink: foreach (Component linkedComponent in f.LinkedComponentValues) { bool valueExists = false; foreach (Component existingLinkedComponent in existingField.LinkedComponentValues) { if (linkedComponent.Id.Equals(existingLinkedComponent.Id)) { // this value already exists valueExists = true; break; } } if (!valueExists) { existingField.LinkedComponentValues.Add(linkedComponent); } } break; case FieldType.Date: foreach (DateTime dateTime in f.DateTimeValues) { bool valueExists = false; foreach (DateTime existingDateTime in existingField.DateTimeValues) { if (dateTime.Equals(existingDateTime)) { // this value already exists valueExists = true; break; } } if (!valueExists) { existingField.DateTimeValues.Add(dateTime); } } break; case FieldType.Number: foreach (int nr in f.NumericValues) { bool valueExists = false; foreach (int existingNr in existingField.NumericValues) { if (nr == existingNr) { // this value already exists valueExists = true; break; } } if (!valueExists) { existingField.NumericValues.Add(nr); } } break; default: foreach (string val in f.Values) { bool valueExists = false; foreach (string existingVal in existingField.Values) { if (val.Equals(existingVal)) { // this value already exists valueExists = true; break; } } if (!valueExists) { existingField.Values.Add(val); } } break; } } } else { Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight); fields.Add(f.Name, f); } } catch (FieldHasNoValueException) { // fail silently, field is not added to the list } catch (FieldTypeNotDefinedException) { // fail silently, field is not added to the list } } }
bool GetTurnToPosition(out Vec3 turnToPosition) { if (Instance != this) { Log.Fatal("PlayerIntellect: GetTurnToPosition: Instance != this."); } turnToPosition = Vec3.Zero; if (ControlledObject == null) { return(false); } //CutSceneManager specific if (CutSceneManager.Instance != null && CutSceneManager.Instance.CutSceneEnable) { return(false); } Vec3 from; Vec3 dir; if (!fpsCamera) { from = ControlledObject.Position + new Vec3(0, 0, tpsCameraCenterOffset); dir = lookDirection.GetVector(); } else { from = ControlledObject.Position + ControlledObject.Type.FPSCameraOffset * ControlledObject.Rotation; dir = lookDirection.GetVector(); } //invalid ray if (dir == Vec3.Zero || float.IsNaN(from.X) || float.IsNaN(dir.X)) { return(false); } float distance = 1000.0f; turnToPosition = from + dir * distance; RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( new Ray(from, dir * distance), (int)ContactGroup.CastAll); foreach (RayCastResult result in piercingResult) { WaterPlane waterPlane = WaterPlane.GetWaterPlaneByBody(result.Shape.Body); if (waterPlane == null && result.Shape.ContactGroup == (int)ContactGroup.NoContact) { continue; } MapObject obj = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (obj == ControlledObject) { continue; } if (waterPlane != null) { //ignore water from inside if (result.Shape.Body.GetGlobalBounds().IsContainsPoint(from)) { continue; } } Dynamic dynamic = obj as Dynamic; if (dynamic != null) { if (dynamic.GetParentUnitHavingIntellect() == ControlledObject) { continue; } } turnToPosition = result.Position; break; } return(true); }
protected void dynamic_LoadControls(object sender, Dynamic.ReloadEventArgs e) { Dynamic dynamic = sender as Dynamic; if (dynamic == null) return; Control ctrl = PluginLoader.Instance.LoadControl(e.Key); dynamic.Controls.Add(ctrl); }
public static int insertDynamic(Dynamic Dyna) { return(IDynamic.insertDynamic(Dyna)); }
public void Should_Get_Dynamic_Member_Value() { dynamic obj = new Dynamic(); var func = obj.Functionality; }
private void RegisterInParents(DeviceInfo device, IDictionary <string, IPeripheral> parents) { foreach (var parentName in device.Connections.Keys) { //TODO: nongeneric version var parent = parents.Single(x => x.Key == parentName).Value; var connections = device.Connections[parentName]; var ifaces = parent.GetType().GetInterfaces().Where(x => IsSpecializationOfRawGeneric(typeof(IPeripheralRegister <,>), x)).ToList(); var ifaceCandidates = ifaces.Where(x => x.GetGenericArguments()[0].IsAssignableFrom(device.Peripheral.GetType())).ToList(); foreach (var connection in connections) { IRegistrationPoint regPoint = null; Type formalType = null; if (connection.ContainsKey(TYPE_NODE)) { var name = (string)connection[TYPE_NODE]; formalType = GetDeviceTypeFromName(name); } Type foundIface = null; foreach (var iface in ifaceCandidates) { var iRegPoint = iface.GetGenericArguments()[1]; Type objType; if (formalType != null && iRegPoint.IsAssignableFrom(formalType)) { objType = formalType; } else { objType = iRegPoint; } object regPointObject; if (!TryInitializeCtor(objType, connection, out regPointObject)) { if (connection.Keys.Any() || !TryHandleSingleton(objType, out regPointObject)) { continue; } } regPoint = (IRegistrationPoint)regPointObject; foundIface = iface; break; //is a construable type } if (foundIface == null) { // let's try attachment through the AttachTo mechanism FailDevice(device.Name, "connection to " + parentName); } else { Dynamic.InvokeMemberAction(parent, "Register", new object[] { device.Peripheral, regPoint } ); } } } }
public void ThreeStepsTests(int n, int expected) { var result = Dynamic.ThreeSteps(n); Assert.AreEqual(expected, result); }
/// <summary> /// Initializes an integer constant. /// </summary> /// <param name="value">The constant's value</param> public Constant(int value) { this.value = new Integer(value); }
public void BooleanEvalutation(string s, bool result, int expected) { var count = Dynamic.BooleanEvalutation(s, result); Assert.AreEqual(expected, count); }
public static string GetPythonName(object o) { var cls = Dynamic.InvokeGet(o, ".class"); return(cls.__name__); }
/// <summary> /// Starts diminuendo dynamic over the range of the specified number of beats. /// </summary> /// <param name="totalBeats">Total number of beats overwhich to gradually decrease volume.</param> /// <param name="endDynamic">Desired volume when diminuendo is complete.</param> /// <remarks> /// Current <see cref="Dynamic"/> is the starting dynamic which should be greater than <paramref name="endDynamic"/>. /// </remarks> public void SetDiminuendoDynamic(int totalBeats, Dynamic endDynamic) { // TODO: implement diminuendo dynamic }
public void SetCodeLambda(Dynamic.Proxy.Lambda.ICodeLambda codeLambda) { }