public void CreateShipWrong2() { MethodFactory factory = EarthFactory.Instance; var ship = factory.BuildCapitalShip("asdadwdq"); Assert.IsNull(ship); }
public void CreateShipEmpty() { MethodFactory factory = EarthFactory.Instance; var ship = factory.BuildFrigate(null); Assert.IsNull(ship); }
public void CreateShipWrong() { MethodFactory factory = EarthFactory.Instance; var ship = factory.BuildFrigate("aeria"); Assert.IsNull(ship); }
public void CreateShipWrong1() { MethodFactory factory = EarthFactory.Instance; var ship = factory.BuildCruiser("dwqdqwd"); Assert.IsNull(ship); }
public void CreateShip2() { MethodFactory factory = EarthFactory.Instance; var ship = factory.BuildCapitalShip("vulkoras"); Assert.IsNotNull(ship); }
public void CreateShip1() { MethodFactory factory = EarthFactory.Instance; var ship = factory.BuildCruiser("destra"); Assert.IsNotNull(ship); }
public void CreateShip() { MethodFactory factory = EarthFactory.Instance; var ship = factory.BuildFrigate("disciple"); Assert.IsNotNull(ship); }
public void CreateShipEmpty2() { MethodFactory factory = EarthFactory.Instance; var ship = factory.BuildCapitalShip(null); Assert.IsNull(ship); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationItemFactory"/> class. /// </summary> /// <param name="assemblies">The assemblies to scan for named items.</param> public ConfigurationItemFactory(params Assembly[] assemblies) { this.CreateInstance = FactoryHelper.CreateInstance; this.targets = new Factory<Target, TargetAttribute>(this); this.filters = new Factory<Filter, FilterAttribute>(this); this.layoutRenderers = new Factory<LayoutRenderer, LayoutRendererAttribute>(this); this.layouts = new Factory<Layout, LayoutAttribute>(this); this.conditionMethods = new MethodFactory<ConditionMethodsAttribute, ConditionMethodAttribute>(); this.ambientProperties = new Factory<LayoutRenderer, AmbientPropertyAttribute>(this); this.timeSources = new Factory<TimeSource, TimeSourceAttribute>(this); this.allFactories = new List<object> { this.targets, this.filters, this.layoutRenderers, this.layouts, this.conditionMethods, this.ambientProperties, this.timeSources, }; foreach (var asm in assemblies) { this.RegisterItemsFromAssembly(asm); } }
/// <summary> /// 初始化 /// </summary> static Copier() { MethodFactory <Func <TValue, TValue> > method = MethodFactory.Create <Func <TValue, TValue> >(); Type type = typeof(TValue); if (type == typeof(object)) { method.LoadArg(0).Return(); return; } switch (Type.GetTypeCode(type)) { case TypeCode.Object: if (type.IsClass) { method.LoadArg(0).Call(Reflector.GetMethod(typeof(object), "MemberwiseClone")).Cast(typeof(object), typeof(TValue)).Return(); } else { method.LoadArg(0).Return(); } break; default: method.LoadArg(0).Return(); break; } Clone = method.Delegation; }
public void MethodFactoryShouldReturnCorrectMethodInstance(string flowType, Type methodType) { var factory = new MethodFactory(_loggerMock); IDischargeCalculator method = factory.SelectCalculator(flowType, _settingsMock); Assert.AreEqual(methodType, method.GetType()); }
public async Task <TResponse> Handle( TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { foreach (var property in request.Command.GetType().GetProperties()) { if (!TryGetRequestValue(property, request.Command, out var keyPair)) { continue; } if (!property.TryGetAttribute <IdCollectionAttribute>(out var attribute)) { request.RequestPropertyValues.Add(keyPair.Key, keyPair.Value); continue; } var entities = await MethodFactory.GetManyAsync(attribute.EntityType) .InvokeAsync( _repository, new object[] { keyPair.Value, cancellationToken }); request.RequestPropertyValues.Add(keyPair.Key, entities); request.RequestForeignEntities.Add(keyPair.Key, attribute.EntityType); request.IncludeNavigation = string.Join(".", keyPair.Key); } return(await next()); }
private static string CalcOneMethod(SemiSpaceParameters parameters) { var bound12 = new Parallelepiped(-1, 1, -1, 1, FunctionsForSemiSpace.H, 1, 4, 4, 4) { Name = BoundNumber.Bound12 }; var bound2 = new Parallelepiped(-1, 1, -1, 1, FunctionsForSemiSpace.H, 1, 4, 4, 4) { Name = BoundNumber.Bound2 }; var bound13 = new Parallelepiped(-1, 1, 0, 1, -1, FunctionsForSemiSpace.H, 4, 4, 4) { Name = BoundNumber.Bound13 }; var bound3 = new Parallelepiped(-1, 1, 0, 1, -1, FunctionsForSemiSpace.H, 4, 4, 4) { Name = BoundNumber.Bound3 }; // var bound12 = new Sphere(new Point3D(5, 0, FunctionsForSemiSpace.H)) { Name = BoundNumber.Bound12 }; //var bound2 = new Sphere(new Point3D(5, 0, FunctionsForSemiSpace.H)) { Name = BoundNumber.Bound2 }; // var bound13 = new Sphere(new Point3D(5, 0, FunctionsForSemiSpace.H)) { Name = BoundNumber.Bound13 }; // var bound3 = new Sphere(new Point3D(5, 0, FunctionsForSemiSpace.H)) { Name = BoundNumber.Bound3 }; var boundWithCondition = ConditionSetter.SetBoundSphere(bound12, bound2, bound13, bound3).ToList(); // var boundWithCondition = ConditionSetter.SetBoundSphere(bound12, bound2).ToList(); var method = MethodFactory.GetSphereMethod(boundWithCondition, null, parameters); method.Solve(); var plotter = PlotterFactory.GetPlotter(method.U, parameters); plotter.Plot(); return(plotter.FormatedFileName); }
// registry this type with the registry public void RegisterType(Type type) { var info = type.GetTypeInfo(); if (info.IsEnum || constructors.ContainsKey(type)) { return; } var constructor = type.GetConstructors().FirstOrDefault(x => x.GetParameters().Length == 0); if (constructor == null) { throw new ArgumentException($"{type.FullName} does not have any accessible parameterless constructors.", nameof(type)); } var attribute = info.GetCustomAttribute <RtmpSharpAttribute>(false) ?? RtmpSharpAttribute.Empty; var canonicalName = attribute.CanonicalName ?? type.FullName; var names = attribute.Names ?? EmptyCollection <string> .Array; foreach (var name in names) { localTypeLookup[name] = type; } constructors[type] = MethodFactory.CompileConstructor(constructor); remoteNameLookup[type.FullName] = canonicalName; if (canonicalName != "") { localTypeLookup[canonicalName] = type; } }
public static IMethodInfo GetMethod(this InvokeExpression invokeExpr, SemanticContext context) { var parts = invokeExpr.MethodName.Parts.ToInvertedStack(); TypeDefinition type; if (!context.TypeRegistry.TrySearch(parts, out type)) { throw new SemanticException("Can't find method by identifier: {0}", invokeExpr.MethodName); } // todo: implement member chaining var methodName = parts.Pop(); var types = invokeExpr.Arguments .Select(x => TypeInference.InferType(x.Value, context)) .ToArray(invokeExpr.Arguments.Count); var method = type.GetMethod(methodName, types); if (method == null) { throw new SemanticException("Can't find method by identifier: {0}", invokeExpr.MethodName); } if (method.DeclaringType.Assembly.Equals(context.TypeDefinition.Assembly)) { return(method); } return(MethodFactory.GetMethodReference(method)); }
public void SetUp() { _relatedMethodFinderMock = MockRepository.GenerateStrictMock <IRelatedMethodFinder>(); _factory = new MethodFactory(_relatedMethodFinderMock); _mutableType = MutableTypeObjectMother.Create(baseType: typeof(DomainType)); }
public void SetUp() { _relatedMethodFinderMock = new Mock <IRelatedMethodFinder> (MockBehavior.Strict); _factory = new MethodFactory(_relatedMethodFinderMock.Object); _mutableType = MutableTypeObjectMother.Create(baseType: typeof(DomainType)); }
public void CreateWehicleChecEmptyName() { MethodFactory factory1 = MarsFactory.Instance; MethodFactory factory2 = MarsFactory.Instance; var ship1 = factory1.BuildCruiser("skarovas"); var ship2 = factory2.BuildCruiser("skarovas"); Assert.AreEqual(ship1.Name, ship2.Name); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (UDIRSHelper.PersonDetails != null) { MethodFactory.BindStatusSearch(ref ddlStatus); BindGridview(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, UDIRSHelper.PersonDetails.Id); } } }
public static FunctionMethod Emit(IR.Function function, MethodFactory methodFactory, FunctionLookup functionLookup) { Contract.Requires(function != null); Contract.Requires(methodFactory != null); Contract.Requires(functionLookup != null); var emitter = new FunctionEmitter(function, methodFactory, functionLookup); emitter.EmitBody(); return(emitter.Method); }
public PaperKirghoff1UmovaProgram(Bound <Point3D> bound, List <InnerSourceWithFunction <Point3D> > source) { var boundWithCondition = ConditionSetter.SetDirichletConditionSphere(bound); method = MethodFactory.GetCollocationKirghoffMethod( boundWithCondition, source, KirghoffTransformation.Pow, KirghoffTransformation.ConversePow); method.Solve(); }
public void MethodFactoryShouldThrowExceptionIfUnsupportedFlowType(string flowType) { var factory = new MethodFactory(_loggerMock); Assert.Throws <Exception>(() => { factory.SelectCalculator(flowType, _settingsMock); }); Mock.Get(_loggerMock).Verify(x => x.Error(It.IsAny <string>()), Times.Once); Mock.Get(_loggerMock).Invocations.Clear(); }
static void Main(string[] args) { var Configuration = ReadFromAppSettings(); var methodInvoker = new MethodFactory(new MethodFactoryConfiguration() { AssemblyPrefix = new List <string>() { "CustomMethod" }, AssemblySuffix = new List <string>() { "MethodLib" }, AssemblyRelatedPath = Configuration["AssemblyRelatedPath"] ?? string.Empty }); var regex = new Regex(@"(?<first>[0-9 ]+)(?<expression>\+|\-|\*|\/)(?<second>[0-9 ]+)", RegexOptions.Compiled); while (true) { Console.WriteLine($"Key in any arithmetic like '123 + 321' or 'Exit' to leave."); var input = Console.ReadLine(); if (input.Equals("Exit", StringComparison.InvariantCultureIgnoreCase)) { break; } var match = regex.Match(input); if (!match.Success) { Console.WriteLine($"Format error!"); continue; } var firstNumber = Convert.ToInt32(match.Groups["first"].Value); var secondNumber = Convert.ToInt32(match.Groups["second"].Value); var expression = match.Groups["expression"].Value.ToString(); // Get Method var method = methodInvoker.GetInvokeMethod(GetMethodName(expression), null); // Call function var returnResult = (int)method.DynamicInvoke(new object[] { firstNumber, secondNumber }); Console.WriteLine($"The answer is : {returnResult}"); } }
private object InvokeEntityMethod(string methodName) { MethodInfo methodInfo = MethodFactory.GetMethodInfo(this.Page.GetType(), methodName); if (methodInfo != null && this.IsAjaxMethod(methodInfo)) { ParameterInfo[] pareameterInfos = ParameterFactory.GetParameterInfos(methodInfo); object[] parameterValueList = this.GetEntityParameterValueList(pareameterInfos); return(methodInfo.Invoke(this.Page, parameterValueList)); } else { throw new Exception("没有找到指定调用方法"); } }
public void DoWork() { var sw = new Stopwatch(); sw.Start(); // var bound = new ParallelepipedNearBound(); var bound = new Parallelepiped(); var boundWithCondition = ConditionSetter.SetKirghoffCondition(bound); var source = new InnerSourcePlate(); // var innerSource = new List<InnerSourceWithFunction<Point3D>>(); //no innersors CollocationKirghoffMethod var innerSource = InnerSourceFactory.GetSourcesParalelepiped(source); var eps = 1; var paperKirghoff = new PaperKirghoff1UmovaProgram(bound, innerSource); var dPrevious = paperKirghoff.GetSolutionVector(); Vector dCurrent; while (true) { var method1 = MethodFactory.GetJakobiMethod(boundWithCondition, innerSource, dPrevious); method1.Solve(); dCurrent = dPrevious + method1.Solution; dPrevious = dCurrent; Console.WriteLine("d: " + method1.Solution.Norma()); if (method1.Solution.Norma() < eps) { break; } } var method = MethodFactory.GetCollocationKirghoffMethod( boundWithCondition, innerSource, KirghoffTransformation.Pow, KirghoffTransformation.ConversePow); method.Solution = dCurrent; var plotter = PlotterFactory.GetPlotter(bound, method.U); plotter.Plot(); // Console.WriteLine("Total time: " + sw.ElapsedMilliseconds); /*f-1*f(d0)=x * d1=d0-x, * f-1*f(d1)=x * d2=d1-x*/ }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (UDIRSHelper.PersonDetails != null) { MethodFactory.BindStatusSearch(ref ddlStatus); BindGridview(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 0); PopulateLocation(); } } else { //lblMsg.Text = "No Incident Report."; } }
public void AddtionProcessTest() { var methodInvoker = new MethodFactory(); var firstNumber = 20; var secondNumber = 30; var expressionMethod = "AddtionProcess"; // Get Method var method = methodInvoker.GetInvokeMethod(expressionMethod, null); // Call function var returnResult = (int)method.DynamicInvoke(new object[] { firstNumber, secondNumber }); Assert.AreEqual(firstNumber + secondNumber, returnResult); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { object instance = MethodFactory.CreateInstance(destinationType); ClassDescription classDescription = this._serializationContext.GetClassDescription(destinationType, instance); IDictionary <string, object> dictionary = value as IDictionary <string, object>; if (dictionary == null) { return(base.ConvertTo(context, culture, value, destinationType)); } foreach (KeyValuePair <string, object> keyValuePair in (IEnumerable <KeyValuePair <string, object> >)dictionary) { IMemberWrapper memberWrapper; if (classDescription.TryGetMember(keyValuePair.Key, out memberWrapper)) { memberWrapper.SetValue(instance, keyValuePair.Value); } } return(instance); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { var instance = MethodFactory.CreateInstance(destinationType); var classDescription = serializationContext.GetClassDescription(destinationType, instance); var source = value as IDictionary <string, object>; if (source != null) { foreach (var kv in source) { IMemberWrapper wrapper; if (classDescription.TryGetMember(kv.Key, out wrapper)) { wrapper.SetValue(instance, kv.Value); } } return(instance); } return(base.ConvertTo(context, culture, value, destinationType)); }
public static object InvokeMethod(this object entity, string methodName, object[] parameters) { try { MethodInfo methodInfo = MethodFactory.GetMethodInfo(entity.GetType(), methodName); if (methodInfo != null) { ParameterInfo[] pareameterInfos = ParameterFactory.GetParameterInfos(methodInfo); return(methodInfo.Invoke(entity, parameters)); } else { throw new Exception("没有找到指定调用方法"); } } catch (Exception e) { throw new Exception(string.Format("调用指定调用方法时出错,{0}", e.Message)); } }
public void DoWork() { var bound = new Circle(800, 2) { IsOuter = true }; ////var bound = new Rectangle(new Point2D(-1, -1), new Point2D(1, 1), 160) { IsOuter = true }; var segment1 = new Segment(new Point2D(-1.1, -1.1), new Point2D(1.1, 1.1), 160); ////var segment1 = new Segment(new Point2D(-0.75, 0.1), new Point2D(0, 0.9), 80); ////var segment2 = new Segment(new Point2D(-0.75, -0.1), new Point2D(0, -0.9), 80); ////var segment3 = new Segment(new Point2D(0.75, 0.1), new Point2D(0, 0.9), 80); ////var segment4 = new Segment(new Point2D(0.75, -0.1), new Point2D(0, -0.9), 80); var boundWithCondition = ConditionSetter.SetDirichletCondition(segment1, bound); var method = MethodFactory.GetCollocationPaper6Method(boundWithCondition, 1); method.Solve(); var plotter = PlotterFactory.GetPlotter(bound, method.U, 40); plotter.Plot(); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationItemFactory"/> class. /// </summary> /// <param name="assemblies">The assemblies to scan for named items.</param> public ConfigurationItemFactory(params Assembly[] assemblies) { CreateInstance = FactoryHelper.CreateInstance; _targets = new Factory<Target, TargetAttribute>(this); _filters = new Factory<Filter, FilterAttribute>(this); _layoutRenderers = new Factory<LayoutRenderer, LayoutRendererAttribute>(this); _layouts = new Factory<Layout, LayoutAttribute>(this); _conditionMethods = new MethodFactory<ConditionMethodsAttribute, ConditionMethodAttribute>(); _ambientProperties = new Factory<LayoutRenderer, AmbientPropertyAttribute>(this); _allFactories = new List<object> { _targets, _filters, _layoutRenderers, _layouts, _conditionMethods, _ambientProperties, }; foreach (var asm in assemblies) RegisterItemsFromAssembly(asm); }