/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { object array; if ( xml.Attributes[ "ref" ] != null ) { int stackIx = int.Parse( xml.Attributes[ "ref" ].Value ); array = context.GetStackObject( stackIx ) as Array; } else { array = Activator.CreateInstance(type); // Add the object to the stack context.Stack(array); foreach ( XmlNode child in xml.ChildNodes ) { Type memberType = null; IConverter conv = context.GetConverter( child, ref memberType ); object item = conv.FromXml( null, null, memberType, child, context ); MethodInfo method = array.GetType().GetMethod("Add"); method.Invoke(array, new object[] {item}); } } return array; //return converter.FromXml(parent, field, type, xml, context); }
public static void StringMarshaller(ref IMarshalContext ctx, Action next) { var @string = ctx.Compilation.GetSpecialType(SpecialType.System_String); var intptr = ctx.Compilation.GetSpecialType(SpecialType.System_IntPtr); var oldVariables = ctx.ParameterVariables.ToArray(); bool[] b = new bool[ctx.ParameterVariables.Length]; int[] bufferVars = new int[ctx.ParameterVariables.Length]; Dictionary <int, ExpressionSyntax> readback = new Dictionary <int, ExpressionSyntax>(); for (var index = 0; index < ctx.ParameterVariables.Length; index++) { b[index] = !SymbolEqualityComparer.Default.Equals(ctx.LoadTypes[index], @string); if (b[index]) { continue; } var marshalAs = ctx.ParameterMarshalOptions[index]?.UnmanagedType ?? Default; var charType = ctx.Compilation.CreatePointerTypeSymbol(marshalAs switch { UnmanagedType.BStr => ctx.Compilation.GetSpecialType(SpecialType.System_Char), UnmanagedType.LPWStr => ctx.Compilation.GetSpecialType(SpecialType.System_Char), UnmanagedType.LPStr => ctx.Compilation.GetSpecialType(SpecialType.System_Byte), UnmanagedType.LPTStr => ctx.Compilation.GetSpecialType(SpecialType.System_Byte), UnmanagedType.LPUTF8Str => ctx.Compilation.GetSpecialType(SpecialType.System_Byte), });
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { MethodInfo info = value as MethodInfo; ParameterInfo[] paramList = info.GetParameters(); if (info.ReflectedType == null) { throw new ConversionException("Unable to serialize MethodInfo, no reflected type."); } context.WriteStartTag(__type, field, xml); xml.WriteElementString("base", context.GetTypeName(info.ReflectedType)); xml.WriteElementString("name", info.Name); xml.WriteStartElement("params"); foreach (ParameterInfo paramInfo in paramList) { xml.WriteElementString("param", context.GetTypeName(paramInfo.ParameterType)); } xml.WriteEndElement(); context.WriteEndTag(__type, field, xml); }
/// <summary> /// Converts the given object to XML representation, /// using the specific MarshalContext for serialization. /// </summary> public string ToXml(object value, IMarshalContext context) { try { Type objectType = value.GetType(); IConverter converter = context.GetConverter(objectType); StringBuilder sbuf = new StringBuilder(); using (StringWriter sw = new StringWriter(sbuf)) { XmlTextWriter writer = new XmlTextWriter(sw); converter.ToXml(value, null, writer, context); writer.Close(); } return(sbuf.ToString()); } catch (ConversionException) { throw; } catch (Exception e) { throw new ConversionException(e.Message, e); } finally { context.ClearStack(); } }
/// <summary> /// Converts the XmlNode data passed in back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { if ( type.IsArray ) return Convert.FromBase64String( xml.InnerText ); else return byte.Parse( xml.InnerText ); }
/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { if ( type == __arrayType ) return xml.InnerText.ToCharArray(); else return char.Parse( xml.InnerText ); }
/// <summary> /// Register is called by a MarshalContext to allow the /// converter instance to register itself in the context /// with all appropriate value types and interfaces. /// </summary> public void Register(IMarshalContext context) { context.RegisterConverter( __type, this ); context.RegisterConverter( __arrayType, this ); context.Alias( "char", __type ); context.Alias( "chars", __arrayType ); }
/// <summary> /// Converts the xml string parameter back to a class instance, /// using the specified context for type mapping. /// </summary> public object FromXml( string xml, IMarshalContext context ) { try { XmlDocument xmlDoc = new XmlDocument(); if (!xml.StartsWith(__rootElement)) xml = __rootElement + Environment.NewLine + xml; xmlDoc.LoadXml( xml ); xmlDoc.RemoveChild(xmlDoc.FirstChild); Type type = null; IConverter converter = context.GetConverter( xmlDoc.FirstChild, ref type ); return converter.FromXml( null, null, type, xmlDoc.FirstChild, context ); } catch ( ConversionException ) { throw; } catch ( Exception e ) { throw new ConversionException( e.Message, e ); } finally { context.ClearStack(); } }
public static void PinMiddleware(ref IMarshalContext ctx, Action next) { for (var index = 0; index < ctx.ParameterVariables.Length; index++) { // in this loop, update all types & expressions var shouldPin = ctx.ShouldPinParameter[index]; if (!shouldPin) { continue; } var loadType = ctx.LoadTypes[index]; loadType = ctx.Compilation.CreatePointerTypeSymbol(loadType); ctx.LoadTypes[index] = loadType; var(id, name) = ctx.DeclareSpecialVariableNoInlining(loadType, false); ctx.SetParameterToVariable(index, id); var symbolName = ctx.MethodSymbol.Parameters[index].Name; var l = ctx.LoadTypes[index].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); ctx.BeginBlock((x, ctx) => FixedStatement ( VariableDeclaration ( IdentifierName(l), SingletonSeparatedList (VariableDeclarator(Identifier(name), null, EqualsValueClause(PrefixUnaryExpression(SyntaxKind.AddressOfExpression, IdentifierName(FormatName(symbolName)))))) ), x )); } next(); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { MethodInfo method = value.GetType().GetMethod("ToArray"); object invoke = method.Invoke(value, new object[] {}); converter.ToXml(invoke, field, xml, context); }
/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml( object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context ) { Array array; if ( xml.Attributes[ "ref" ] != null ) { int stackIx = int.Parse( xml.Attributes[ "ref" ].Value ); array = context.GetStackObject( stackIx ) as Array; } else { int childCount = xml.ChildNodes.Count; array = Activator.CreateInstance( type, new object[] { childCount } ) as Array; // Add the object to the stack context.Stack(array); int i = 0; foreach ( XmlNode child in xml.ChildNodes ) { Type memberType = null; IConverter converter = context.GetConverter( child, ref memberType ); array.SetValue( converter.FromXml( null, null, memberType, child, context ), i ); i++; } } return array; }
public static void InjectMiddleware(ref IMarshalContext ctx, Action next) { var context = ctx; var injectDatas = ctx.MethodSymbol.GetAttributes().Where( x => SymbolEqualityComparer.Default.Equals(x.AttributeClass, context.Compilation.GetTypeByMetadataName(typeof(InjectAttribute).FullName)) ); foreach (var injectData in injectDatas) { var injectPoint = (SilkTouchStage)injectData.ConstructorArguments[0].Value !; var code = (string)injectData.ConstructorArguments[1].Value !; ctx.AddSideEffectToStage(injectPoint, ctx => { if (injectPoint == SilkTouchStage.End) { var substitutions = _substitutionRegex.Match(code); if (substitutions.Success) { var codeBuilder = new StringBuilder(); var start = 0; string?resultStr = null; Dictionary <string, string>?pValues = null; while (substitutions.Success) { string?substitution = null; if (substitutions.Groups["result"].Success) { if (ctx.ResultVariable.HasValue) { // Cache for multiple-substitution if (resultStr is null) { resultStr = ParenthesizedExpression(ctx.ResolveVariable(ctx.ResultVariable.Value).Value) .NormalizeWhitespace() .ToFullString(); } substitution = resultStr; } } else { var parameterName = substitutions.Groups["pname"].Value; // Create parameter lookup dictionary first time we see the substitution. if (pValues is null) { pValues = ctx.MethodSymbol.Parameters .Select((p, i) => ( Name: p.Name, Value: ParenthesizedExpression(ctx.ResolveVariable(ctx.ParameterVariables[i]).Value) .NormalizeWhitespace() .ToFullString())) .ToDictionary(t => t.Name, t => t.Value); } if (pValues.TryGetValue(parameterName, out var value)) { substitution = value; } }
/// <summary> /// Register is called by a MarshalContext to allow the /// converter instance to register itself in the context /// with all appropriate value types and interfaces. /// </summary> public void Register(IMarshalContext context) { context.RegisterConverter(__type, this); context.RegisterConverter(__arrayType, this); context.Alias("char", __type); context.Alias("chars", __arrayType); }
/// <summary> /// Converts the given object to XML representation, /// using the specific MarshalContext for serialization. /// </summary> public string ToXml( object value, IMarshalContext context ) { try { Type objectType = value.GetType(); IConverter converter = context.GetConverter( objectType ); StringBuilder sbuf = new StringBuilder(); using ( StringWriter sw = new StringWriter( sbuf ) ) { XmlTextWriter writer = new XmlTextWriter( sw ); converter.ToXml( value, null, writer, context ); writer.Close(); } return sbuf.ToString(); } catch ( ConversionException ) { throw; } catch ( Exception e ) { throw new ConversionException( e.Message, e ); } finally { context.ClearStack(); } }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Array array = value as Array; Type arrayType = array.GetType(); context.WriteStartTag( arrayType, field, xml ); int stackIx = context.GetStackIndex( value ); if ( stackIx >= 0 ) xml.WriteAttributeString( "ref", stackIx.ToString() ); else { context.Stack( array ); foreach ( object child in array ) { IConverter converter; if ( child != null ) converter = context.GetConverter( child.GetType() ); else converter = context.GetConverter( null ); if (converter == null) throw new ConversionException("Couldnot find converter for: " + child.GetType() + " having value: " + child); converter.ToXml( child, null, xml, context ); } } context.WriteEndTag( arrayType, field, xml ); }
/// <summary> /// Converts the xml string parameter back to a class instance, /// using the specified context for type mapping. /// </summary> public object FromXml(string xml, IMarshalContext context) { try { XmlDocument xmlDoc = new XmlDocument(); if (!xml.StartsWith(__rootElement)) { xml = __rootElement + Environment.NewLine + xml; } xmlDoc.LoadXml(xml); xmlDoc.RemoveChild(xmlDoc.FirstChild); Type type = null; IConverter converter = context.GetConverter(xmlDoc.FirstChild, ref type); return(converter.FromXml(null, null, type, xmlDoc.FirstChild, context)); } catch (ConversionException) { throw; } catch (Exception e) { throw new ConversionException(e.Message, e); } finally { context.ClearStack(); } }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Type type = value.GetType(); context.WriteStartTag( type, field, xml ); xml.WriteString( value.ToString() ); context.WriteEndTag( type, field, xml ); }
public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { var removedString = value.ToString().Replace("\b", "").Replace("\0", ""); context.WriteStartTag(__type, field, xml); xml.WriteString(removedString); context.WriteEndTag(__type, field, xml); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Type type = value.GetType(); context.WriteStartTag(type, field, xml); xml.WriteString(value.ToString()); context.WriteEndTag(type, field, xml); }
public static void SpanMarshaller(ref IMarshalContext ctx, Action next) { bool[] b = new bool[ctx.ParameterVariables.Length]; for (var index = 0; index < ctx.ParameterVariables.Length; index++) { if (!(ctx.LoadTypes[index] is INamedTypeSymbol named)) { continue; } if (!named.IsGenericType) { continue; } if (!SymbolEqualityComparer.Default.Equals(named.OriginalDefinition, ctx.Compilation.GetTypeByMetadataName("System.Span`1"))) { continue; } b[index] = true; } var oldParameterIds = ctx.ParameterVariables.ToArray(); for (var index = 0; index < ctx.ParameterVariables.Length; index++) { // in this loop, update all types & expressions var shouldPin = b[index]; if (!shouldPin) { continue; } var loadType = ctx.LoadTypes[index]; loadType = ctx.Compilation.CreatePointerTypeSymbol((loadType as INamedTypeSymbol) !.TypeArguments[0]); ctx.LoadTypes[index] = loadType; var(id, name) = ctx.DeclareSpecialVariableNoInlining(loadType, false); ctx.SetParameterToVariable(index, id); var l = ctx.LoadTypes[index].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var old = ctx.ResolveVariable(oldParameterIds[index]); ctx.BeginBlock((x, ctx) => FixedStatement ( VariableDeclaration ( IdentifierName(l), SingletonSeparatedList (VariableDeclarator(Identifier(name), null, EqualsValueClause(old.Value))) ), x )); } next(); }
public static void ParameterInitMiddleware(ref IMarshalContext ctx, Action next) { for (int index = 0; index < ctx.MethodSymbol.Parameters.Length; index++) { var symbol = ctx.MethodSymbol.Parameters[index]; var id = ctx.DeclareVariable(symbol.Type); ctx.SetVariable(id, _ => IdentifierName(FormatName(symbol.Name))); ctx.SetParameterToVariable(index, id); } next(); }
private void ToXmlAs(IMarshalContext context, Type type, object value, XmlTextWriter xml) { // Get all the fields of the object FieldInfo[] fields = GetFields(type, value); // Serialize all fields foreach (FieldInfo objectField in fields) { if (ShouldIgnore(objectField, context.IgnoredAttributeType)) { AddNullValue(objectField, xml); continue; } try { object fieldValue = objectField.GetValue(value); if (fieldValue != null && fieldValue.GetType().Name.StartsWith("CProxyType") && !fieldValue.GetType().Name.Contains("Hibernate")) { objectField.SetValue(value, null, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, null); fieldValue = null; } if (fieldValue != null) { IConverter converter = null; if (fieldValue.GetType() == typeof(string) && context.IsCData(type, MarshalContext.auto_property_name(objectField.Name))) { converter = context.GetCDataConverter(); } else { converter = context.GetConverter(fieldValue.GetType()); } converter.ToXml(fieldValue, objectField, xml, context); } else { AddNullValue(objectField, xml); } } catch (Exception e) { throw new ApplicationException("Couldn't set field " + objectField.Name + " in object " + value + ": " + e.Message, e); } } if (type != typeof(object)) { ToXmlAs(context, type.BaseType, value, xml); } }
private static void FromXmlAs(IMarshalContext context, Type type, object value, XmlNode xml) { FieldInfo[] fields = type.GetFields(__flags); Hashtable fieldMap = new Hashtable(fields.Length); foreach (FieldInfo objectField in fields) { string name = objectField.Name; if (objectField.Name.Contains("k__BackingField")) { name = objectField.Name.Replace("<", "").Replace(">k__BackingField", ""); } if (!context.CaseSensitive) { name = name.ToLower(); } fieldMap[name] = objectField; } // Handle all fields foreach (XmlNode child in xml.ChildNodes) { string name = child.Name; if (!context.CaseSensitive) { name = name.ToLower(); } FieldInfo objectField = fieldMap[name] as FieldInfo; if (objectField == null) { continue; } if (child.Attributes["null"] != null) { objectField.SetValue(value, null); continue; } Type objectFieldType = objectField.FieldType; IConverter converter = context.GetConverter(child, ref objectFieldType); try { objectField.SetValue(value, converter.FromXml(value, objectField, objectFieldType, child, context)); } catch (Exception e) { throw new ApplicationException("Couldn't set field " + objectField.Name + " in object " + ": " + e.Message, e); } } if (type != typeof(object)) { FromXmlAs(context, type.BaseType, value, xml); } }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Type type = value != null ? value.GetType() : null; if (typeof (MulticastDelegate).IsAssignableFrom(type)) return; // If dynamic type, use the base type instead if (type.ToString().StartsWith(DynamicInstanceBuilder.__typePrefix)) type = type.BaseType; context.WriteStartTag(type, field, xml); WriteAfterStartTag(value, field, xml, context, type); }
/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { XmlNode node = xml.SelectSingleNode( "base" ); Type baseType = Type.GetType( node.InnerText ); // Get parameter types of the method node = xml.SelectSingleNode( "params" ); Type[] paramTypes = new Type[ node.ChildNodes.Count ]; int index = 0; foreach ( XmlNode param in node.ChildNodes ) paramTypes[ index++ ] = Type.GetType( param.InnerText ); return baseType.GetMethod( xml.SelectSingleNode( "name" ).InnerText, paramTypes ); }
private void WriteAfterStartTag(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context, Type type) { int stackIx = context.GetStackIndex(value); if (stackIx >= 0) xml.WriteAttributeString("ref", stackIx.ToString()); else { context.Stack(value, type); if (value != null) ToXmlAs(context, type, value, xml); } context.WriteEndTag(type, field, xml); }
private void ToXmlAs(IMarshalContext context, Type type, object value, XmlTextWriter xml) { // Get all the fields of the object FieldInfo[] fields = GetFields(type, value); // Serialize all fields foreach (FieldInfo objectField in fields) { if (ShouldIgnore(objectField, context.IgnoredAttributeType)) { AddNullValue(objectField, xml); continue; } try { object fieldValue = objectField.GetValue(value); if (fieldValue != null && fieldValue.GetType().Name.StartsWith("CProxyType") && !fieldValue.GetType().Name.Contains("Hibernate")) { objectField.SetValue(value, null, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, null); fieldValue = null; } if (fieldValue != null) { IConverter converter = null; if (fieldValue.GetType() == typeof(string) && context.IsCData(type, MarshalContext.auto_property_name(objectField.Name))) converter = context.GetCDataConverter(); else converter = context.GetConverter(fieldValue.GetType()); converter.ToXml(fieldValue, objectField, xml, context); } else AddNullValue(objectField, xml); } catch (Exception e) { throw new ApplicationException("Couldn't set field " + objectField.Name + " in object " + value + ": " + e.Message, e); } } if (type != typeof (object)) ToXmlAs(context, type.BaseType, value, xml); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Type type = value.GetType(); if ( type.IsArray ) { byte[] bytes = value as byte[]; context.WriteStartTag( __arrayType, field, xml ); xml.WriteBase64( bytes, 0, bytes.Length ); context.WriteEndTag( __arrayType, field, xml ); } else { context.WriteStartTag( __type, field, xml ); xml.WriteString( value.ToString() ); context.WriteEndTag( __type, field, xml ); } }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Type type = value != null?value.GetType() : null; if (typeof(MulticastDelegate).IsAssignableFrom(type)) { return; } // If dynamic type, use the base type instead if (type.ToString().StartsWith(DynamicInstanceBuilder.__typePrefix)) { type = type.BaseType; } context.WriteStartTag(type, field, xml); WriteAfterStartTag(value, field, xml, context, type); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Type type = value.GetType(); if (type.IsArray) { byte[] bytes = value as byte[]; context.WriteStartTag(__arrayType, field, xml); xml.WriteBase64(bytes, 0, bytes.Length); context.WriteEndTag(__arrayType, field, xml); } else { context.WriteStartTag(__type, field, xml); xml.WriteString(value.ToString()); context.WriteEndTag(__type, field, xml); } }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Type type = value.GetType(); if ( value is char[] ) { char[] buffer = value as char[]; context.WriteStartTag( __arrayType, field, xml ); xml.WriteChars( buffer, 0, buffer.Length ); context.WriteEndTag( __arrayType, field, xml ); } else { context.WriteStartTag( __type, field, xml ); xml.WriteString( value.ToString() ); context.WriteEndTag( __type, field, xml ); } }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Type type = value.GetType(); if (value is char[]) { char[] buffer = value as char[]; context.WriteStartTag(__arrayType, field, xml); xml.WriteChars(buffer, 0, buffer.Length); context.WriteEndTag(__arrayType, field, xml); } else { context.WriteStartTag(__type, field, xml); xml.WriteString(value.ToString()); context.WriteEndTag(__type, field, xml); } }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { context.WriteStartTag(__type, field, xml); string dateTimeWithColon = ((DateTime)value).ToString("yyyy-MM-ddTHH:mm:ss.fff"); xml.WriteString(dateTimeWithColon); //string dateTimeWithColon = ((DateTime)value).ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"); //System.Text.RegularExpressions.Regex // regexTimeZone // = new System.Text.RegularExpressions.Regex(@"\+(\d{2}):(\d{2})", // System.Text.RegularExpressions.RegexOptions.Compiled | // System.Text.RegularExpressions.RegexOptions.IgnoreCase); //string res = regexTimeZone.Replace(dateTimeWithColon, @"+$1$2"); //xml.WriteString(res); context.WriteEndTag(__type, field, xml); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { MethodInfo info = value as MethodInfo; ParameterInfo[] paramList = info.GetParameters(); if ( info.ReflectedType == null ) throw new ConversionException( "Unable to serialize MethodInfo, no reflected type." ); context.WriteStartTag( __type, field, xml ); xml.WriteElementString( "base", context.GetTypeName( info.ReflectedType ) ); xml.WriteElementString( "name", info.Name ); xml.WriteStartElement( "params" ); foreach ( ParameterInfo paramInfo in paramList ) xml.WriteElementString( "param", context.GetTypeName( paramInfo.ParameterType ) ); xml.WriteEndElement(); context.WriteEndTag( __type, field, xml ); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { Array array = value as Array; Type arrayType = array.GetType(); context.WriteStartTag(arrayType, field, xml); int stackIx = context.GetStackIndex(value); if (stackIx >= 0) { xml.WriteAttributeString("ref", stackIx.ToString()); } else { context.Stack(array); foreach (object child in array) { IConverter converter; if (child != null) { converter = context.GetConverter(child.GetType()); } else { converter = context.GetConverter(null); } if (converter == null) { throw new ConversionException("Couldnot find converter for: " + child.GetType() + " having value: " + child); } converter.ToXml(child, null, xml, context); } } context.WriteEndTag(arrayType, field, xml); }
public static void GenericPointerMarshaller(ref IMarshalContext ctx, Action next) { for (int i = 0; i < ctx.LoadTypes.Length - 1; i++) { var lt = ctx.LoadTypes[i]; if (lt is IPointerTypeSymbol pts) { if (pts.PointedAtType is ITypeParameterSymbol tps) { var id = ctx.DeclareVariable ( ctx.Compilation.CreatePointerTypeSymbol (ctx.Compilation.GetSpecialType(SpecialType.System_Void)) ); var baseId = ctx.ParameterVariables[i]; ctx.SetVariable(id, ctx => CastExpression(IdentifierName("void*"), ctx.ResolveVariable(baseId).Value)); ctx.SetParameterToVariable(i, id); } } } next(); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { context.WriteStartTag( __type, field, xml ); xml.WriteString( ( (TimeSpan) value ).Ticks.ToString() ); context.WriteEndTag( __type, field, xml ); }
/// <summary> /// Converts the XmlNode data passed in back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { return TimeSpan.FromTicks( long.Parse( xml.InnerText ) ); }
public virtual void Register(IMarshalContext context) { context.RegisterConverter(type, this); context.Alias(controlTypeAlias, type); }
public MarshalRunner(IMarshalContext context, List <Middleware> middleware) { _context = context; _middleware = middleware; }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { xml.WriteElementString("null", string.Empty); }
/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { return Type.GetType( xml.InnerText ); }
/// <summary> /// Register is called by a MarshalContext to allow the /// converter instance to register itself in the context /// with all appropriate value types and interfaces. /// </summary> public void Register(IMarshalContext context) { context.RegisterConverter( __type, this ); context.Alias( "type", __type ); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { context.WriteStartTag(__type, field, xml); xml.WriteCData(value.ToString()); context.WriteEndTag(__type, field, xml); }
public void Register(IMarshalContext context) { context.RegisterConverter(__type, this); }
/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { if (xml.NodeType == XmlNodeType.CDATA) return string.Intern(xml.Value); return string.Intern(xml.InnerText); }
/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { return Enum.Parse( type, xml.InnerText ); }
/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { return new StringBuilder( string.Intern( xml.InnerText ) ); }
/// <summary> /// Converts the XmlNode data passed in, back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { return(decimal.Parse(xml.InnerText)); }
public virtual void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { context.WriteStartTag(type, field, xml); xml.WriteString(((ControlType)value).Id.ToString()); context.WriteEndTag(type, field, xml); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { context.WriteStartTag( __type, field, xml ); xml.WriteString( (value as Type).AssemblyQualifiedName ); context.WriteEndTag( __type, field, xml ); }
public virtual object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { int lookupId = int.Parse(xml.InnerText); return(ControlType.LookupById(lookupId)); }
/// <summary> /// Register is called by a MarshalContext to allow the /// converter instance to register itself in the context /// with all appropriate value types and interfaces. /// </summary> public void Register(IMarshalContext context) { context.RegisterConverter(__type, this); context.Alias("null", __type); }
/// <summary> /// Converts the object passed in to its XML representation. /// The XML string is written on the XmlTextWriter. /// </summary> public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { context.WriteStartTag(__type, field, xml); xml.WriteString((value as Type).AssemblyQualifiedName); context.WriteEndTag(__type, field, xml); }
/// <summary> /// Converts the XmlNode data passed in back to an actual /// .NET instance object. /// </summary> /// <returns>Object created from the XML.</returns> public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { return(null); }
/// <summary> /// Register is called by a MarshalContext to allow the /// converter instance to register itself in the context /// with all appropriate value types and interfaces. /// </summary> public void Register(IMarshalContext context) { context.RegisterConverter(GetType(), this); }
public virtual object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context) { int lookupId = int.Parse(xml.InnerText); return ControlType.LookupById(lookupId); }
public virtual void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context) { context.WriteStartTag(type, field, xml); xml.WriteString(((ControlType) value).Id.ToString()); context.WriteEndTag(type, field, xml); }