protected override String ConvertCore(IConversionContext <Color> context) { context.ValidateWith(ContextValidator).ThrowIfNotValid(); // ReSharper disable once AssignNullToNotNullAttribute - Validator takes care of context.Format but there is no way to tell it R# return(string.Format(context.FormatProvider, context.Format, context.Value)); }
protected override DateTime ConvertCore(IConversionContext <string> context) { return (string.IsNullOrEmpty(context.Format) ? DateTime.Parse(context.Value, context.FormatProvider, DateTimeStyles.None) : DateTime.ParseExact(context.Value, context.Format, context.FormatProvider, DateTimeStyles.None)); }
protected override T ConvertCore(IConversionContext <string> context) { // String-types require quotes for deserialization. var requiresQuotes = IsStringType(typeof(T)) && !IsQuoted(context.Value); return(JsonConvert.DeserializeObject <T>(requiresQuotes ? Quote(context.Value) : context.Value, Settings)); }
public object Convert(IConversionContext <object> context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (IsConverted(context.FromType, context.ToType)) { return(context.Value); } try { return (CanConvert(context.FromType, context.ToType) ? ConvertCore(context) : throw DynamicException.Create ( $"UnsupportedConversion", $"There is no converter from '{context.FromType.ToPrettyString()}' to '{context.ToType.ToPrettyString()}'." )); } catch (Exception inner) { throw DynamicException.Create ( $"Conversion", $"Could not convert from '{context.FromType.ToPrettyString()}' to '{context.ToType.ToPrettyString()}'.", inner ); } }
protected override string ConvertCore(IConversionContext <decimal> context) { return (string.IsNullOrEmpty(context.Format) ? context.Value.ToString(context.FormatProvider) : context.Value.ToString(context.Format, context.FormatProvider)); }
public UnitOfWork(IConversionContext context, IUserContext userContext) { _context = (ConversionsContext)context; _userContext = (UserContext)userContext; Converts = new ConvertRepository(_context); Users = new UserRepository(_userContext); }
public IBuildIntention <IInterfaceType> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = InterfaceType.Create(); return(new BuildIntention <IInterfaceType>(toBuild, () => { maker.Build(Scope.Convert(context).Members); })); }
public IBuildIntention <IReturnOperation> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = ReturnOperation.Create(); return(new BuildIntention <IReturnOperation>(toBuild, () => { maker.Build(Result.GetOrThrow().ConvertElementOrThrow(context)); })); }
public IBuildIntention <IFinalizedScope> GetBuildIntention(IConversionContext context) { var scope = new Tac.Model.Instantiated.Scope(); return(new BuildIntention <Model.Instantiated.Scope>(scope, () => { scope.Build(membersList.Select(x => new IsStatic(x.Convert(context), false)).ToArray()); })); }
public IBuildIntention <IEmptyInstance> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = EmptyInstance.Create(); return(new BuildIntention <IEmptyInstance>(toBuild, () => { maker.Build(); })); }
public IBuildIntention <IMemberReference> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = MemberReference.Create(); return(new BuildIntention <IMemberReference>(toBuild, () => { maker.Build(MemberDefinition.GetValue().Is1OrThrow().Convert(context)); })); }
public static IVerifiableType ConvertTypeOrThrow(this IFrontendType self, IConversionContext context) { if (self is IConvertableFrontendType <IVerifiableType> convertable) { return(convertable.Convert(context)); } throw new Exception("could not be converted"); }
public override IBuildIntention <IIfOperation> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = IfOperation.Create(); return(new BuildIntention <IIfOperation>(toBuild, () => { maker.Build(Left.GetOrThrow().ConvertElementOrThrow(context), Right.GetOrThrow().ConvertElementOrThrow(context)); })); }
public IBuildIntention <IObjectDefiniton> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = ObjectDefiniton.Create(); return(new BuildIntention <IObjectDefiniton>(toBuild, () => { maker.Build(Scope.Convert(context), Assignments.Select(x => x.GetOrThrow().Convert(context)).ToArray()); })); }
public IBuildIntention <IConstantString> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = ConstantString.Create(); return(new BuildIntention <IConstantString>(toBuild, () => { maker.Build( Value.GetOrThrow()); })); }
public IBuildIntention <IFinalizedScope> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = Model.Instantiated.Scope.Create(); return(new BuildIntention <IFinalizedScope>(toBuild, () => { maker.Build( members.Select(x => new Tac.Model.Instantiated.Scope.IsStatic(x.Value.Single().Definition.GetValue().GetOrThrow().Convert(context), false)).ToArray()); })); }
public IBuildIntention <IVerifiableType> GetBuildIntention(IConversionContext _) { var(res, maker) = Model.Instantiated.GemericTypeParameterPlacholder.Create(); // this is stack allocated and might be GC'ed so we need to create locals // to feed to the lambda var key = Key; return(new BuildIntention <IVerifiableType>(res, () => { maker.Build(key); })); }
public override IBuildIntention <ITypeOr> GetBuildIntention(IConversionContext context) { // not sure what I am doing with this ... should it just become a type? var(res, builder) = TypeOr.Create(); return(new BuildIntention <ITypeOr>(res, () => builder.Build( Left.GetOrThrow().ConvertTypeOrThrow(context), Right.GetOrThrow().ConvertTypeOrThrow(context) ))); }
protected override string ConvertCore(IConversionContext <T> context) { var result = JsonConvert.SerializeObject(context.Value, Settings); // String-types must not contain quotes after serialization. return (IsStringType(typeof(T)) ? Unquote(result) : result); }
/// <summary> /// Converts the <paramref name="sourceNode"/> and attaches conversion results to the <paramref name="targetParent"/>. /// </summary> /// <param name="sourceNode">Source node to convert</param> /// <param name="targetParent">Target parent node</param> /// <param name="context">Current conversion context</param> /// <returns>Converted node</returns> public override XNode ConvertNode(XNode sourceNode, XNode targetParent, IConversionContext context) { // Typical over-expression node will have two children: aggregate function identifier and over-expression parameters. if (sourceNode.Children.Count == 2) { // Get the function identifier node var sourceFunctionIdentifierNode = sourceNode.Children[0]; // Extract function name var sourceFunctionCompoundName = OracleNameProcessor.Instance.GetNameFromIdentifier(sourceFunctionIdentifierNode); // Check, if function identifier is a simple one-part identifier and is suitable for our conversion if (sourceFunctionCompoundName.Count == 1 && SupportedAggregationFunctions.Contains(sourceFunctionCompoundName.Last.NormalName)) { // Create over-expression node in the target tree var targetOverExpressionNode = targetParent.Children.AddNew(SqlServerParserConstants.NodeNames.OVER_EXPRESSION); // Create identifier node for the aggregate function in the target over-expression var targetFunctionIdentifierNode = targetOverExpressionNode.Children.AddNew(SqlServerParserConstants.NodeNames.SIMPLE_IDENTIFIER); targetFunctionIdentifierNode.Attributes[SqlServerParserConstants.AttributeNames.TEXT] = targetFunctionIdentifierNode.Attributes[SqlServerParserConstants.AttributeNames.VALUE] = sourceFunctionCompoundName.Last.NormalName; // Create parameters node under target function identifier node var targetFunctionIdentifierParamsNode = targetFunctionIdentifierNode.Children.AddNew(SqlServerParserConstants.NodeNames.SIMPLE_IDENTIFIER_PARAMS); // Convert function arguments base.ConvertNode( sourceFunctionIdentifierNode.GetAllNodesByName(SqlServerParserConstants.NodeNames.EXPRESSION_LIST).First(), targetFunctionIdentifierParamsNode, context); // Get the parameters for over expression var sourceOverExpressionParametersNode = sourceNode.Children[1]; // Create parameters node in target over-expression var overExpressionParams = targetOverExpressionNode.Children.AddNew(SqlServerParserConstants.NodeNames.OVER_EXPRESSION_PARAMS); // Convert first child of source over-expression-parameters base.ConvertNode( sourceOverExpressionParametersNode.FirstChild, overExpressionParams, context); return(targetOverExpressionNode); } } // Fallback to original over-expression node converter, in case we don't support the input return(originalOverExpressionConverter.ConvertNode(sourceNode, targetParent, context)); }
public override IBuildIntention <IBlockDefinition> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = BlockDefinition.Create(); return(new BuildIntention <IBlockDefinition>(toBuild, () => { maker.Build( Scope.Convert(context), Body.Select(x => x.GetOrThrow().ConvertElementOrThrow(context)).ToArray(), StaticInitailizers.Select(x => x.GetOrThrow().ConvertElementOrThrow(context)).ToArray()); })); }
//public IMemberDefinition Convert(IConversionContext context) //{ // return MemberDefinitionShared.Convert(Type, context, Access, Key); //} public virtual IBuildIntention <IMemberDefinition> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = MemberDefinition.Create(); return(new BuildIntention <IMemberDefinition>(toBuild, () => { maker.Build( Key, Type.GetValue().Is1OrThrow().Convert(context), Access); })); }
protected override Color ConvertCore(IConversionContext <String> context) { foreach (var colorParser in _colorParsers) { if (colorParser.TryParse(context.Value, out var argb)) { return(new Color32(argb)); } } return(Color.Empty); }
protected override String ConvertCore(IConversionContext <XElement> context) { using (var memoryStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memoryStream)) { var saveMethod = typeof(XElement).GetMethod("Save", new[] { typeof(StreamWriter), typeof(SaveOptions) }); // ReSharper disable once PossibleNullReferenceException - saveMethod is never null saveMethod.Invoke(context.Value, new object[] { streamWriter, SaveOptions.DisableFormatting }); var xml = Encoding.UTF8.GetString(memoryStream.ToArray()); return(xml); } }
public IBuildIntention <ITryAssignOperation> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = TryAssignOperation.Create(); return(new BuildIntention <ITryAssignOperation>(toBuild, () => { maker.Build( Left.Is1OrThrow().GetValue().ConvertElementOrThrow(context), Right.Is1OrThrow().GetValue().ConvertElementOrThrow(context), Body.Is1OrThrow().GetValue().ConvertElementOrThrow(context), Scope.Is1OrThrow().GetValue().Convert(context)); })); }
public IBuildIntention <IRootScope> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = RootScope.Create(); return(new BuildIntention <IRootScope>(toBuild, () => { maker.Build( Scope.Is1OrThrow().Convert(context), Assignments.GetValue().Select(x => x.Is1OrThrow().GetValue().Convert(context)).ToArray(), EntryPoint.GetValue().Is1OrThrow().GetValue().Convert(context) ); })); }
public override IBuildIntention <IGenericMethodDefinition> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = GenericMethodDefinition.Create(); return(new BuildIntention <IGenericMethodDefinition>(toBuild, () => { maker.Build( OutputType.Is1OrThrow().Convert(context), ParameterDefinition.Convert(context), Scope.Is1OrThrow().Convert(context), Body.GetValue().Select(x => x.Is1OrThrow().GetValue().ConvertElementOrThrow(context)).ToArray(), StaticInitailizers.Select(x => x.GetOrThrow().ConvertElementOrThrow(context)).ToArray(), TypeParameterDefinitions.Select(x => x.Is1OrThrow().Convert(context).SafeCastTo(out IGenericTypeParameter _)).ToArray()); }));
public override IBuildIntention <IEntryPointDefinition> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = EntryPointDefinition.Create(); return(new BuildIntention <IEntryPointDefinition>(toBuild, () => { maker.Build( OutputType.Is1OrThrow().Convert(context), ParameterDefinition.Convert(context), Scope.Is1OrThrow().Convert(context), Body.GetValue().Select(x => x.Is1OrThrow().GetValue().ConvertElementOrThrow(context)).ToArray(), StaticInitailizers.Select(x => x.GetOrThrow().ConvertElementOrThrow(context)).ToArray()); })); }
protected override object ConvertCore(IConversionContext <IEnumerable> context) { var valueType = context.ToType.GetGenericArguments()[0]; var listType = typeof(List <>).MakeGenericType(valueType); var list = (IList)Activator.CreateInstance(listType); foreach (var value in context.Value) { var element = context.Converter.Convert(new ConversionContext <object>(value, valueType, context)); list.Add(element); } return(list); }
public object Convert(IConversionContext <object> context) { if (IsConverted(context.FromType, context.ToType)) { return(context.Value); } if (CanConvert(context.FromType, context.ToType)) { return(ConvertCore(context)); } throw new FormatException($"Could not convert '{context.Value.GetType()}' to '{context.ToType}'."); }