internal void VerifyStore (Reflect.Type type) { Uri.Locator created = this.CreatedName(type); Uri.Locator resource = this.CorrectName(type); this.Factory.Store(this.Factory.Create(type), created); this.Factory.VerifyResource(created, resource, "Serializing test \"{0}\" failed.", this.Factory.Name(type)); }
public ISerializer Find(Reflect.Type type, bool deserialize) { ISerializer result = null; foreach (ISerializer serializer in this.serializers) if ((result = serializer.Find(type, deserialize)).NotNull()) break; return result; }
public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator) { Data.Branch result = new Data.Branch(data, type); foreach (Reflect.Field field in data.GetFields()) { Uri.Locator l = locator.Copy(); string name = field.Name.Convert(Casing.Camel, storage.Casing); l.Fragment = (l.Fragment.NotEmpty() ? l.Fragment + "." : "") + name; result.Nodes.Add(storage.Serialize(field.Type, field.Data, l).UpdateName(name)); } return result; }
object Create(byte[] value, Reflect.Type type) { object result = null; switch ((Reflect.Type)Enum.GetUnderlyingType(type)) { case "sbyte": if (value.Length == 1) result = Enum.ToObject(type, (sbyte)value[0]); break; case "byte": if (value.Length == 1) result = Enum.ToObject(type, value[0]); break; case "short": if (value.Length == 2) result = Enum.ToObject(type, BitConverter.ToInt32(value, 0)); break; case "ushort": if (value.Length == 2) result = Enum.ToObject(type, BitConverter.ToUInt32(value, 0)); break; case "int": if (value.Length == 4) result = Enum.ToObject(type, BitConverter.ToInt32(value, 0)); break; case "uint": if (value.Length == 4) result = Enum.ToObject(type, BitConverter.ToUInt32(value, 0)); break; case "long": if (value.Length == 8) result = Enum.ToObject(type, BitConverter.ToInt64(value, 0)); break; case "ulong": if (value.Length == 8) result = Enum.ToObject(type, BitConverter.ToUInt64(value, 0)); break; } return result; }
public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator) { Data.Collection result = new Data.Collection(data, type); Reflect.Type elementType = this.GetElementType(type); int c = 0; foreach (object child in data as System.Collections.IEnumerable) { Uri.Locator l = null; if (locator.NotNull()) { l = locator.Copy(); l.Fragment = (l.Fragment.NotEmpty() ? l.Fragment + "/" : "") + (c++).ToString(); } result.Nodes.Add(storage.Serialize(elementType, child, l)); } return result; }
public ISerializer Find(Reflect.Type type, bool deserialize) { ISerializer result = null; if (type.NotNull()) { if (this.cache[deserialize ? 1 : 0].Contains(type)) result = this.cache[deserialize ? 1 : 0][type]; else { MethodAttribute[] attributes; if (type.Category != Reflect.TypeCategory.Primitive && (attributes = type.GetAttributes<MethodAttribute>()).Length == 1) result = attributes[0].Serializer; else result = serializer.Find(type, deserialize); if (result.NotNull()) this.cache[deserialize ? 1 : 0][type] = result; } } return result; }
/// <summary> /// Indicates that the specified property belongs /// to the business object type. /// </summary> /// <typeparam name="P">Type of property</typeparam> /// <param name="propertyLambdaExpression">Property Expression</param> /// <param name="friendlyName">Friendly description for a property to be used in databinding</param> /// <returns></returns> protected static PropertyInfo <P> RegisterProperty <P>(Expression <Func <T, object> > propertyLambdaExpression, string friendlyName) { PropertyInfo reflectedPropertyInfo = Reflect <T> .GetProperty(propertyLambdaExpression); return(RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create <P>(typeof(T), reflectedPropertyInfo.Name, friendlyName))); }
protected abstract bool Found(Reflect.Type type, bool deserialize);
protected abstract Reflect.Type GetElementType(Reflect.Type type);
protected override object Create(Reflect.Type type, Reflect.Type elementType, int count) { return null; }
public ISerializer Find(Reflect.Type type, bool deserialize) { return type.Category == Reflect.TypeCategory.Class ? this : null; }
/// <summary> /// Configures an explicit value for a property. /// /// </summary> /// <typeparam name="TLimit">Registration limit type.</typeparam> /// <typeparam name="TStyle">Registration style.</typeparam> /// <typeparam name="TReflectionActivatorData">Activator data type.</typeparam> /// <typeparam name="TValue">The type of the property being set</typeparam> /// <param name="registration">Registration to set property on.</param> /// <param name="property">An expression referencing a property on the target type.</param> /// <param name="propertyValue">Value to supply to the property.</param> /// <returns> /// A registration builder allowing further configuration of the component. /// </returns> public static IRegistrationBuilder <TLimit, TReflectionActivatorData, TStyle> WithProperty <TLimit, TReflectionActivatorData, TStyle, TValue>( this IRegistrationBuilder <TLimit, TReflectionActivatorData, TStyle> registration, Expression <Func <TLimit, TValue> > property, TValue propertyValue) where TReflectionActivatorData : ReflectionActivatorData { return(registration.WithProperty(Reflect.PropertyOf(property).Name, propertyValue)); }
private object[] GetAttributes <T>(Expression <Func <Email, object> > member) { return(Reflect <Email> .GetProperty(member).GetCustomAttributes(typeof(T), false)); }
TestCorrelationProperty GetCorrelationProperty(Expression <Func <SagaDataWithVariousCorrelationProperties, object> > expression) { return(new TestCorrelationProperty(Reflect.Path(expression), typeof(SagaDataWithVariousCorrelationProperties))); }
async Task <ISagaData> Find(object value, Expression <Func <SagaDataWithVariousCorrelationProperties, object> > expression) { return(await _sagaStorage.Find(typeof(SagaDataWithVariousCorrelationProperties), Reflect.Path(expression), value)); }
protected string NameOf <TValue>(Expression <Func <TCmdlet, TValue> > propertyAccessor) { return(Reflect.PropertyOf(propertyAccessor).Name); }
public bool CanBuildFrom(Type type) { return(Reflect.HasAttribute(type, NUnitFramework.SetUpFixtureAttribute, false)); }
public void NameShouldReturnNameByMethodAndProperty() { Assert.AreEqual("Title", Reflect.Name <Foo>(x => x.GetBoo().Title)); }
int mrt3(int color, Reflect r, int x, int y) { double procent = r.size - FHypot(r.xp - x, r.yp - y); procent /= (r.size * 0.12); if (procent > 0) { if (procent > 1) procent = 1 - (procent * 0.12); color = fixpix(color, procent, r.ccol); } return color; }
protected override IEnumerable PerformWork() { InitializeSetUpAndTearDownCommands(); if (UnityTestExecutionContext.CurrentContext != null && m_DontRunRestoringResult && EditModeTestCallbacks.RestoringTestContext != null) { EditModeTestCallbacks.RestoringTestContext(); } if (!CheckForCancellation()) if (Test.RunState == RunState.Explicit && !_childFilter.IsExplicitMatch(Test)) SkipFixture(ResultState.Explicit, GetSkipReason(), null); else switch (Test.RunState) { default: case RunState.Runnable: case RunState.Explicit: Result.SetResult(ResultState.Success); CreateChildWorkItems(); if (Children.Count > 0) { if (!m_DontRunRestoringResult) { //This is needed to give the editor a chance to go out of playmode if needed before creating objects. //If we do not, the objects could be automatically destroyed when exiting playmode and could result in errors later on yield return null; PerformOneTimeSetUp(); if (_unitySetupMethods != null) foreach (var method in _unitySetupMethods) yield return Reflect.InvokeMethod(method, Context.TestObject); if (_asyncSetupMethods != null) foreach (var method in _asyncSetupMethods) yield return WaitForTask(Reflect.InvokeMethod(method, Context.TestObject) as Task); } if (!CheckForCancellation()) { switch (Result.ResultState.Status) { case TestStatus.Passed: foreach (var child in RunChildren()) { if (CheckForCancellation()) { yield break; } yield return child; } break; case TestStatus.Skipped: case TestStatus.Inconclusive: case TestStatus.Failed: SkipChildren(_suite, Result.ResultState.WithSite(FailureSite.Parent), "OneTimeSetUp: " + Result.Message); break; } } if (Context.ExecutionStatus != TestExecutionStatus.AbortRequested && !m_DontRunRestoringResult) { if (_asyncTeardownMethods != null) foreach (var method in _asyncTeardownMethods) yield return WaitForTask(Reflect.InvokeMethod(method, Context.TestObject) as Task); if (_unityTeardownMethods != null) foreach (var method in _unityTeardownMethods) yield return Reflect.InvokeMethod(method, Context.TestObject); PerformOneTimeTearDown(); } } break; case RunState.Skipped: SkipFixture(ResultState.Skipped, GetSkipReason(), null); break; case RunState.Ignored: SkipFixture(ResultState.Ignored, GetSkipReason(), null); break; case RunState.NotRunnable: SkipFixture(ResultState.NotRunnable, GetSkipReason(), GetProviderStackTrace()); break; } if (!ResultedInDomainReload) { WorkItemComplete(); } }
public ISerializer Find(Reflect.Type type, bool deserialize) { return this.GetFromStringCast(type).NotNull() && this.GetToStringCast(type).NotNull() ? this : null; }
public SagaDataElementNameConvention() { RevisionMemberName = Reflect.Path <ISagaData>(d => d.Revision); }
public Node DefaultType(Reflect.Type type) { this.OriginalType = this.Type; if (type.Name == "System.Nullable") { if (this.Type.IsNull()) this.Type = type.Arguments[0]; else if (!this.Type.Implements(type.Arguments[0])) this.Type = type; } else if (this.Type.IsNull() || type != typeof(object) && !this.Type.Implements(type)) this.Type = type; return this; }
/// <summary> /// Builds a single NUnitTestMethod, either as a child of the fixture /// or as one of a set of test cases under a ParameterizedTestMethodSuite. /// </summary> /// <param name="method">The MethodInfo from which to construct the TestMethod</param> /// <param name="parms">The ParameterSet to be used, or null</param> /// <returns></returns> public static NUnitTestMethod BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms) { #if CLR_2_0 || CLR_4_0 NUnitTestMethod testMethod = Reflect.IsAsyncMethod(method) ? new NUnitAsyncTestMethod(method) : new NUnitTestMethod(method); #else NUnitTestMethod testMethod = new NUnitTestMethod(method); #endif string prefix = method.ReflectedType.FullName; if (parentSuite != null) { prefix = parentSuite.TestName.FullName; testMethod.TestName.FullName = prefix + "." + testMethod.TestName.Name; } if (CheckTestMethodSignature(testMethod, parms)) { if (parms == null) { NUnitFramework.ApplyCommonAttributes(method, testMethod); } NUnitFramework.ApplyExpectedExceptionAttribute(method, testMethod); } if (parms != null) { // NOTE: After the call to CheckTestMethodSignature, the Method // property of testMethod may no longer be the same as the // original MethodInfo, so we reassign it here. method = testMethod.Method; if (parms.TestName != null) { testMethod.TestName.Name = parms.TestName; testMethod.TestName.FullName = prefix + "." + parms.TestName; } else if (parms.OriginalArguments != null) { string name = MethodHelper.GetDisplayName(method, parms.OriginalArguments); testMethod.TestName.Name = name; testMethod.TestName.FullName = prefix + "." + name; } if (parms.Ignored) { testMethod.RunState = RunState.Ignored; testMethod.IgnoreReason = parms.IgnoreReason; } else if (parms.Explicit) { testMethod.RunState = RunState.Explicit; } if (parms.ExpectedExceptionName != null) { testMethod.exceptionProcessor = new ExpectedExceptionProcessor(testMethod, parms); } foreach (string key in parms.Properties.Keys) { testMethod.Properties[key] = parms.Properties[key]; } // Description is stored in parms.Properties if (parms.Description != null) { testMethod.Description = parms.Description; } } //if (testMethod.BuilderException != null && testMethod.RunState != RunState.NotRunnable) //{ // testMethod.RunState = RunState.NotRunnable; // testMethod.IgnoreReason = testMethod.BuilderException.Message; //} if (parentSuite != null) { if (parentSuite.RunState == RunState.NotRunnable && testMethod.RunState != RunState.NotRunnable) { testMethod.RunState = RunState.NotRunnable; testMethod.IgnoreReason = parentSuite.IgnoreReason; } if (parentSuite.RunState == RunState.Ignored && testMethod.RunState != RunState.Ignored && testMethod.RunState != RunState.NotRunnable) { testMethod.RunState = RunState.Ignored; testMethod.IgnoreReason = parentSuite.IgnoreReason; } } return(testMethod); }
protected override Reflect.Type GetElementType(Reflect.Type type) { return this.GetInterface(type).GetGenericArguments()[0]; }
/// <summary> /// Helper method that checks the signature of a TestMethod and /// any supplied parameters to determine if the test is valid. /// /// Currently, NUnitTestMethods are required to be public, /// non-abstract methods, either static or instance, /// returning void. They may take arguments but the values must /// be provided or the TestMethod is not considered runnable. /// /// Methods not meeting these criteria will be marked as /// non-runnable and the method will return false in that case. /// </summary> /// <param name="testMethod">The TestMethod to be checked. If it /// is found to be non-runnable, it will be modified.</param> /// <param name="parms">Parameters to be used for this test, or null</param> /// <returns>True if the method signature is valid, false if not</returns> private static bool CheckTestMethodSignature(TestMethod testMethod, ParameterSet parms) { if (testMethod.Method.IsAbstract) { testMethod.RunState = RunState.NotRunnable; testMethod.IgnoreReason = "Method is abstract"; return(false); } if (!testMethod.Method.IsPublic) { testMethod.RunState = RunState.NotRunnable; testMethod.IgnoreReason = "Method is not public"; return(false); } ParameterInfo[] parameters = testMethod.Method.GetParameters(); int argsNeeded = parameters.Length; object[] arglist = null; int argsProvided = 0; if (parms != null) { testMethod.arguments = parms.Arguments; testMethod.hasExpectedResult = parms.HasExpectedResult; if (testMethod.hasExpectedResult) { testMethod.expectedResult = parms.Result; } testMethod.RunState = parms.RunState; testMethod.IgnoreReason = parms.IgnoreReason; testMethod.BuilderException = parms.ProviderException; arglist = parms.Arguments; if (arglist != null) { argsProvided = arglist.Length; } if (testMethod.RunState != RunState.Runnable) { return(false); } } #if CLR_2_0 || CLR_4_0 bool isAsyncMethod = Reflect.IsAsyncMethod(testMethod.Method); bool hasMeaningfulReturnType = isAsyncMethod ? testMethod.Method.ReturnType.IsGenericType : testMethod.Method.ReturnType != typeof(void); #else bool hasMeaningfulReturnType = testMethod.Method.ReturnType != typeof(void); #endif if (hasMeaningfulReturnType && (parms == null || !parms.HasExpectedResult && parms.ExpectedExceptionName == null)) { return(MarkAsNotRunnable(testMethod, "Test method has non-void return type, but no result is expected")); } if (!hasMeaningfulReturnType && parms != null && parms.HasExpectedResult) { return(MarkAsNotRunnable(testMethod, "Test method has void return type, but a result is expected")); } if (argsProvided > 0 && argsNeeded == 0) { return(MarkAsNotRunnable(testMethod, "Arguments provided for method not taking any")); } if (argsProvided == 0 && argsNeeded > 0) { return(MarkAsNotRunnable(testMethod, "No arguments were provided")); } //if (argsProvided > argsNeeded) //{ // ParameterInfo lastParameter = parameters[argsNeeded - 1]; // Type lastParameterType = lastParameter.ParameterType; // if (lastParameterType.IsArray && lastParameter.IsDefined(typeof(ParamArrayAttribute), false)) // { // object[] newArglist = new object[argsNeeded]; // for (int i = 0; i < argsNeeded; i++) // newArglist[i] = arglist[i]; // int length = argsProvided - argsNeeded + 1; // Array array = Array.CreateInstance(lastParameterType.GetElementType(), length); // for (int i = 0; i < length; i++) // array.SetValue(arglist[argsNeeded + i - 1], i); // newArglist[argsNeeded - 1] = array; // testMethod.arguments = arglist = newArglist; // argsProvided = argsNeeded; // } //} if (argsProvided != argsNeeded) { testMethod.RunState = RunState.NotRunnable; testMethod.IgnoreReason = "Wrong number of arguments provided"; return(false); } #if CLR_2_0 || CLR_4_0 if (testMethod.Method.IsGenericMethodDefinition) { Type[] typeArguments = GetTypeArgumentsForMethod(testMethod.Method, arglist); foreach (object o in typeArguments) { if (o == null) { testMethod.RunState = RunState.NotRunnable; testMethod.IgnoreReason = "Unable to determine type arguments for fixture"; return(false); } } testMethod.method = testMethod.Method.MakeGenericMethod(typeArguments); parameters = testMethod.Method.GetParameters(); for (int i = 0; i < parameters.Length; i++) { if (arglist[i].GetType() != parameters[i].ParameterType && arglist[i] is IConvertible) { try { arglist[i] = Convert.ChangeType(arglist[i], parameters[i].ParameterType); } catch (Exception) { // Do nothing - the incompatible argument will be reported below } } } } #endif return(true); }
public override void Patch(Harmony harmony) { PatchPrefix(harmony, Reflect.Method((DevConsole t) => t.Update())); }
/// <summary> /// Determine whether any test cases are available for a parameterized method. /// </summary> /// <param name="method">A MethodInfo representing a parameterized test</param> /// <returns>True if any cases are available, otherwise false.</returns> public bool HasTestCasesFor(MethodInfo method) { return(Reflect.HasAttribute(method, NUnitFramework.TestCaseSourceAttribute, false)); }
public ISerializer Find(Reflect.Type type, bool deserialize) { return type == "short" ? this : null; }
public ISerializer Find(Reflect.Type type, bool deserialize) { return type.Implements<IString>() ? this : null; }
/// <summary> /// Registers a method for use in Authorization. /// </summary> /// <param name="methodLambdaExpression">The method lambda expression.</param> /// <returns></returns> protected static MethodInfo RegisterMethod(Expression <Action <T> > methodLambdaExpression) { System.Reflection.MethodInfo reflectedMethodInfo = Reflect <T> .GetMethod(methodLambdaExpression); return(RegisterMethod(typeof(T), reflectedMethodInfo.Name)); }
void initref(int sx, int sy, int width, int height, int matt) { int xh = width / 2; int yh = height / 2; int dx = xh - sx; int dy = yh - sy; _numref = 19; _reflect[0] = new Reflect(); _reflect[0].type = 1; _reflect[0].size = matt * 0.027; _reflect[0].xp = (int)(0.6699 * dx + xh); _reflect[0].yp = (int)(0.6699 * dy + yh); _reflect[0].ccol.r = 0.0; _reflect[0].ccol.g = 14.0 / 255.0; _reflect[0].ccol.b = 113.0 / 255.0; _reflect[1] = new Reflect(); _reflect[1].type = 1; _reflect[1].size = matt * 0.01; _reflect[1].xp = (int)(0.2692 * dx + xh); _reflect[1].yp = (int)(0.2692 * dy + yh); _reflect[1].ccol.r = 90.0 / 255.0; _reflect[1].ccol.g = 181.0 / 255.0; _reflect[1].ccol.b = 142.0 / 255.0; _reflect[2] = new Reflect(); _reflect[2].type = 1; _reflect[2].size = matt * 0.005; _reflect[2].xp = (int)(-0.0112 * dx + xh); _reflect[2].yp = (int)(-0.0112 * dy + yh); _reflect[2].ccol.r = 56.0 / 255.0; _reflect[2].ccol.g = 140.0 / 255.0; _reflect[2].ccol.b = 106.0 / 255.0; _reflect[3] = new Reflect(); _reflect[3].type = 2; _reflect[3].size = matt * 0.031; _reflect[3].xp = (int)(0.6490 * dx + xh); _reflect[3].yp = (int)(0.6490 * dy + yh); _reflect[3].ccol.r = 9.0 / 255.0; _reflect[3].ccol.g = 29.0 / 255.0; _reflect[3].ccol.b = 19.0 / 255.0; _reflect[4] = new Reflect(); _reflect[4].type = 2; _reflect[4].size = matt * 0.015; _reflect[4].xp = (int)(0.4696 * dx + xh); _reflect[4].yp = (int)(0.4696 * dy + yh); _reflect[4].ccol.r = 24.0 / 255.0; _reflect[4].ccol.g = 14.0 / 255.0; _reflect[4].ccol.b = 0.0; _reflect[5] = new Reflect(); _reflect[5].type = 2; _reflect[5].size = matt * 0.037; _reflect[5].xp = (int)(0.4087 * dx + xh); _reflect[5].yp = (int)(0.4087 * dy + yh); _reflect[5].ccol.r = 24.0 / 255.0; _reflect[5].ccol.g = 14.0 / 255.0; _reflect[5].ccol.b = 0.0; _reflect[6] = new Reflect(); _reflect[6].type = 2; _reflect[6].size = matt * 0.022; _reflect[6].xp = (int)(-0.2003 * dx + xh); _reflect[6].yp = (int)(-0.2003 * dy + yh); _reflect[6].ccol.r = 42.0 / 255.0; _reflect[6].ccol.g = 19.0 / 255.0; _reflect[6].ccol.b = 0.0; _reflect[7] = new Reflect(); _reflect[7].type = 2; _reflect[7].size = matt * 0.025; _reflect[7].xp = (int)(-0.4103 * dx + xh); _reflect[7].yp = (int)(-0.4103 * dy + yh); _reflect[7].ccol.b = 17.0 / 255.0; _reflect[7].ccol.g = 9.0 / 255.0; _reflect[7].ccol.r = 0.0; _reflect[8] = new Reflect(); _reflect[8].type = 2; _reflect[8].size = matt * 0.058; _reflect[8].xp = (int)(-0.4503 * dx + xh); _reflect[8].yp = (int)(-0.4503 * dy + yh); _reflect[8].ccol.b = 10.0 / 255.0; _reflect[8].ccol.g = 4.0 / 255.0; _reflect[8].ccol.r = 0.0; _reflect[9] = new Reflect(); _reflect[9].type = 2; _reflect[9].size = matt * 0.017; _reflect[9].xp = (int)(-0.5112 * dx + xh); _reflect[9].yp = (int)(-0.5112 * dy + yh); _reflect[9].ccol.r = 5.0 / 255.0; _reflect[9].ccol.g = 5.0 / 255.0; _reflect[9].ccol.b = 14.0 / 255.0; _reflect[10] = new Reflect(); _reflect[10].type = 2; _reflect[10].size = matt * 0.2; _reflect[10].xp = (int)(-1.496 * dx + xh); _reflect[10].yp = (int)(-1.496 * dy + yh); _reflect[10].ccol.r = 9.0 / 255.0; _reflect[10].ccol.g = 4.0 / 255.0; _reflect[10].ccol.b = 0.0; _reflect[11] = new Reflect(); _reflect[11].type = 2; _reflect[11].size = matt * 0.5; _reflect[11].xp = (int)(-1.496 * dx + xh); _reflect[11].yp = (int)(-1.496 * dy + yh); _reflect[11].ccol.r = 9.0 / 255.0; _reflect[11].ccol.g = 4.0 / 255.0; _reflect[11].ccol.b = 0.0; _reflect[12] = new Reflect(); _reflect[12].type = 3; _reflect[12].size = matt * 0.075; _reflect[12].xp = (int)(0.4487 * dx + xh); _reflect[12].yp = (int)(0.4487 * dy + yh); _reflect[12].ccol.r = 34.0 / 255.0; _reflect[12].ccol.g = 19.0 / 255.0; _reflect[12].ccol.b = 0.0; _reflect[13] = new Reflect(); _reflect[13].type = 3; _reflect[13].size = matt * 0.1; _reflect[13].xp = (int)(dx + xh); _reflect[13].yp = (int)(dy + yh); _reflect[13].ccol.r = 14.0 / 255.0; _reflect[13].ccol.g = 26.0 / 255.0; _reflect[13].ccol.b = 0.0; _reflect[14] = new Reflect(); _reflect[14].type = 3; _reflect[14].size = matt * 0.039; _reflect[14].xp = (int)(-1.301 * dx + xh); _reflect[14].yp = (int)(-1.301 * dy + yh); _reflect[14].ccol.r = 10.0 / 255.0; _reflect[14].ccol.g = 25.0 / 255.0; _reflect[14].ccol.b = 13.0 / 255.0; _reflect[15] = new Reflect(); _reflect[15].type = 4; _reflect[15].size = matt * 0.19; _reflect[15].xp = (int)(1.309 * dx + xh); _reflect[15].yp = (int)(1.309 * dy + yh); _reflect[15].ccol.r = 9.0 / 255.0; _reflect[15].ccol.g = 0.0; _reflect[15].ccol.b = 17.0 / 255.0; _reflect[16] = new Reflect(); _reflect[16].type = 4; _reflect[16].size = matt * 0.195; _reflect[16].xp = (int)(1.309 * dx + xh); _reflect[16].yp = (int)(1.309 * dy + yh); _reflect[16].ccol.r = 9.0 / 255.0; _reflect[16].ccol.g = 16.0 / 255.0; _reflect[16].ccol.b = 5.0 / 255.0; _reflect[17] = new Reflect(); _reflect[17].type = 4; _reflect[17].size = matt * 0.20; _reflect[17].xp = (int)(1.309 * dx + xh); _reflect[17].yp = (int)(1.309 * dy + yh); _reflect[17].ccol.r = 17.0 / 255.0; _reflect[17].ccol.g = 4.0 / 255.0; _reflect[17].ccol.b = 0.0; _reflect[18] = new Reflect(); _reflect[18].type = 4; _reflect[18].size = matt * 0.038; _reflect[18].xp = (int)(-1.301 * dx + xh); _reflect[18].yp = (int)(-1.301 * dy + yh); _reflect[18].ccol.r = 17.0 / 255.0; _reflect[18].ccol.g = 4.0 / 255.0; _reflect[18].ccol.b = 0.0; }
public override void Serialize(IDataWriter writer) { writer.WriteVarUhLong(Experience); writer.WriteVarUhLong(ExperienceLevelFloor); writer.WriteVarUhLong(ExperienceNextLevelFloor); writer.WriteVarUhLong(ExperienceBonusLimit); writer.WriteVarUhLong(Kamas); writer.WriteVarUhShort(StatsPoints); writer.WriteVarUhShort(AdditionnalPoints); writer.WriteVarUhShort(SpellsPoints); AlignmentInfos.Serialize(writer); writer.WriteVarUhInt(LifePoints); writer.WriteVarUhInt(MaxLifePoints); writer.WriteVarUhShort(EnergyPoints); writer.WriteVarUhShort(MaxEnergyPoints); writer.WriteVarShort(ActionPointsCurrent); writer.WriteVarShort(MovementPointsCurrent); Initiative.Serialize(writer); Prospecting.Serialize(writer); ActionPoints.Serialize(writer); MovementPoints.Serialize(writer); Strength.Serialize(writer); Vitality.Serialize(writer); Wisdom.Serialize(writer); Chance.Serialize(writer); Agility.Serialize(writer); Intelligence.Serialize(writer); Range.Serialize(writer); SummonableCreaturesBoost.Serialize(writer); Reflect.Serialize(writer); CriticalHit.Serialize(writer); writer.WriteVarUhShort(CriticalHitWeapon); CriticalMiss.Serialize(writer); HealBonus.Serialize(writer); AllDamagesBonus.Serialize(writer); WeaponDamagesBonusPercent.Serialize(writer); DamagesBonusPercent.Serialize(writer); TrapBonus.Serialize(writer); TrapBonusPercent.Serialize(writer); GlyphBonusPercent.Serialize(writer); RuneBonusPercent.Serialize(writer); PermanentDamagePercent.Serialize(writer); TackleBlock.Serialize(writer); TackleEvade.Serialize(writer); PAAttack.Serialize(writer); PMAttack.Serialize(writer); PushDamageBonus.Serialize(writer); CriticalDamageBonus.Serialize(writer); NeutralDamageBonus.Serialize(writer); EarthDamageBonus.Serialize(writer); WaterDamageBonus.Serialize(writer); AirDamageBonus.Serialize(writer); FireDamageBonus.Serialize(writer); DodgePALostProbability.Serialize(writer); DodgePMLostProbability.Serialize(writer); NeutralElementResistPercent.Serialize(writer); EarthElementResistPercent.Serialize(writer); WaterElementResistPercent.Serialize(writer); AirElementResistPercent.Serialize(writer); FireElementResistPercent.Serialize(writer); NeutralElementReduction.Serialize(writer); EarthElementReduction.Serialize(writer); WaterElementReduction.Serialize(writer); AirElementReduction.Serialize(writer); FireElementReduction.Serialize(writer); PushDamageReduction.Serialize(writer); CriticalDamageReduction.Serialize(writer); PvpNeutralElementResistPercent.Serialize(writer); PvpEarthElementResistPercent.Serialize(writer); PvpWaterElementResistPercent.Serialize(writer); PvpAirElementResistPercent.Serialize(writer); PvpFireElementResistPercent.Serialize(writer); PvpNeutralElementReduction.Serialize(writer); PvpEarthElementReduction.Serialize(writer); PvpWaterElementReduction.Serialize(writer); PvpAirElementReduction.Serialize(writer); PvpFireElementReduction.Serialize(writer); MeleeDamageDonePercent.Serialize(writer); MeleeDamageReceivedPercent.Serialize(writer); RangedDamageDonePercent.Serialize(writer); RangedDamageReceivedPercent.Serialize(writer); WeaponDamageDonePercent.Serialize(writer); WeaponDamageReceivedPercent.Serialize(writer); SpellDamageDonePercent.Serialize(writer); SpellDamageReceivedPercent.Serialize(writer); writer.WriteShort((short)SpellModifications.Count); for (var spellModificationsIndex = 0; spellModificationsIndex < SpellModifications.Count; spellModificationsIndex++) { var objectToSend = SpellModifications[spellModificationsIndex]; objectToSend.Serialize(writer); } writer.WriteInt(ProbationTime); }
public void NameShouldReturnNameByPropertyAndProperty() { Assert.AreEqual("Title", Reflect.Name <Foo>(x => x.Boo.Title)); }
public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator) { return new Data.String((data as IString).String, data, type); }
public void Correlate <TMessage>(Func <TMessage, object> messageValueExtractorFunction, Expression <Func <TSagaData, object> > sagaDataValueExpression) { var sagaDataPropertyName = Reflect.Path(sagaDataValueExpression); Correlate(messageValueExtractorFunction, sagaDataPropertyName); }
int mrt1(int color, Reflect r, int x, int y) { double procent = 1 - FHypot(r.xp - x, r.yp - y) / r.size; if (procent > 0) { procent *= procent; color = fixpix(color, procent, r.ccol); } return color; }
public void CorrelateHeader <TMessage>(string headerKey, Expression <Func <TSagaData, object> > sagaDataValueExpression) { var sagaDataPropertyName = Reflect.Path(sagaDataValueExpression); CorrelateHeader <TMessage>(headerKey, sagaDataPropertyName); }
int mrt4(int color, Reflect r, int x, int y) { double procent = FHypot(r.xp - x, r.yp - y) - r.size; procent /= (r.size * 0.04); procent = Math.Abs(procent); if (procent < 1) color = fixpix(color, 1 - procent, r.ccol); return color; }
public void CorrelateContext <TMessage>(Func <IMessageContext, object> contextValueExtractorFunction, Expression <Func <TSagaData, object> > sagaDataValueExpression) { var sagaDataPropertyName = Reflect.Path(sagaDataValueExpression); CorrelateContext <TMessage>(contextValueExtractorFunction, sagaDataPropertyName); }
public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator resource) { Data.Node result; Uri.Locator l = storage.Resolver.Update(data, resource); if (l.NotNull()) result = new Data.Link(l); else { result = new Data.Branch(data, type); foreach (Reflect.Property property in data.GetProperties()) { ParameterAttribute[] attributes = property.GetAttributes<ParameterAttribute>(); if (attributes.Length == 1 && property.Data.NotNull()) { string name = attributes[0].Name ?? property.Name.Convert(Casing.Pascal, storage.Casing); if (resource.NotNull()) { l = resource.Copy(); l.Fragment = (l.Fragment.NotEmpty() ? l.Fragment + "/" : "") + name; } (result as Data.Branch).Nodes.Add(storage.Serialize(property.Type, property.Data, l).UpdateName(name).UpdateAttribute(attributes[0]).UpdateLocator(resource)); } } } return result; }
public Picture DrawPage(byte pageNumber) { Picture output = new Picture(320, 200); int yy; switch (pageNumber) { case 1: string[] text = new string[0]; text = Resources.GetCivilopediaText("BLURB0/" + Name.ToUpper()); yy = 76; foreach (string line in text) { Log(line); output.DrawText(line, 6, 1, 12, yy); yy += 9; } break; case 2: yy = 84; if (pageNumber == 2) { if (RequiredTechs.Length > 0) { StringBuilder requiredTech = new StringBuilder(); foreach (IAdvance tech in RequiredTechs) { if (requiredTech.Length > 0) { requiredTech.Append(" and "); } requiredTech.Append(tech.Name); } output.DrawText(string.Format("Requires {0}", requiredTech), 6, 1, 32, yy); yy += 8; } yy += 16; output.DrawText("Allows:", 6, 1, 32, yy); yy += 8; foreach (IAdvance tech in Common.Advances.Where(a => a.Requires(Id))) { string allows = tech.Name; foreach (IAdvance at in tech.RequiredTechs.Where(a => a.Id != Id)) { allows += string.Format(" (with {0})", at.Name); } output.DrawText(allows, 6, 9, 40, yy); yy += 8; } yy += 4; foreach (IUnit unit in Reflect.GetUnits().Where(u => u.RequiredTech != null && u.RequiredTech.Id == Id)) { output.AddLayer(unit.ToBitmap(Game.PlayerNumber(Human)), 40, yy - 5); output.DrawText(string.Format("{0} unit", unit.Name), 6, 12, 60, yy); yy += 12; } foreach (IBuilding building in Reflect.GetBuildings().Where(b => b.RequiredTech != null && b.RequiredTech.Id == Id)) { if (building.SmallIcon != null) { output.AddLayer(building.SmallIcon, 39, yy - 2); } output.DrawText(string.Format("{0} improvement", building.Name), 6, 2, 60, yy); yy += 12; } foreach (IWonder wonder in Reflect.GetWonders().Where(w => w.RequiredTech != null && w.RequiredTech.Id == Id)) { if (wonder.SmallIcon != null) { output.AddLayer(wonder.SmallIcon, 39, yy - 2); } output.DrawText(string.Format("{0} Wonder", wonder.Name), 6, 2, 60, yy); yy += 12; } } break; default: Log("Invalid page number: {0}", pageNumber); break; } return(output); }
public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator) { return new Data.String((string)this.GetToStringCast(data.Type()).Invoke(null, System.Reflection.BindingFlags.Static, null, new object[] { data }, System.Globalization.CultureInfo.InvariantCulture), data, type); }
private object RunNonAsyncTestMethod(TestExecutionContext context) { return(Reflect.InvokeMethod(testMethod.Method, context.TestObject, arguments)); }
public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator) { ISerializer serializer = this.Find(data.Type(), false); return serializer.NotNull() ? serializer.Serialize(storage, type, data, locator) : null; }
/// <summary>获取提供者工厂</summary> /// <param name="assemblyFile"></param> /// <param name="className"></param> /// <returns></returns> protected static DbProviderFactory GetProviderFactory(String assemblyFile, String className) { var url = NewLife.Setting.Current.PluginServer; var name = Path.GetFileNameWithoutExtension(assemblyFile); var linkName = name; if (Runtime.Is64BitProcess) { linkName += "64"; } var ver = Environment.Version; if (ver.Major >= 4) { linkName += "Fx" + ver.Major + ver.Minor; } // 有些数据库驱动不区分x86/x64,并且逐步以Fx4为主,所以来一个默认 linkName += ";" + name; var type = PluginHelper.LoadPlugin(className, null, assemblyFile, linkName, url); // 反射实现获取数据库工厂 var file = assemblyFile; file = NewLife.Setting.Current.GetPluginPath().CombinePath(file); // 如果还没有,就写异常 if (type == null && !File.Exists(file)) { throw new FileNotFoundException("缺少文件" + file + "!", file); } if (type == null) { XTrace.WriteLine("驱动文件{0}无效或不适用于当前环境,准备删除后重新下载!", assemblyFile); try { File.Delete(file); } catch (UnauthorizedAccessException) { } catch (Exception ex) { XTrace.Log.Error(ex.ToString()); } type = PluginHelper.LoadPlugin(className, null, file, linkName, url); // 如果还没有,就写异常 if (!File.Exists(file)) { throw new FileNotFoundException("缺少文件" + file + "!", file); } } if (type == null) { return(null); } var field = type.GetFieldEx("Instance"); if (field == null) { return(Activator.CreateInstance(type) as DbProviderFactory); } return(Reflect.GetValue(null, field) as DbProviderFactory); }
DEFINE_STANDARD_OP(Reflect, REFLECT)
public void DynamicCrudTest() { FileInfo inputFile = new FileInfo("c:\\BamTestData\\Db_SillydatabaseNameMap_NormalizEDOnTypes.json"); SchemaNameMap map = SchemaNameMap.Load(inputFile.FullName); DynamicDatabase db = new DynamicDatabase(GetDatabase(), map); var bryan = new { Type = "Customer", Where = new { FirstName = "Bam" } }; db.Delete(bryan); var retrieved = db.RetrieveFirst(bryan); Expect.IsNull(retrieved); db.Create(Reflect.Combine(bryan, new { FirstName = "Bam", LastName = "Apellanes", Birthday = new DateTime(1976, 11, 1), Age = 38 })); db.Create(Reflect.Combine(bryan, new { FirstName = "Bam", LastName = "Banana", Birthday = new DateTime(1974, 1, 1), Age = 10 })); var query = new { TableName = "Customer", Where = new { FirstName = "Bam" } }; dynamic[] results = db.Retrieve(query).ToArray(); Expect.AreEqual(2, results.Length); OutLine("Results after insert", ConsoleColor.Cyan); foreach (object result in results) { OutLine(result.PropertiesToString(), ConsoleColor.Cyan); } db.Delete(new { Type = "Customer", Where = new { LastName = "Apellanes", Or = new { LastName = "Banana" } } }); results = db.Retrieve(query).ToArray(); Expect.AreEqual(0, results.Length, "Should have got no results"); }
protected override bool Found(Reflect.Type type, bool deserialize) { return !deserialize && this.GetInterface(type).NotNull(); }
private static bool CheckTestMethodSignature(TestMethod testMethod, TestCaseParameters?parms) { if (testMethod.Method.IsAbstract) { return(MarkAsNotRunnable(testMethod, "Method is abstract")); } if (!testMethod.Method.IsPublic) { return(MarkAsNotRunnable(testMethod, "Method is not public")); } IParameterInfo[] parameters; parameters = testMethod.Method.GetParameters(); int minArgsNeeded = 0; foreach (var parameter in parameters) { // IsOptional is supported since .NET 1.1 if (!parameter.IsOptional) { minArgsNeeded++; } } int maxArgsNeeded = parameters.Length; object?[]? arglist = null; int argsProvided = 0; if (parms != null) { testMethod.parms = parms; testMethod.RunState = parms.RunState; arglist = parms.Arguments; if (arglist != null) { argsProvided = arglist.Length; } if (testMethod.RunState != RunState.Runnable) { return(false); } } var returnType = testMethod.Method.ReturnType.Type; if (AsyncToSyncAdapter.IsAsyncOperation(testMethod.Method.MethodInfo)) { if (returnType == typeof(void)) { return(MarkAsNotRunnable(testMethod, "Async test method must have non-void return type")); } var voidResult = Reflect.IsVoidOrUnit(AwaitAdapter.GetResultType(returnType)); if (!voidResult && (parms == null || !parms.HasExpectedResult)) { return(MarkAsNotRunnable(testMethod, "Async test method must return an awaitable with a void result when no result is expected")); } if (voidResult && parms != null && parms.HasExpectedResult) { return(MarkAsNotRunnable(testMethod, "Async test method must return an awaitable with a non-void result when a result is expected")); } } else if (Reflect.IsVoidOrUnit(returnType)) { if (parms != null && parms.HasExpectedResult) { return(MarkAsNotRunnable(testMethod, "Method returning void cannot have an expected result")); } } else if (parms == null || !parms.HasExpectedResult) { return(MarkAsNotRunnable(testMethod, "Method has non-void return value, but no result is expected")); } if (argsProvided > 0 && maxArgsNeeded == 0) { return(MarkAsNotRunnable(testMethod, "Arguments provided for method with no parameters")); } if (argsProvided == 0 && minArgsNeeded > 0) { return(MarkAsNotRunnable(testMethod, "No arguments were provided")); } if (argsProvided < minArgsNeeded) { return(MarkAsNotRunnable(testMethod, string.Format("Not enough arguments provided, provide at least {0} arguments.", minArgsNeeded))); } if (argsProvided > maxArgsNeeded) { return(MarkAsNotRunnable(testMethod, string.Format("Too many arguments provided, provide at most {0} arguments.", maxArgsNeeded))); } if (testMethod.Method.IsGenericMethodDefinition) { if (arglist == null || !new GenericMethodHelper(testMethod.Method.MethodInfo).TryGetTypeArguments(arglist, out Type[] typeArguments))
System.Type GetInterface(Reflect.Type type) { return type.Name == "System.Collections.Generic.IEnumerable" ? (System.Type)type : ((System.Type)type).GetInterface(typeof(System.Collections.Generic.IEnumerable<>).Name); }
private static object InvokeMethod(MethodInfo method, TestExecutionContext context) { return(Reflect.InvokeMethod(method, method.IsStatic ? null : context.TestObject)); }
public ISerializer Find(Reflect.Type type, bool deserialize) { return this.Found(type, deserialize) ? this : null; }
/// <summary> /// Sets the default value of the given property /// </summary> public void SetPropertyDefault <T>(Expression <Func <T, object> > property, object value) { var prop = Reflect <T> .GetProperty(property); SetDefault(typeof(T).FullName + "." + prop.Name, value); }
protected abstract object Create(Reflect.Type type, Reflect.Type elementType, int count);
/// <summary> /// Indicates that the specified property belongs /// to the business object type. /// </summary> /// <typeparam name="P">Type of property</typeparam> /// <param name="propertyLambdaExpression">Property Expression</param> /// <param name="relationship">Relationship with /// referenced object.</param> /// <returns></returns> protected static PropertyInfo <P> RegisterProperty <P>(Expression <Func <T, object> > propertyLambdaExpression, RelationshipTypes relationship) { PropertyInfo reflectedPropertyInfo = Reflect <T> .GetProperty(propertyLambdaExpression); return(RegisterProperty <P>(reflectedPropertyInfo.Name, relationship)); }
public ISerializer Find(Reflect.Type type, bool deserialize) { return type == "System.DateTime" ? this : null; }
/// <summary> /// Indicates that the specified property belongs /// to the business object type. /// </summary> /// <typeparam name="P">Type of property</typeparam> /// <param name="propertyLambdaExpression">Property Expression</param> /// <param name="friendlyName">Friendly description for a property to be used in databinding</param> /// <returns></returns> protected static PropertyInfo <P> RegisterProperty <P>(Expression <Func <T, object> > propertyLambdaExpression, string friendlyName) { PropertyInfo reflectedPropertyInfo = Reflect <T> .GetProperty(propertyLambdaExpression); return(RegisterProperty <P>(reflectedPropertyInfo.Name, friendlyName)); }
public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator) { return new Data.Short(data, type); }
/// <summary> /// Indicates that the specified property belongs /// to the business object type. /// </summary> /// <typeparam name="P">Type of property</typeparam> /// <param name="propertyLambdaExpression">Property Expression</param> /// <param name="friendlyName">Friendly description for a property to be used in databinding</param> /// <param name="defaultValue">Default Value for the property</param> /// <param name="relationship">Relationship with /// referenced object.</param> /// <returns></returns> protected static PropertyInfo <P> RegisterProperty <P>(Expression <Func <T, object> > propertyLambdaExpression, string friendlyName, P defaultValue, RelationshipTypes relationship) { PropertyInfo reflectedPropertyInfo = Reflect <T> .GetProperty(propertyLambdaExpression); return(RegisterProperty(reflectedPropertyInfo.Name, friendlyName, defaultValue, relationship)); }