/// <see cref="MarkupExtension.ProvideValue"/> public override object ProvideValue(IServiceProvider serviceProvider) { TypeArguments.Add(TypeArgument); ConstructorArguments.Add(App.Container); ConstructorArguments.Add(Name); return(base.ProvideValue(serviceProvider)); }
public bool ContainedIn(ISymbol symbol) { bool result = false; var attributes = symbol.GetAttributes(); foreach (var attribute in attributes) { INamedTypeSymbol attributeClass = attribute.AttributeClass; if (Uid != VisitorHelper.GetId(attributeClass)) { continue; } // arguments need to be a total match of the config IEnumerable <string> arguments = attribute.ConstructorArguments.Select(arg => GetLiteralString(arg)); if (!ConstructorArguments.SequenceEqual(arguments)) { continue; } // namedarguments need to be a superset of the config Dictionary <string, string> namedArguments = attribute.NamedArguments.ToDictionary(pair => pair.Key, pair => GetLiteralString(pair.Value)); if (!ConstructorNamedArguments.Except(namedArguments).Any()) { result = true; break; } } return(result); }
public ContextualServiceDescriptor(IServiceCollection services, Type serviceType, Type implementationType, ServiceLifetime lifetime) { if (serviceType == null) { throw new ArgumentNullException(nameof(serviceType)); } if (implementationType == null) { throw new ArgumentNullException(nameof(implementationType)); } Services = services ?? throw new ArgumentNullException(nameof(services)); ServiceDescriptor = new ServiceDescriptor(serviceType, factory, lifetime); object factory(IServiceProvider serviceProvider) { var serviceTypes = ConstructorArguments .Select(x => x.ServiceType) .ToArray(); var arguments = ConstructorArguments .Select(x => serviceProvider.GetService(x.ImplementationType)) .ToArray(); var f = ActivatorUtilities.CreateFactory(implementationType, serviceTypes); return(f(serviceProvider, arguments)); } }
private void EditOverrideForm_Load(object sender, EventArgs e) { var clone = new CustomAttribute(SelectedAttribute.Constructor); foreach (var ctorarg in SelectedAttribute.ConstructorArguments) { clone.ConstructorArguments.Add(ctorarg); } foreach (var fnarg in SelectedAttribute.Fields) { clone.Fields.Add(fnarg); } foreach (var pnarg in SelectedAttribute.Properties) { clone.Properties.Add(pnarg); } WorkingAttribute = clone; ConstructorArguments.Bind(clone); Fields.Bind(clone); Properties.Bind(clone); Constructor.SelectedOperand = clone.Constructor; AttributeType.SelectedOperand = clone.AttributeType; }
public bool ContainedIn(SymbolFilterData symbol) { bool result = false; var attributes = symbol.Attributes; foreach (var attribute in attributes) { if (Uid != attribute.Id) { continue; } // arguments need to be a total match of the config if (ConstructorArguments != null && !ConstructorArguments.SequenceEqual(attribute.ConstructorArguments)) { continue; } // namedarguments need to be a superset of the config if (!ConstructorNamedArguments.Except(attribute.ConstructorNamedArguments).Any()) { result = true; break; } } return(result); }
protected override object CreateTestClass() { var testClass = base.CreateTestClass(); (testClass as ILoggedTest).Initialize( TestMethod, TestMethodArguments, _output ?? ConstructorArguments.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper); if (testClass is LoggedTestBase loggedTestBase) { // Used for testing loggedTestBase.RetryContext = _retryContext; if (_retryContext != null) { // Log retry attempt as warning if (_retryContext.CurrentIteration > 0) { loggedTestBase.Logger.LogWarning($"{TestMethod.Name} failed and retry conditions are met, re-executing. The reason for failure is {_retryContext.Reason}."); } // Save the test class instance for non-static predicates _retryContext.TestClassInstance = testClass; } } return(testClass); }
public void ValidateFromParsable() { object obj = new AggregateNumbers(); Type parseType = typeof(AggregateNumbers); bool suppressDefaults = true; ConstructorArguments ctorArgs = ConstructorArguments.FromParsable(obj, parseType, suppressDefaults); Assert.IsNotNull(ctorArgs); }
public static NamedSequence Parse(string constructorArgs) { ConstructorArguments constArgs = new ConstructorArguments("(" + constructorArgs + ")"); NamedSequence result = new NamedSequence(); result.Protein = constArgs.ExtractOptional <string>("Protein", null); result.Name = constArgs.ExtractNext <string>("name"); return(result); }
/// <summary> /// Creates an instance of the tag definition specified by this configuration element /// </summary> /// <returns>The tag definition instance</returns> public ITagDefinition CreateTagDefinition() { if (ConstructorArguments == null || ConstructorArguments.Count == 0) { return((ITagDefinition)Activator.CreateInstance(TagDefinitionType)); } object[] args = ConstructorArguments.Cast <ArgumentConfigurationElement>().Select(elem => elem.Value).ToArray(); return((ITagDefinition)Activator.CreateInstance(TagDefinitionType, args)); }
public void ValidateToString() { object obj = new AggregateNumbers(); Type parseType = typeof(AggregateNumbers); bool suppressDefaults = true; ConstructorArguments ctorArgs = ConstructorArguments.FromParsable(obj, parseType, suppressDefaults); string str = ctorArgs.ToString(); Assert.IsTrue(str.Contains("ResultFile")); Assert.IsTrue(str.Contains("InputFile")); }
public void ValidateToStringWithParams() { object parsableObject = new AggregateNumbers(); bool suppressDefaults = false; string str = ConstructorArguments.ToString(parsableObject, suppressDefaults); Assert.IsTrue(str.Contains("AggregateNumbers")); Assert.IsTrue(str.Contains("Cleanup")); Assert.IsTrue(str.Contains("ResultFile")); Assert.IsTrue(str.Contains("InputFile")); }
public static string ToFormattedName(this MethodReturnType type) { // 对 (T, T) 类型的需要特殊考虑。 if (type.ReturnType.FullName.StartsWith("System.ValueTuple`", StringComparison.InvariantCulture) && type.ReturnType is GenericInstanceType vgt) { var names = type.CustomAttributes.FirstOrDefault(x => x.AttributeType.FullName is "System.Runtime.CompilerServices.TupleElementNamesAttribute") ?.ConstructorArguments.SelectMany(x => (CustomAttributeArgument[])x.Value).Select(x => x.Value as string).ToArray() ?? new string[vgt.GenericArguments.Count]; return($"({string.Join(", ", vgt.GenericArguments.Select((x, i) => $"{x.ToFormattedName()}{(names[i] is null ? "" : $" {names[i]}")}"))})"); }
public Expression BindParameter(ParameterExpression parameter, Dictionary <Expression, Expression> processedExpressions) { Func <Expression, Expression> genericBinder = e => GenericExpressionVisitor <IMappedExpression> .Process(e, mapped => mapped.BindParameter(parameter, processedExpressions)); return(new ConstructorExpression( Type, Bindings.ToDictionary(kvp => kvp.Key, kvp => genericBinder(kvp.Value)), NativeBindings.ToDictionary(kvp => kvp.Key, kvp => genericBinder(kvp.Value)), Constructor, ConstructorArguments.Select(genericBinder).ToList())); }
private void CreateOverrideForm_Load(object sender, EventArgs e) { ButInsertBefore.Enabled = SelectedAttribute != null; ButInsertAfter.Enabled = SelectedAttribute != null; var newca = new CustomAttribute(null); WorkingAttribute = newca; ConstructorArguments.Bind(WorkingAttribute); Fields.Bind(WorkingAttribute); Properties.Bind(WorkingAttribute); }
public Expression RemoveOuterParameter(Dictionary <Expression, Expression> processedExpressions) { Func <Expression, Expression> genericRemover = e => GenericExpressionVisitor <IMappedExpression> .Process(e, mapped => mapped.RemoveOuterParameter(processedExpressions)); var result = new ConstructorExpression( Type, Bindings.ToDictionary(kvp => kvp.Key, kvp => genericRemover(kvp.Value)), NativeBindings = NativeBindings.ToDictionary(kvp => kvp.Key, kvp => genericRemover(kvp.Value)), Constructor, ConstructorArguments.Select(genericRemover).ToList()); return(result); }
protected override object CreateTestClass() { var testClass = base.CreateTestClass(); if (testClass is ILoggedTest loggedTest) { loggedTest.Initialize( TestMethod, TestMethodArguments, _output ?? ConstructorArguments.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper); } return(testClass); }
public override int GetHashCode() { unchecked { var hashCode = TypeFullyQualified.GetHashCode(); hashCode = (hashCode * 397) ^ _type.IsReferenceType.GetHashCode(); hashCode = (hashCode * 397) ^ InnerTypesInfo.GetHashCode(); hashCode = (hashCode * 397) ^ Settings.GetHashCode(); hashCode = (hashCode * 397) ^ ConstructorArguments.ComputeHashCode(); hashCode = (hashCode * 397) ^ Items.ComputeHashCode(); return(hashCode); } }
void CreateArguments() { int count = Constructor == null ? 0 : Constructor.MethodSig.GetParamCount(); while (ConstructorArguments.Count > count) { ConstructorArguments.RemoveAt(ConstructorArguments.Count - 1); } while (ConstructorArguments.Count < count) { var type = Constructor.MethodSig.Params[ConstructorArguments.Count]; ConstructorArguments.Add(new CAArgumentVM(ownerModule, CreateCAArgument(type), new TypeSigCreatorOptions(ownerModule, language), type)); } }
protected async override Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { var testOutputHelper = ConstructorArguments.SingleOrDefault(a => typeof(TestOutputHelper).IsAssignableFrom(a.GetType())) as TestOutputHelper ?? new TestOutputHelper(); testOutputHelper.Initialize(MessageBus, Test); var executionTime = await InvokeTestMethodAsync(aggregator, testOutputHelper); var output = testOutputHelper.Output; testOutputHelper.Uninitialize(); return(Tuple.Create(executionTime, output)); }
public void ValidateConstructT() { string fileName = Path.GetTempFileName(); fileName = fileName.Replace(Path.GetTempPath(), ""); string fileName1 = Path.GetTempFileName(); fileName1 = fileName1.Replace(Path.GetTempPath(), ""); using (File.Create(fileName)) { } using (File.Create(fileName1)) { } string args = "(ResultFile:(" + fileName + "),(" + fileName1 + "))"; AggregateNumbers aggregateNums = ConstructorArguments.Construct <AggregateNumbers>(args); Assert.IsNotNull(aggregateNums); }
public Expression Remap(int[] map, Dictionary <Expression, Expression> processedExpressions) { Func <IMappedExpression, Expression> remapper = delegate(IMappedExpression mapped) { var parametrizedExpression = mapped as ParameterizedExpression; if (parametrizedExpression != null && (parametrizedExpression.OuterParameter == OuterParameter || OuterParameter == null)) { return(mapped.Remap(map, new Dictionary <Expression, Expression>())); } return((Expression)mapped); }; var newBindings = Bindings.ToDictionary(kvp => kvp.Key, kvp => GenericExpressionVisitor <IMappedExpression> .Process(kvp.Value, remapper)); var newConstructorArguments = ConstructorArguments.Select(arg => GenericExpressionVisitor <IMappedExpression> .Process(arg, remapper)); var newNativeBindings = NativeBindings.ToDictionary(kvp => kvp.Key, kvp => GenericExpressionVisitor <IMappedExpression> .Process(kvp.Value, remapper)); return(new ConstructorExpression(Type, newBindings, newNativeBindings, Constructor, newConstructorArguments)); }
protected override object CreateTestClass() { var testClass = base.CreateTestClass(); if (testClass is LoggedTest loggedTestClass) { var classType = loggedTestClass.GetType(); var logLevelAttribute = TestMethod.GetCustomAttribute <LogLevelAttribute>() as LogLevelAttribute; var testName = TestMethodArguments.Aggregate(TestMethod.Name, (a, b) => $"{a}-{(b ?? "null")}"); // Try resolving ITestOutputHelper from constructor arguments loggedTestClass.TestOutputHelper = ConstructorArguments?.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper; var useShortClassName = TestMethod.DeclaringType.GetCustomAttribute <ShortClassNameAttribute>() ?? TestMethod.DeclaringType.Assembly.GetCustomAttribute <ShortClassNameAttribute>(); var resolvedClassName = useShortClassName == null ? classType.FullName : classType.Name; // None resolved so create a new one and retain a reference to it for initialization/uninitialization if (loggedTestClass.TestOutputHelper == null) { loggedTestClass.TestOutputHelper = _output = new TestOutputHelper(); _output.Initialize(MessageBus, Test); } AssemblyTestLog .ForAssembly(classType.GetTypeInfo().Assembly) .StartTestLog( loggedTestClass.TestOutputHelper, resolvedClassName, out var loggerFactory, logLevelAttribute?.LogLevel ?? LogLevel.Trace, out var resolvedTestName, testName); // internal for testing loggedTestClass.ResolvedTestMethodName = resolvedTestName; loggedTestClass.ResolvedTestClassName = resolvedClassName; loggedTestClass.LoggerFactory = loggerFactory; loggedTestClass.Logger = loggerFactory.CreateLogger(classType); loggedTestClass.TestSink = new TestSink(); loggerFactory.AddProvider(new TestLoggerProvider(loggedTestClass.TestSink)); loggedTestClass.AdditionalSetup(); } return(testClass); }
protected override object CreateTestClass() { var testClass = base.CreateTestClass(); (testClass as ILoggedTest).Initialize( TestMethod, TestMethodArguments, _output ?? ConstructorArguments.SingleOrDefault(a => typeof(ITestOutputHelper).IsAssignableFrom(a.GetType())) as ITestOutputHelper); if (testClass is LoggedTestBase loggedTestBase) { // Used for testing loggedTestBase.RepeatContext = _repeatContext; } return(testClass); }
public bool Equals(BaseEnumState?other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(TypeFullyQualified == other.TypeFullyQualified && _type.IsReferenceType.Equals(other._type.IsReferenceType) && InnerTypesInfo.Equals(other.InnerTypesInfo) && Settings.Equals(other.Settings) && ConstructorArguments.EqualsTo(other.ConstructorArguments) && Items.EqualsTo(other.Items)); }
public bool IsValid(Notification notification) { try { var constructor = GetType().GetConstructor(ConstructorArguments.Select(x => x.GetType()).ToArray()); if (constructor == null) { notification.AddError(new ValidationError(string.Format("Failed to extract constructor for operation {0}. Check the order of the parameters going into the base class. The order needs to be the same is in your constructor", GetType().Name))); return(false); } } catch (Exception ex) { notification.AddError(new ValidationError(string.Format("Failed to extract constructor for operation {0}. Error message: {1}", GetType().Name, ex.Message))); return(false); } return(true); }
protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { var testOutputHelper = ConstructorArguments.OfType <TestOutputHelper>().FirstOrDefault() ?? new TestOutputHelper(); testOutputHelper.Initialize(MessageBus, Test); try { TestContextProvider.Initialize(TestMethod, TestMethodArguments, testOutputHelper, SkipReason); var totalTime = await InvokeTestMethodAsync(aggregator); return(Tuple.Create(totalTime, testOutputHelper.Output)); } finally { testOutputHelper.Uninitialize(); TestContextProvider.Clear(); } }
/// <inheritdoc/> protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { var output = String.Empty; var testOutputHelper = ConstructorArguments.OfType <TestOutputHelper>().FirstOrDefault(); if (testOutputHelper != null) { testOutputHelper.Initialize(MessageBus, Test); } var executionTime = await new XunitTestInvoker(Test, MessageBus, TestClass, ConstructorArguments, TestMethod, TestMethodArguments, beforeAfterAttributes, aggregator, CancellationTokenSource).RunAsync(); if (testOutputHelper != null) { output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } return(Tuple.Create(executionTime, output)); }
/// <inheritdoc/> protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { var output = String.Empty; var testOutputHelper = ConstructorArguments.OfType <TestOutputHelper>().FirstOrDefault(); if (testOutputHelper != null) { testOutputHelper.Initialize(MessageBus, Test); } var executionTime = await InvokeTestMethodAsync(aggregator); if (testOutputHelper != null) { output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } return(Tuple.Create(executionTime, output)); }
void InitializeFrom(CustomAttributeOptions options) { IsRawData = options.RawData != null; RawData.Value = options.RawData; Constructor = options.Constructor; ConstructorArguments.Clear(); var sig = Constructor == null ? null : Constructor.MethodSig; for (int i = 0; i < options.ConstructorArguments.Count; i++) { TypeSig type = null; if (sig != null && i < sig.Params.Count) { type = sig.Params[i]; } ConstructorArguments.Add(new CAArgumentVM(ownerModule, options.ConstructorArguments[i], new TypeSigCreatorOptions(ownerModule, language), type)); } CANamedArgumentsVM.InitializeFrom(options.NamedArguments); CreateArguments(); }
protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { string output = string.Empty; var testOutputHelper = TestMethodArguments.OfType <TestOutputHelper>().FirstOrDefault(); if (testOutputHelper == null) { testOutputHelper = ConstructorArguments.OfType <TestOutputHelper>().FirstOrDefault(); } if (testOutputHelper == null) { testOutputHelper = new TestOutputHelper(); } testOutputHelper?.Initialize(MessageBus, Test); decimal item = await InvokeTestMethodAsync(aggregator); if (testOutputHelper != null) { output = testOutputHelper.Output; var scenarioRunOutput = RenderScenarioReport(Scenario); if (scenarioRunOutput != null) { if (output.Length == 0) { scenarioRunOutput = scenarioRunOutput.Trim(); } output += scenarioRunOutput; } testOutputHelper.Uninitialize(); } return(Tuple.Create(item, output)); }