Datei: NDOEnhancer/ILCode/ILCustomElement.cs
Last Commit (0508969)
| 1 | // |
| 2 | // Copyright ( c) 2002-2022 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System; |
| 24 | using System.Globalization; |
| 25 | |
| 26 | namespace NDOEnhancer. ILCode |
| 27 | { |
| 28 | ····/// <summary> |
| 29 | ····/// Summary description for ILCustomElement. |
| 30 | ····/// </summary> |
| 31 | ····internal class ILCustomElement : ILElement |
| 32 | ····{ |
| 33 | /* |
| 34 | ······.custom instance void [NDO]NDO.Linq.ServerFunctionAttribute::.ctor(string) = ( 01 00 15 4D 49 4E 5F 41 43 54 49 56 45 5F 52 4F·· // ...MIN_ACTIVE_RO |
| 35 | ···················································································· 57 56 45 52 53 49 4F 4E 00 00 )·················· // WVERSION..········ |
| 36 | ········ */ |
| 37 | |
| 38 | ········public ILCustomElement( string firstLine, ILElement owner ) |
| 39 | ············: base( firstLine, owner ) |
| 40 | ········{ |
| 41 | ········} |
| 42 | |
| 43 | ········internal class ILCustomElementType : ILElementType |
| 44 | ········{ |
| 45 | ············public ILCustomElementType() |
| 46 | : base( ". custom", typeof( ILCustomElement ) ) |
| 47 | ············{ |
| 48 | ············} |
| 49 | ········} |
| 50 | |
| 51 | private static ILElementType m_elementType = new ILCustomElementType( ) ; |
| 52 | ········private AttributeInfo attributeInfo = null; |
| 53 | |
| 54 | |
| 55 | private void Resolve( ) |
| 56 | ········{ |
| 57 | if ( this. attributeInfo == null) |
| 58 | ················this.attributeInfo = GetAttributeInfo(); |
| 59 | ········} |
| 60 | |
| 61 | ········public bool |
| 62 | IsAttribute( Type type ) |
| 63 | ········{ |
| 64 | Resolve( ) ; |
| 65 | return this. attributeInfo. TypeName == type. FullName; |
| 66 | ········} |
| 67 | |
| 68 | |
| 69 | ········private object |
| 70 | ReadParam( byte[] bytes, Type type, ref int pos ) |
| 71 | ········{ |
| 72 | if ( type. FullName == "System. String" || type. FullName == "System. Type") |
| 73 | ············{ |
| 74 | ················string para; |
| 75 | ················int len = PackedLength.Read(bytes, ref pos); |
| 76 | ················if (len == -1) |
| 77 | ····················para = null; |
| 78 | ················else |
| 79 | para = new System. Text. UTF8Encoding( ) . GetString( bytes, pos + 1, len ) ; |
| 80 | ················//string para = new string( chars, pos + 1, bytes[pos]); |
| 81 | ················pos += 1 + bytes[pos]; |
| 82 | ················if (para != null && para != string.Empty) |
| 83 | ················{ |
| 84 | ····················if (para[para.Length - 1] == '\0') |
| 85 | para = para. Substring( 0, para. Length - 1 ) ; |
| 86 | ················} |
| 87 | ················return para; |
| 88 | ············} |
| 89 | else if ( type == typeof( System. Boolean ) ) |
| 90 | ············{ |
| 91 | ················bool para = Convert.ToBoolean( bytes[pos] ); |
| 92 | ················pos += 1; |
| 93 | ················return para; |
| 94 | ············} |
| 95 | else if ( type == typeof( System. Char ) ) |
| 96 | ············{ |
| 97 | ················char para = Convert.ToChar( bytes[pos+1] * 256 + bytes[pos] ); |
| 98 | ················pos += 2; |
| 99 | ················return para; |
| 100 | ············} |
| 101 | else if ( type == typeof( System. Int16 ) ) |
| 102 | ············{ |
| 103 | ················short para = Convert.ToInt16( bytes[pos+1] * 256 + bytes[pos] ); |
| 104 | ················pos += 2; |
| 105 | ················return para; |
| 106 | ············} |
| 107 | else if ( type == typeof( System. Int32 ) ) |
| 108 | ············{ |
| 109 | ················int para = ((bytes[pos+3] * 256 + bytes[pos+2]) * 256 + bytes[pos+1]) * 256 + bytes[pos]; |
| 110 | ················pos += 4; |
| 111 | ················return para; |
| 112 | ············} |
| 113 | else if ( type. FullName == "NDO. RelationInfo") |
| 114 | ············{ |
| 115 | ················short para = Convert.ToInt16( bytes[pos+1] * 256 + bytes[pos] ); |
| 116 | ················pos += 2; |
| 117 | ················return (NDO.RelationInfo) para; |
| 118 | ············} |
| 119 | ············else if (typeof(System.Enum).IsAssignableFrom( type ) ) |
| 120 | ············{ |
| 121 | ················int para = ((bytes[pos+3] * 256 + bytes[pos+2]) * 256 + bytes[pos+1]) * 256 + bytes[pos]; |
| 122 | ················pos += 4; |
| 123 | ················return Enum.ToObject( type, para ); |
| 124 | ············} |
| 125 | |
| 126 | ············MessageAdapter ma = new MessageAdapter(); |
| 127 | ma. ShowError( $"Relation Attribute: Unknown type in attribute parameter list: { type. FullName} , owner type: { ( this. Owner as ILClassElement ) ?. Name ?? "-"} " ) ; |
| 128 | |
| 129 | ············return null; |
| 130 | ········} |
| 131 | |
| 132 | |
| 133 | ········internal class AttributeInfo |
| 134 | ········{ |
| 135 | public string TypeName; |
| 136 | ············public string AssemblyName; |
| 137 | ············public string[] ParamTypeNames = new string[]{}; |
| 138 | ············public object[] ParamValues = new object[]{}; |
| 139 | ········} |
| 140 | |
| 141 | |
| 142 | ········public AttributeInfo |
| 143 | GetAttributeInfo( ) |
| 144 | ········{ |
| 145 | ············string text = ""; |
| 146 | |
| 147 | for ( int i = 0; i < LineCount; i++) |
| 148 | ············{ |
| 149 | string line = GetLine( i ) ; |
| 150 | |
| 151 | ················int cmt = line.IndexOf( "//" ); |
| 152 | if ( -1 < cmt) |
| 153 | ····················line = line.Substring( 0, cmt ).Trim(); |
| 154 | |
| 155 | ················text += " " + line; |
| 156 | ············} |
| 157 | |
| 158 | ············int start, end; |
| 159 | |
| 160 | ············// assembly name |
| 161 | |
| 162 | ············start = text.IndexOf( "[" ) + 1; |
| 163 | end = text. IndexOf( "]", start ) ; |
| 164 | string assName = StripComment( text. Substring( start, end - start ) ) ; |
| 165 | |
| 166 | ············// type name |
| 167 | |
| 168 | ············start = text.IndexOf( "]" ) + 1; |
| 169 | end = text. IndexOf( "::", start ) ; |
| 170 | string typeName = StripComment( text. Substring( start, end - start ) ) ; |
| 171 | |
| 172 | ············// constructor signature |
| 173 | |
| 174 | ············start = text.IndexOf( "(" ) + 1; |
| 175 | end = text. IndexOf( ") ", start ) ; |
| 176 | string signature = StripComment( text. Substring( start, end - start ) ) ; |
| 177 | |
| 178 | ············// parameter bytes |
| 179 | |
| 180 | ············start = text.IndexOf( "= (" ) + 3; |
| 181 | end = text. IndexOf( ") ", start ) ; |
| 182 | string byteText = text. Substring( start, end - start ) . Trim( ) ; |
| 183 | |
| 184 | char[] spc = { ' ' } ; |
| 185 | ············string[] byteStrings = byteText.Split( spc ); |
| 186 | byte[] bytes = new byte[byteStrings. Length]; |
| 187 | ············//············char[]···· chars········ = new char[byteStrings.Length]; |
| 188 | |
| 189 | for ( int i = 0; i < byteStrings. Length; i++) |
| 190 | ············{ |
| 191 | ················bytes[i] = Byte.Parse( byteStrings[i], NumberStyles.HexNumber ); |
| 192 | ················//················chars[i] = Convert.ToChar( bytes[i] ); |
| 193 | ············} |
| 194 | |
| 195 | ············//············char[] chars = new System.Text.UTF8Encoding().GetChars(bytes); |
| 196 | |
| 197 | ············//············Type attributeType = Type.GetType( typeName + ", " + assName ); |
| 198 | ············//············if ( null == attributeType ) |
| 199 | ············//················return null; |
| 200 | |
| 201 | ············char·· comma =··','; |
| 202 | ············string[] paramTypeNames = new string[]{}; |
| 203 | ············object[] paramValues = new object[]{}; |
| 204 | ············Type[] paramTypes = new Type[]{}; |
| 205 | ············//CustomAttrib starts with a Prolog – an unsigned int16, with value 0x0001 |
| 206 | ············int pos = 2; |
| 207 | ············if (signature != "") |
| 208 | ············{ |
| 209 | ················paramTypeNames = signature.Split( comma ); |
| 210 | paramTypes = new Type[paramTypeNames. Length]; |
| 211 | paramValues = new Object[paramTypeNames. Length]; |
| 212 | |
| 213 | for ( int i = 0; i < paramTypeNames. Length; i++) |
| 214 | ················{ |
| 215 | ····················string paramTypeName = paramTypeNames[i].Trim(); |
| 216 | if ( paramTypeName == "string" || paramTypeName. IndexOf( "System. String" ) > -1) |
| 217 | ····················{ |
| 218 | ························paramTypeNames[i] = "System.String"; |
| 219 | paramTypes[i] = typeof( string ) ; |
| 220 | ····················} |
| 221 | else if ( paramTypeName == "bool") |
| 222 | ····················{ |
| 223 | paramTypes[i] = typeof( bool ) ; |
| 224 | ························paramTypeNames[i] = "System.Boolean"; |
| 225 | ····················} |
| 226 | else if ( paramTypeName == "char") |
| 227 | ····················{ |
| 228 | paramTypes[i] = typeof( char ) ; |
| 229 | ························paramTypeNames[i] = "System.Char"; |
| 230 | ····················} |
| 231 | else if ( paramTypeName == "short" || paramTypeName == "int16") |
| 232 | ····················{ |
| 233 | ························paramTypeNames[i] = "System.Int16"; |
| 234 | paramTypes[i] = typeof( System. Int16 ) ; |
| 235 | ····················} |
| 236 | else if ( paramTypeName == "int" || paramTypeName == "int32") |
| 237 | ····················{ |
| 238 | ························paramTypeNames[i] = "System.Int32"; |
| 239 | paramTypes[i] = typeof( System. Int32 ) ; |
| 240 | ····················} |
| 241 | ····················// Achtung: System.Type wird als string abgespeichert!!! |
| 242 | else if ( paramTypeName. IndexOf( "[mscorlib" ) > -1 && paramTypeName. IndexOf( "System. Type" ) > -1) |
| 243 | ····················{ |
| 244 | paramTypes[i] = typeof( System. String ) ; |
| 245 | ························paramTypeNames[i] = "System.Type"; |
| 246 | ····················} |
| 247 | else if ( paramTypeName == "valuetype [NDO]NDO. RelationInfo") |
| 248 | ····················{ |
| 249 | paramTypes[i] = typeof( NDO. RelationInfo ) ; |
| 250 | ························paramTypeNames[i] = "NDO.RelationInfo, NDO"; |
| 251 | ····················} |
| 252 | ····················else |
| 253 | ····················{ |
| 254 | ························var paramTypeString = paramTypeName.Substring(paramTypeName.IndexOf(']') + 1); |
| 255 | ························var t = Type.GetType( paramTypeString ); |
| 256 | ························if (t != null) |
| 257 | ························{ |
| 258 | ····························paramTypes[i] = t; |
| 259 | ····························paramTypeNames[i] = "paramTypeString"; |
| 260 | ························} |
| 261 | ························else |
| 262 | throw new Exception( $"Relation Attribute: Unknown type in attribute parameter list: { paramTypeName} , type: { ( this. Owner as ILClassElement ) ?. Name ?? ""} " ) ; |
| 263 | ····················} |
| 264 | |
| 265 | ····················//paramTypes[i]··= Type.GetType( paramTypeNames[i] ); |
| 266 | paramValues[i] = ReadParam( bytes, paramTypes[i], ref pos ) ; |
| 267 | ················} |
| 268 | ············} |
| 269 | ············//············ConstructorInfo ci···· = attributeType.GetConstructor( paramTypes ); |
| 270 | AttributeInfo attr = new AttributeInfo( ) ; |
| 271 | attr. TypeName = typeName; |
| 272 | ············attr.AssemblyName = assName; |
| 273 | ············attr.ParamTypeNames = paramTypeNames; |
| 274 | ············attr.ParamValues = paramValues; |
| 275 | |
| 276 | //TODO: Should we ever need to analyze named parameters |
| 277 | // we'll have to add lots of code here. |
| 278 | ············// We'd be better off, if we analyzed the IL code using the ECMA spec. |
| 279 | |
| 280 | ············//············short count = (short) readParam( bytes, chars, Type.GetType( "System.Int16" ), ref pos ); |
| 281 | ············// |
| 282 | ············//············for ( short i=0; i<count; i++ ) |
| 283 | ············//············{ |
| 284 | ············//················pos += 2; |
| 285 | ············// |
| 286 | ············//················string propName = readParam( bytes, chars, Type.GetType( "System.String" ), ref pos ) as string; |
| 287 | ············// |
| 288 | ············//················PropertyInfo pi = attributeType.GetProperty( propName ); |
| 289 | ············// |
| 290 | ············//················object propVal = readParam( bytes, chars, pi.PropertyType, ref pos ); |
| 291 | ············// |
| 292 | ············//················pi.SetValue( attr, propVal, null ); |
| 293 | ············//············} |
| 294 | |
| 295 | ············this.attributeInfo = attr; |
| 296 | ············return attr; |
| 297 | ········} |
| 298 | |
| 299 | ········public void |
| 300 | ············replaceLines( string firstLine ) |
| 301 | ········{ |
| 302 | ClearLines( ) ; |
| 303 | |
| 304 | AddLine( firstLine ) ; |
| 305 | ········} |
| 306 | |
| 307 | |
| 308 | ····} |
| 309 | } |
| 310 |
New Commit (f892a37)
| 1 | // |
| 2 | // Copyright ( c) 2002-2016 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System; |
| 24 | using System.Globalization; |
| 25 | using System.Diagnostics; |
| 26 | using System.Reflection; |
| 27 | using NDOEnhancer; |
| 28 | |
| 29 | // using com. poet. util; |
| 30 | |
| 31 | namespace ILCode |
| 32 | { |
| 33 | ····/// <summary> |
| 34 | ····/// Summary description for ILCustomElement. |
| 35 | ····/// </summary> |
| 36 | ····internal class ILCustomElement : ILElement |
| 37 | ····{ |
| 38 | ········public ILCustomElement() |
| 39 | ············: base( false ) |
| 40 | ········{ |
| 41 | } |
| 42 | |
| 43 | ········public ILCustomElement( string firstLine, ILElement owner ) |
| 44 | ············: base( firstLine, owner ) |
| 45 | ········{ |
| 46 | ········} |
| 47 | /* |
| 48 | ········public ILCustomElement(string typeName, object[] parameters) |
| 49 | ············: base ( false ) |
| 50 | ········{ |
| 51 | ············string param = makeParameters(parameters); |
| 52 | ············//this.addLine |
| 53 | ········} |
| 54 | */ |
| 55 | ········internal class ILCustomElementType : ILElementType |
| 56 | ········{ |
| 57 | ············public ILCustomElementType() |
| 58 | : base( ". custom", typeof ( ILCustomElement) ) |
| 59 | ············{ |
| 60 | ············} |
| 61 | ········} |
| 62 | |
| 63 | ········internal class Iterator : ILElementIterator |
| 64 | ········{ |
| 65 | ············public Iterator( ILElement element ) |
| 66 | ················: base( element, typeof (ILCustomElement) ) |
| 67 | ············{ |
| 68 | ············} |
| 69 | |
| 70 | ············public new ILCustomElement |
| 71 | ················getNext() |
| 72 | ············{ |
| 73 | ················return base.getNext() as ILCustomElement; |
| 74 | ············} |
| 75 | ········} |
| 76 | |
| 77 | private static ILElementType m_elementType = new ILCustomElementType( ) ; |
| 78 | ········ |
| 79 | ········public static void |
| 80 | ············initialize() |
| 81 | ········{ |
| 82 | ········} |
| 83 | |
| 84 | public static ILCustomElement. Iterator |
| 85 | ············getIterator( ILElement element ) |
| 86 | ········{ |
| 87 | return new Iterator( element ) ; |
| 88 | ········} |
| 89 | |
| 90 | ········public bool |
| 91 | isAttribute( Type type ) |
| 92 | ········{ |
| 93 | if ( null == type ) |
| 94 | return false; |
| 95 | |
| 96 | ············string firstLine = getLine( 0 ); |
| 97 | |
| 98 | ············return (-1 < firstLine.IndexOf( type.FullName )); |
| 99 | ········} |
| 100 | |
| 101 | /* |
| 102 | ········private string |
| 103 | ············makeParameters(object[] parameters) |
| 104 | ········{ |
| 105 | ············return null; |
| 106 | ········} |
| 107 | */ |
| 108 | ········private object |
| 109 | readParam( byte[] bytes, Type type, ref int pos ) |
| 110 | ········{ |
| 111 | if ( type. FullName == "System. String" || type. FullName == "System. Type") |
| 112 | ············{ |
| 113 | ················string para; |
| 114 | ················int len = PackedLength.Read(bytes, ref pos); |
| 115 | ················if (len == -1) |
| 116 | ····················para = null; |
| 117 | ················else |
| 118 | para = new System. Text. UTF8Encoding( ) . GetString( bytes, pos + 1, len) ; |
| 119 | ················//string para = new string( chars, pos + 1, bytes[pos]); |
| 120 | ················pos += 1 + bytes[pos]; |
| 121 | ················if (para != null && para != string.Empty) |
| 122 | ················{ |
| 123 | ····················if (para[para.Length - 1] == '\0') |
| 124 | para = para. Substring( 0, para. Length - 1) ; |
| 125 | ················} |
| 126 | ················return para; |
| 127 | ············} |
| 128 | else if ( type == typeof( System. Boolean) ) |
| 129 | ············{ |
| 130 | ················bool para = Convert.ToBoolean( bytes[pos] ); |
| 131 | ················pos += 1; |
| 132 | ················return para; |
| 133 | ············} |
| 134 | else if ( type == typeof( System. Char) ) |
| 135 | ············{ |
| 136 | ················char para = Convert.ToChar( bytes[pos+1] * 256 + bytes[pos] ); |
| 137 | ················pos += 2; |
| 138 | ················return para; |
| 139 | ············} |
| 140 | else if ( type == typeof( System. Int16) ) |
| 141 | ············{ |
| 142 | ················short para = Convert.ToInt16( bytes[pos+1] * 256 + bytes[pos] ); |
| 143 | ················pos += 2; |
| 144 | ················return para; |
| 145 | ············} |
| 146 | else if ( type == typeof( System. Int32) ) |
| 147 | ············{ |
| 148 | ················int para = ((bytes[pos+3] * 256 + bytes[pos+2]) * 256 + bytes[pos+1]) * 256 + bytes[pos]; |
| 149 | ················pos += 4; |
| 150 | ················return para; |
| 151 | ············} |
| 152 | else if ( type. FullName == "NDO. RelationInfo" ) |
| 153 | ············{ |
| 154 | ················short para = Convert.ToInt16( bytes[pos+1] * 256 + bytes[pos] ); |
| 155 | ················pos += 2; |
| 156 | ················return (NDO.RelationInfo) para; |
| 157 | ············} |
| 158 | ············else if (typeof(System.Enum).IsAssignableFrom( type ) ) |
| 159 | ············{ |
| 160 | ················int para = ((bytes[pos+3] * 256 + bytes[pos+2]) * 256 + bytes[pos+1]) * 256 + bytes[pos]; |
| 161 | ················pos += 4; |
| 162 | ················return Enum.ToObject( type, para ); |
| 163 | ············} |
| 164 | |
| 165 | ············MessageAdapter ma = new MessageAdapter(); |
| 166 | ma. ShowError( $"Relation Attribute: Unknown type in attribute parameter list: { type. FullName} , owner type: { ( this. getOwner( ) as ILClassElement ) ?. getName( ) ?? "-"} " ) ; |
| 167 | |
| 168 | ············return null; |
| 169 | ········} |
| 170 | |
| 171 | |
| 172 | ········internal class AttributeInfo |
| 173 | ········{ |
| 174 | public string Name; |
| 175 | ············public string AssemblyName; |
| 176 | ············public string[] ParamTypeNames = new string[]{}; |
| 177 | ············public object[] ParamValues = new object[]{}; |
| 178 | ········} |
| 179 | |
| 180 | |
| 181 | ········public AttributeInfo |
| 182 | getAttributeInfo( ) |
| 183 | ········{ |
| 184 | ············string text = ""; |
| 185 | |
| 186 | for ( int i=0; i<getLineCount( ) ; i++ ) |
| 187 | ············{ |
| 188 | string line = getLine( i ) ; |
| 189 | ················ |
| 190 | ················int cmt = line.IndexOf( "//" ); |
| 191 | if ( -1 < cmt ) |
| 192 | ····················line = line.Substring( 0, cmt ).Trim(); |
| 193 | ················ |
| 194 | ················text += " " + line; |
| 195 | ············} |
| 196 | |
| 197 | ············int start, end; |
| 198 | |
| 199 | ············// assembly name |
| 200 | |
| 201 | ············start = text.IndexOf( "[" ) + 1; |
| 202 | end = text. IndexOf( "]", start ) ; |
| 203 | string assName = stripComment( text. Substring( start, end - start ) ) ; |
| 204 | |
| 205 | ············// type name |
| 206 | |
| 207 | ············start = text.IndexOf( "]" ) + 1; |
| 208 | end = text. IndexOf( "::", start ) ; |
| 209 | string typeName = stripComment( text. Substring( start, end - start ) ) ; |
| 210 | |
| 211 | ············// constructor signature |
| 212 | |
| 213 | ············start = text.IndexOf( "(" ) + 1; |
| 214 | end = text. IndexOf( ") ", start ) ; |
| 215 | string signature = stripComment( text. Substring( start, end - start ) ) ; |
| 216 | |
| 217 | ············// parameter bytes |
| 218 | |
| 219 | ············start = text.IndexOf( "= (" ) + 3; |
| 220 | end = text. IndexOf( ") ", start ) ; |
| 221 | string byteText = text. Substring( start, end - start ) . Trim( ) ; |
| 222 | |
| 223 | char[] spc = { ' ' } ; |
| 224 | ············string[] byteStrings = byteText.Split( spc ); |
| 225 | byte[] bytes = new byte[byteStrings. Length]; |
| 226 | ············//············char[]···· chars········ = new char[byteStrings.Length]; |
| 227 | |
| 228 | for ( int i=0; i<byteStrings. Length; i++ ) |
| 229 | ············{ |
| 230 | ················bytes[i] = Byte.Parse( byteStrings[i], NumberStyles.HexNumber ); |
| 231 | ················//················chars[i] = Convert.ToChar( bytes[i] ); |
| 232 | ············} |
| 233 | |
| 234 | //············char[] chars = new System.Text.UTF8Encoding().GetChars(bytes); |
| 235 | ············ |
| 236 | ············//············Type attributeType = Type.GetType( typeName + ", " + assName ); |
| 237 | ············//············if ( null == attributeType ) |
| 238 | ············//················return null; |
| 239 | |
| 240 | ············char·· comma =··','; |
| 241 | ············string[] paramTypeNames = new string[]{}; |
| 242 | ············object[] paramValues = new object[]{}; |
| 243 | ············Type[] paramTypes = new Type[]{}; |
| 244 | ············//CustomAttrib starts with a Prolog – an unsigned int16, with value 0x0001 |
| 245 | ············int pos = 2; |
| 246 | ············if (signature != "") |
| 247 | ············{ |
| 248 | ················paramTypeNames = signature.Split( comma ); |
| 249 | paramTypes = new Type[paramTypeNames. Length]; |
| 250 | paramValues = new Object[paramTypeNames. Length]; |
| 251 | |
| 252 | for ( int i=0; i<paramTypeNames. Length; i++ ) |
| 253 | ················{ |
| 254 | ····················string paramTypeName = paramTypeNames[i].Trim(); |
| 255 | if ( paramTypeName == "string" || paramTypeName. IndexOf( "System. String") > -1) |
| 256 | ····················{ |
| 257 | ························paramTypeNames[i] = "System.String"; |
| 258 | paramTypes[i] = typeof( string) ; |
| 259 | ····················} |
| 260 | else if ( paramTypeName == "bool" ) |
| 261 | ····················{ |
| 262 | paramTypes[i] = typeof( bool) ; |
| 263 | ························paramTypeNames[i] = "System.Boolean"; |
| 264 | ····················} |
| 265 | else if ( paramTypeName == "char" ) |
| 266 | ····················{ |
| 267 | paramTypes[i] = typeof( char) ; |
| 268 | ························paramTypeNames[i] = "System.Char"; |
| 269 | ····················} |
| 270 | else if ( paramTypeName == "short" || paramTypeName == "int16" ) |
| 271 | ····················{ |
| 272 | ························paramTypeNames[i] = "System.Int16"; |
| 273 | paramTypes[i] = typeof( System. Int16) ; |
| 274 | ····················} |
| 275 | else if ( paramTypeName == "int" || paramTypeName == "int32") |
| 276 | ····················{ |
| 277 | ························paramTypeNames[i] = "System.Int32"; |
| 278 | paramTypes[i] = typeof( System. Int32) ; |
| 279 | ····················} |
| 280 | ························// Achtung: System.Type wird als string abgespeichert!!! |
| 281 | else if ( paramTypeName. IndexOf( "[mscorlib") > -1 && paramTypeName. IndexOf( "System. Type") > -1 ) |
| 282 | ····················{ |
| 283 | paramTypes[i] = typeof( System. String) ; |
| 284 | ························paramTypeNames[i] = "System.Type";························ |
| 285 | ····················} |
| 286 | else if ( paramTypeName == "valuetype [NDO]NDO. RelationInfo" ) |
| 287 | ····················{ |
| 288 | paramTypes[i] = typeof( NDO. RelationInfo) ; |
| 289 | ························paramTypeNames[i] = "NDO.RelationInfo, NDO";························ |
| 290 | ····················} |
| 291 | ····················else |
| 292 | ····················{ |
| 293 | ························var paramTypeString = paramTypeName.Substring(paramTypeName.IndexOf(']') + 1); |
| 294 | ························var t = Type.GetType( paramTypeString ); |
| 295 | ························if (t != null) |
| 296 | ························{ |
| 297 | ····························paramTypes[i] = t; |
| 298 | ····························paramTypeNames[i] = "paramTypeString"; |
| 299 | ························} |
| 300 | ························else |
| 301 | throw new Exception( $"Relation Attribute: Unknown type in attribute parameter list: { paramTypeName} , type: { ( this. getOwner( ) as ILClassElement ) ?. getName( ) ?? ""} " ) ; |
| 302 | ····················} |
| 303 | |
| 304 | ····················//paramTypes[i]··= Type.GetType( paramTypeNames[i] ); |
| 305 | paramValues[i] = readParam( bytes, paramTypes[i], ref pos ) ; |
| 306 | ················} |
| 307 | ············} |
| 308 | ············//············ConstructorInfo ci···· = attributeType.GetConstructor( paramTypes ); |
| 309 | AttributeInfo attr = new AttributeInfo( ) ; |
| 310 | attr. Name = typeName; |
| 311 | ············attr.AssemblyName = assName; |
| 312 | ············attr.ParamTypeNames = paramTypeNames; |
| 313 | ············attr.ParamValues = paramValues; |
| 314 | |
| 315 | //TODO: sollten jemals benannte Parameter dazukommen |
| 316 | //TODO: müssten wir hier einigen Code hinzufügen |
| 317 | |
| 318 | ············//············short count = (short) readParam( bytes, chars, Type.GetType( "System.Int16" ), ref pos ); |
| 319 | ············// |
| 320 | ············//············for ( short i=0; i<count; i++ ) |
| 321 | ············//············{ |
| 322 | ············//················pos += 2; |
| 323 | ············// |
| 324 | ············//················string propName = readParam( bytes, chars, Type.GetType( "System.String" ), ref pos ) as string; |
| 325 | ············// |
| 326 | ············//················PropertyInfo pi = attributeType.GetProperty( propName ); |
| 327 | ············// |
| 328 | ············//················object propVal = readParam( bytes, chars, pi.PropertyType, ref pos ); |
| 329 | ············// |
| 330 | ············//················pi.SetValue( attr, propVal, null ); |
| 331 | ············//············} |
| 332 | |
| 333 | ············return attr; |
| 334 | ········} |
| 335 | |
| 336 | ········public void |
| 337 | ············replaceLines( string firstLine ) |
| 338 | ········{ |
| 339 | clearLines( ) ; |
| 340 | |
| 341 | addLine( firstLine ) ; |
| 342 | ········} |
| 343 | |
| 344 | ···· |
| 345 | ····} |
| 346 | } |
| 347 |