1 // ==++== 2 // 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // 5 // ==--== 6 /*============================================================ 7 ** 8 ** File: RemotingAttributes.cs 9 ** 10 ** Purpose: Custom attributes for modifying remoting interactions. 11 ** 12 ** 13 ===========================================================*/ 14 15 namespace System.Runtime.Remoting.Metadata 16 { 17 using System.Runtime.Remoting.Messaging; 18 using System.Runtime.Remoting.Metadata; 19 using System.Reflection; 20 using System.Threading; 21 using System.Runtime.Serialization; 22 using TypeInfo = System.Runtime.Remoting.TypeInfo; 23 24 // This is the data we store in MemberInfo.CachedData, mainly to cache custom 25 // attributes. 26 internal abstract class RemotingCachedData 27 { 28 private SoapAttribute _soapAttr = null; // Soap related attributes derive from SoapAttribute 29 30 // Retrieve SOAP attribute info for _mi (or create for caching if not specified) GetSoapAttribute()31 internal SoapAttribute GetSoapAttribute() 32 { 33 if (_soapAttr == null) 34 { 35 lock (this) 36 { 37 if (_soapAttr == null) 38 { 39 _soapAttr = GetSoapAttributeNoLock(); 40 } // if (_soapAttr == null) 41 } // lock (this) 42 } 43 44 return _soapAttr; 45 } // GetSoapAttribute 46 GetSoapAttributeNoLock()47 abstract internal SoapAttribute GetSoapAttributeNoLock(); 48 } // class RemotingCachedData 49 50 51 internal class RemotingFieldCachedData : RemotingCachedData 52 { 53 private FieldInfo RI; // reflection structure on which this data structure is stored 54 RemotingFieldCachedData(RuntimeFieldInfo ri)55 internal RemotingFieldCachedData(RuntimeFieldInfo ri) 56 { 57 RI = ri; 58 } RemotingFieldCachedData(SerializationFieldInfo ri)59 internal RemotingFieldCachedData(SerializationFieldInfo ri) 60 { 61 RI = ri; 62 } 63 64 // Retrieve SOAP attribute info for _mi (or create for caching if not specified) GetSoapAttributeNoLock()65 internal override SoapAttribute GetSoapAttributeNoLock() 66 { 67 SoapAttribute tempSoapAttr = null; 68 69 Object[] attrs = RI.GetCustomAttributes(typeof(SoapFieldAttribute), false); 70 if ((attrs != null) && (attrs.Length != 0)) 71 tempSoapAttr = (SoapAttribute)attrs[0]; 72 else 73 tempSoapAttr = new SoapFieldAttribute(); 74 75 // IMPORTANT: This has to be done for certain values to be automatically 76 // generated in the attribute. 77 tempSoapAttr.SetReflectInfo(RI); 78 79 return tempSoapAttr; 80 } 81 } 82 83 84 internal class RemotingParameterCachedData : RemotingCachedData 85 { 86 private RuntimeParameterInfo RI; // reflection structure on which this data structure is stored 87 RemotingParameterCachedData(RuntimeParameterInfo ri)88 internal RemotingParameterCachedData(RuntimeParameterInfo ri) 89 { 90 RI = ri; 91 } 92 GetSoapAttributeNoLock()93 internal override SoapAttribute GetSoapAttributeNoLock() 94 { 95 SoapAttribute tempSoapAttr = null; 96 97 Object[] attrs = RI.GetCustomAttributes(typeof(SoapParameterAttribute), true); 98 if ((attrs != null) && (attrs.Length != 0)) 99 tempSoapAttr = (SoapParameterAttribute)attrs[0]; 100 else 101 tempSoapAttr = new SoapParameterAttribute(); 102 103 // IMPORTANT: This has to be done for certain values to be automatically 104 // generated in the attribute. 105 tempSoapAttr.SetReflectInfo(RI); 106 107 return tempSoapAttr; 108 } 109 } 110 111 112 internal class RemotingTypeCachedData : RemotingCachedData 113 { 114 private RuntimeType RI; 115 private class LastCalledMethodClass 116 { 117 public String methodName; 118 public MethodBase MB; 119 } 120 121 private LastCalledMethodClass _lastMethodCalled; // cache for last method that was called 122 private TypeInfo _typeInfo; // type info to be used for ObjRef's of this type 123 private String _qualifiedTypeName; 124 private String _assemblyName; 125 private String _simpleAssemblyName; // (no strong name, version, etc.) 126 127 RemotingTypeCachedData(RuntimeType ri)128 internal RemotingTypeCachedData(RuntimeType ri) 129 { 130 RI = ri; 131 } 132 GetSoapAttributeNoLock()133 internal override SoapAttribute GetSoapAttributeNoLock() 134 { 135 SoapAttribute tempSoapAttr = null; 136 137 Object[] attrs = RI.GetCustomAttributes(typeof(SoapTypeAttribute), true); 138 if ((attrs != null) && (attrs.Length != 0)) 139 tempSoapAttr = (SoapAttribute)attrs[0]; 140 else 141 tempSoapAttr = new SoapTypeAttribute(); 142 143 // IMPORTANT: This has to be done for certain values to be automatically 144 // generated in the attribute. 145 tempSoapAttr.SetReflectInfo(RI); 146 147 return tempSoapAttr; 148 } 149 GetLastCalledMethod(String newMeth)150 internal MethodBase GetLastCalledMethod(String newMeth) 151 { 152 LastCalledMethodClass lastMeth = _lastMethodCalled; 153 if (lastMeth == null) 154 return null; 155 156 String methodName = lastMeth.methodName; 157 MethodBase mbToReturn = lastMeth.MB; 158 159 if (mbToReturn==null || methodName==null) 160 return null; 161 162 if (methodName.Equals(newMeth)) 163 return mbToReturn; 164 165 return null; 166 } // GetLastCalledMethod 167 SetLastCalledMethod(String newMethName, MethodBase newMB)168 internal void SetLastCalledMethod(String newMethName, MethodBase newMB) 169 { 170 LastCalledMethodClass lastMeth = new LastCalledMethodClass(); 171 lastMeth.methodName = newMethName; 172 lastMeth.MB = newMB; 173 174 _lastMethodCalled = lastMeth; 175 } // SetLastCalledMethod 176 177 178 // Retrieve TypeInfo object to be used in ObjRef. 179 internal TypeInfo TypeInfo 180 { 181 [System.Security.SecurityCritical] // auto-generated 182 get 183 { 184 if (_typeInfo == null) 185 _typeInfo = new TypeInfo(RI); 186 187 return _typeInfo; 188 } 189 } // TypeInfo 190 191 192 internal String QualifiedTypeName 193 { 194 [System.Security.SecurityCritical] // auto-generated 195 get 196 { 197 if (_qualifiedTypeName == null) 198 _qualifiedTypeName = RemotingServices.DetermineDefaultQualifiedTypeName(RI); 199 200 return _qualifiedTypeName; 201 } 202 } // QualifiedTypeName 203 204 205 internal String AssemblyName 206 { 207 get 208 { 209 if (_assemblyName == null) 210 _assemblyName = RI.Module.Assembly.FullName; 211 212 return _assemblyName; 213 } 214 } // AssemblyName 215 216 217 internal String SimpleAssemblyName 218 { 219 [System.Security.SecurityCritical] // auto-generated 220 get 221 { 222 if (_simpleAssemblyName == null) 223 _simpleAssemblyName = RI.GetRuntimeAssembly().GetSimpleName(); 224 225 return _simpleAssemblyName; 226 } 227 } // SimpleAssemblyName 228 229 } // class RemotingTypeCachedData 230 231 232 internal class RemotingMethodCachedData : RemotingCachedData 233 { 234 private MethodBase RI; 235 private ParameterInfo[] _parameters = null; // list of parameters (cached because reflection always 236 // generates a new copy of this array) 237 238 [Serializable] 239 [Flags] 240 private enum MethodCacheFlags 241 { 242 None = 0x00, 243 CheckedOneWay = 0x01, // Have we checked for OneWay attribute? 244 IsOneWay = 0x02, // Is the OneWay attribute present? 245 CheckedOverloaded = 0x04, // Have we checked to see if this method is overloaded 246 IsOverloaded = 0x08, // Is the method overloaded? 247 CheckedForAsync = 0x10, // Have we looked for async versions of this method? 248 CheckedForReturnType = 0x20, // Have we looked for the return type? 249 } 250 251 private MethodCacheFlags flags; 252 253 // Names 254 private String _typeAndAssemblyName = null; 255 private String _methodName = null; 256 private Type _returnType = null; // null if return type is void or .ctor 257 258 // parameter maps 259 // NOTE: these fields are all initialized at the same time however access to 260 // the internal property of each field is locked only on that specific field 261 // having been initialized. - Microsoft 262 private int[] _inRefArgMap = null; // parameter map of input and ref parameters 263 private int[] _outRefArgMap = null; // parameter map of out and ref parameters (exactly all byref parameters) 264 private int[] _outOnlyArgMap = null; // parameter map of only output parameters 265 private int[] _nonRefOutArgMap = null; // parameter map of non byref parameters marked with [In, Out] (or [Out]) 266 267 private int[] _marshalRequestMap = null; // map of parameters that should be marshaled in 268 private int[] _marshalResponseMap = null; // map of parameters that should be marshaled out 269 RemotingMethodCachedData(RuntimeMethodInfo ri)270 internal RemotingMethodCachedData(RuntimeMethodInfo ri) 271 { 272 RI = ri; 273 } 274 RemotingMethodCachedData(RuntimeConstructorInfo ri)275 internal RemotingMethodCachedData(RuntimeConstructorInfo ri) 276 { 277 RI = ri; 278 } 279 GetSoapAttributeNoLock()280 internal override SoapAttribute GetSoapAttributeNoLock() 281 { 282 SoapAttribute tempSoapAttr = null; 283 284 Object[] attrs = RI.GetCustomAttributes(typeof(SoapMethodAttribute), true); 285 if ((attrs != null) && (attrs.Length != 0)) 286 tempSoapAttr = (SoapAttribute)attrs[0]; 287 else 288 tempSoapAttr = new SoapMethodAttribute(); 289 290 // IMPORTANT: This has to be done for certain values to be automatically 291 // generated in the attribute. 292 tempSoapAttr.SetReflectInfo(RI); 293 294 return tempSoapAttr; 295 } 296 297 internal String TypeAndAssemblyName 298 { 299 [System.Security.SecurityCritical] // auto-generated 300 get 301 { 302 if (_typeAndAssemblyName == null) 303 UpdateNames(); 304 return _typeAndAssemblyName; 305 } 306 } // TypeAndAssemblyName 307 308 internal String MethodName 309 { 310 [System.Security.SecurityCritical] // auto-generated 311 get 312 { 313 if (_methodName == null) 314 UpdateNames(); 315 return _methodName; 316 } 317 } // MethodName 318 319 [System.Security.SecurityCritical] // auto-generated UpdateNames()320 private void UpdateNames() 321 { 322 MethodBase mb = RI; 323 _methodName = mb.Name; 324 if (mb.DeclaringType != null) { 325 _typeAndAssemblyName = RemotingServices.GetDefaultQualifiedTypeName((RuntimeType)mb.DeclaringType); 326 } 327 } // UpdateNames 328 329 internal ParameterInfo[] Parameters 330 { 331 get 332 { 333 if (_parameters == null) 334 _parameters = RI.GetParameters(); 335 return _parameters; 336 } 337 } // Parameters 338 339 340 // contains index of all byref parameters (marked as "out" or "ref") 341 internal int[] OutRefArgMap 342 { 343 get 344 { 345 if (_outRefArgMap == null) 346 GetArgMaps(); 347 return _outRefArgMap; 348 } 349 } // OutRefArgMap 350 351 // contains index of parameters marked as out 352 internal int[] OutOnlyArgMap 353 { 354 get 355 { 356 if (_outOnlyArgMap == null) 357 GetArgMaps(); 358 return _outOnlyArgMap; 359 } 360 } // OutOnlyArgMap 361 362 // contains index of non byref parameters marked with [In, Out] 363 internal int[] NonRefOutArgMap 364 { 365 get 366 { 367 if (_nonRefOutArgMap == null) 368 GetArgMaps(); 369 return _nonRefOutArgMap; 370 } 371 } // NonRefOutArgMap 372 373 // contains index of parameters that should be marshalled for a request 374 internal int[] MarshalRequestArgMap 375 { 376 get 377 { 378 if (_marshalRequestMap == null) 379 GetArgMaps(); 380 return _marshalRequestMap; 381 } 382 } // MarshalRequestMap 383 384 // contains index of parameters that should be marshalled for a response 385 internal int[] MarshalResponseArgMap 386 { 387 get 388 { 389 if (_marshalResponseMap == null) 390 GetArgMaps(); 391 return _marshalResponseMap; 392 } 393 } // MarshalResponseArgMap 394 395 GetArgMaps()396 private void GetArgMaps() 397 { 398 lock (this) 399 { 400 if (_inRefArgMap == null) 401 { 402 int[] inRefArgMap = null; 403 int[] outRefArgMap = null; 404 int[] outOnlyArgMap = null; 405 int[] nonRefOutArgMap = null; 406 int[] marshalRequestMap = null; 407 int[] marshalResponseMap = null; 408 409 ArgMapper.GetParameterMaps(Parameters, 410 out inRefArgMap, out outRefArgMap, out outOnlyArgMap, 411 out nonRefOutArgMap, 412 out marshalRequestMap, out marshalResponseMap); 413 414 _inRefArgMap = inRefArgMap; 415 _outRefArgMap = outRefArgMap; 416 _outOnlyArgMap = outOnlyArgMap; 417 _nonRefOutArgMap = nonRefOutArgMap; 418 _marshalRequestMap = marshalRequestMap; 419 _marshalResponseMap = marshalResponseMap; 420 421 } 422 } 423 } // GetArgMaps 424 IsOneWayMethod()425 internal bool IsOneWayMethod() 426 { 427 // We are not protecting against a ---- 428 // If there is a ---- while setting flags 429 // we will have to compute the result again, 430 // but we will always return the correct result 431 // 432 if ((flags & MethodCacheFlags.CheckedOneWay) == 0) 433 { 434 MethodCacheFlags isOneWay = MethodCacheFlags.CheckedOneWay; 435 Object[] attrs = RI.GetCustomAttributes(typeof(OneWayAttribute), true); 436 437 if ((attrs != null) && (attrs.Length > 0)) 438 isOneWay |= MethodCacheFlags.IsOneWay; 439 440 flags |= isOneWay; 441 return (isOneWay & MethodCacheFlags.IsOneWay) != 0; 442 } 443 return (flags & MethodCacheFlags.IsOneWay) != 0; 444 } // IsOneWayMethod 445 IsOverloaded()446 internal bool IsOverloaded() 447 { 448 // We are not protecting against a ---- 449 // If there is a ---- while setting flags 450 // we will have to compute the result again, 451 // but we will always return the correct result 452 // 453 if ((flags & MethodCacheFlags.CheckedOverloaded) == 0) 454 { 455 MethodCacheFlags isOverloaded = MethodCacheFlags.CheckedOverloaded; 456 MethodBase mb = RI; 457 458 RuntimeMethodInfo rmi = null; 459 RuntimeConstructorInfo rci = null; 460 461 if ((rmi = mb as RuntimeMethodInfo) != null) 462 { 463 if (rmi.IsOverloaded) 464 isOverloaded |= MethodCacheFlags.IsOverloaded; 465 } 466 else if ((rci = mb as RuntimeConstructorInfo) != null) 467 { 468 if (rci.IsOverloaded) 469 isOverloaded |= MethodCacheFlags.IsOverloaded; 470 } 471 else 472 { 473 throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_Method")); 474 } 475 476 flags |= isOverloaded; 477 } 478 479 return (flags & MethodCacheFlags.IsOverloaded) != 0; 480 } // IsOverloaded 481 482 483 // This will return the return type of the method, or null 484 // if the return type is void or this is a .ctor. 485 internal Type ReturnType 486 { 487 get 488 { 489 if ((flags & MethodCacheFlags.CheckedForReturnType) == 0) 490 { 491 MethodInfo mi = RI as MethodInfo; 492 if (mi != null) 493 { 494 Type returnType = mi.ReturnType; 495 if (returnType != typeof(void)) 496 _returnType = returnType; 497 } 498 499 flags |= MethodCacheFlags.CheckedForReturnType; 500 } 501 502 return _returnType; 503 } // get 504 } // ReturnType 505 506 } // class RemotingMethodCachedData 507 508 509 // 510 // SOAP ATTRIBUTES 511 // 512 513 // Options for use with SoapOptionAttribute (combine with OR to get any combination) 514 [Serializable] 515 [Flags] 516 [System.Runtime.InteropServices.ComVisible(true)] 517 public enum SoapOption 518 { 519 None = 0x0, 520 AlwaysIncludeTypes = 0x1, // xsi:type always included on SOAP elements 521 XsdString = 0x2, // xsi:type always included on SOAP elements 522 EmbedAll = 0x4, // Soap will be generated without references 523 /// <internalonly/> 524 Option1 = 0x8, // Option for temporary interop conditions, the use will change over time 525 /// <internalonly/> 526 Option2 = 0x10, // Option for temporary interop conditions, the use will change over time 527 } // SoapOption 528 529 /// <internalonly/> 530 [Serializable] 531 [System.Runtime.InteropServices.ComVisible(true)] 532 public enum XmlFieldOrderOption 533 { 534 All, 535 Sequence, 536 Choice 537 } // XmlFieldOrderOption 538 539 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Enum)] 540 [System.Runtime.InteropServices.ComVisible(true)] 541 public sealed class SoapTypeAttribute : SoapAttribute 542 { 543 // Used to track which values have been explicitly set. Information needed 544 // by SoapServices. 545 [Serializable] 546 [Flags] 547 private enum ExplicitlySet 548 { 549 None = 0x0, 550 XmlElementName = 0x1, 551 XmlNamespace = 0x2, 552 XmlTypeName = 0x4, 553 XmlTypeNamespace = 0x8 554 } 555 556 private ExplicitlySet _explicitlySet = ExplicitlySet.None; 557 558 private SoapOption _SoapOptions = SoapOption.None; 559 private String _XmlElementName = null; 560 private String _XmlTypeName = null; 561 private String _XmlTypeNamespace = null; 562 private XmlFieldOrderOption _XmlFieldOrder = XmlFieldOrderOption.All; 563 564 565 // Returns true if this attribute specifies interop xml element values. IsInteropXmlElement()566 internal bool IsInteropXmlElement() 567 { 568 return (_explicitlySet & (ExplicitlySet.XmlElementName | ExplicitlySet.XmlNamespace)) != 0; 569 } // IsInteropXmlElement 570 IsInteropXmlType()571 internal bool IsInteropXmlType() 572 { 573 return (_explicitlySet & (ExplicitlySet.XmlTypeName | ExplicitlySet.XmlTypeNamespace)) != 0; 574 } // IsInteropXmlType 575 576 577 578 public SoapOption SoapOptions 579 { 580 get { return _SoapOptions; } 581 set { _SoapOptions = value; } 582 } // SoapOptions 583 584 public String XmlElementName 585 { 586 get 587 { 588 // generate this if it hasn't been set yet 589 if ((_XmlElementName == null) && (ReflectInfo != null)) 590 _XmlElementName = GetTypeName((Type)ReflectInfo); 591 return _XmlElementName; 592 } 593 594 set 595 { 596 _XmlElementName = value; 597 _explicitlySet |= ExplicitlySet.XmlElementName; 598 } 599 } // XmlElementName 600 601 public override String XmlNamespace 602 { 603 get 604 { 605 // generate this if it hasn't been set 606 if ((ProtXmlNamespace == null) && (ReflectInfo != null)) 607 { 608 ProtXmlNamespace = XmlTypeNamespace; 609 } 610 return ProtXmlNamespace; 611 } 612 613 set 614 { 615 ProtXmlNamespace = value; 616 _explicitlySet |= ExplicitlySet.XmlNamespace; 617 } 618 } // XmlNamespace 619 620 public String XmlTypeName // value for xml type name (this should always be valid) 621 { 622 get 623 { 624 // generate this if it hasn't been set yet 625 if ((_XmlTypeName == null) && (ReflectInfo != null)) 626 _XmlTypeName = GetTypeName((Type)ReflectInfo); 627 return _XmlTypeName; 628 } 629 630 set 631 { 632 _XmlTypeName = value; 633 _explicitlySet |= ExplicitlySet.XmlTypeName; 634 } 635 } // XmlTypeName 636 637 public String XmlTypeNamespace // value for xml type namespace (this should always be valid) 638 { 639 [System.Security.SecuritySafeCritical] // auto-generated 640 get 641 { 642 // generate this if it hasn't been set yet 643 if ((_XmlTypeNamespace == null) && (ReflectInfo != null)) 644 { 645 _XmlTypeNamespace = 646 XmlNamespaceEncoder.GetXmlNamespaceForTypeNamespace((RuntimeType)ReflectInfo, null); 647 } 648 return _XmlTypeNamespace; 649 } 650 651 set 652 { 653 _XmlTypeNamespace = value; 654 _explicitlySet |= ExplicitlySet.XmlTypeNamespace; 655 } 656 } // XmlTypeNamespace 657 658 /// <internalonly/> 659 public XmlFieldOrderOption XmlFieldOrder 660 { 661 get { return _XmlFieldOrder; } 662 set { _XmlFieldOrder = value; } 663 } // XmlFieldOrder 664 665 public override bool UseAttribute 666 { 667 get { return false; } 668 set { throw new RemotingException( 669 Environment.GetResourceString("Remoting_Attribute_UseAttributeNotsettable")); } 670 } // UseAttribute 671 GetTypeName(Type t)672 private static string GetTypeName(Type t) { 673 if (t.IsNested) { 674 string name = t.FullName; 675 string ns = t.Namespace; 676 if (ns == null || ns.Length == 0) { 677 return name; 678 } 679 else { 680 name = name.Substring(ns.Length + 1); 681 return name; 682 } 683 } 684 return t.Name; 685 } 686 687 } // class SoapTypeAttribute 688 689 690 [AttributeUsage(AttributeTargets.Method)] 691 [System.Runtime.InteropServices.ComVisible(true)] 692 public sealed class SoapMethodAttribute : SoapAttribute 693 { 694 private String _SoapAction = null; 695 696 private String _responseXmlElementName = null; 697 private String _responseXmlNamespace = null; 698 private String _returnXmlElementName = null; 699 700 private bool _bSoapActionExplicitySet = false; // Needed by SoapServices to determine if 701 // SoapAction was actually set (otherwise, 702 // accessing it will return a generated 703 // value) 704 705 internal bool SoapActionExplicitySet { get { return _bSoapActionExplicitySet; } } 706 707 public String SoapAction // SoapAction value to place in protocol headers. 708 { 709 [System.Security.SecuritySafeCritical] // auto-generated 710 get 711 { 712 // generate this if it hasn't been set 713 if (_SoapAction == null) 714 { 715 _SoapAction = XmlTypeNamespaceOfDeclaringType + "#" + 716 ((MemberInfo)ReflectInfo).Name; // This will be the method name. 717 } 718 return _SoapAction; 719 } 720 721 set 722 { 723 _SoapAction = value; 724 _bSoapActionExplicitySet = true; 725 } 726 } 727 728 public override bool UseAttribute 729 { 730 get { return false; } 731 set { throw new RemotingException( 732 Environment.GetResourceString("Remoting_Attribute_UseAttributeNotsettable")); } 733 } 734 735 public override String XmlNamespace 736 { 737 [System.Security.SecuritySafeCritical] // auto-generated 738 get 739 { 740 // generate this if it hasn't been set 741 if (ProtXmlNamespace == null) 742 { 743 ProtXmlNamespace = XmlTypeNamespaceOfDeclaringType; 744 } 745 return ProtXmlNamespace; 746 } 747 748 set { ProtXmlNamespace = value; } 749 } // XmlNamespace 750 751 752 public String ResponseXmlElementName 753 { 754 get 755 { 756 // generate this if it hasn't been set yet 757 if ((_responseXmlElementName == null) && (ReflectInfo != null)) 758 _responseXmlElementName = ((MemberInfo)ReflectInfo).Name + "Response"; 759 return _responseXmlElementName; 760 } 761 762 set { _responseXmlElementName = value; } 763 } // ResponseXmlElementName 764 765 766 public String ResponseXmlNamespace 767 { 768 get 769 { 770 // generate this if it hasn't been set 771 if (_responseXmlNamespace == null) 772 _responseXmlNamespace = XmlNamespace; 773 return _responseXmlNamespace; 774 } 775 776 set { _responseXmlNamespace = value; } 777 } // ResponseXmlNamespace 778 779 780 public String ReturnXmlElementName 781 { 782 get 783 { 784 // generate this if it hasn't been set yet 785 if (_returnXmlElementName == null) 786 _returnXmlElementName = "return"; 787 return _returnXmlElementName; 788 } 789 790 set { _returnXmlElementName = value; } 791 } // ReturnXmlElementName 792 793 794 private String XmlTypeNamespaceOfDeclaringType 795 { 796 [System.Security.SecurityCritical] // auto-generated 797 get 798 { 799 if (ReflectInfo != null) 800 { 801 Type declaringType = ((MemberInfo)ReflectInfo).DeclaringType; 802 return XmlNamespaceEncoder.GetXmlNamespaceForType((RuntimeType)declaringType, null); 803 } 804 else 805 return null; 806 } 807 } // XmlTypeNamespaceOfDeclaringType 808 809 } // class SoapMethodAttribute 810 811 812 [AttributeUsage(AttributeTargets.Field)] 813 [System.Runtime.InteropServices.ComVisible(true)] 814 public sealed class SoapFieldAttribute : SoapAttribute 815 { 816 // Used to track which values have been explicitly set. Information needed 817 // by SoapServices. 818 [Serializable] 819 [Flags] 820 private enum ExplicitlySet 821 { 822 None = 0x0, 823 XmlElementName = 0x1 824 } 825 826 private ExplicitlySet _explicitlySet = ExplicitlySet.None; 827 828 829 private String _xmlElementName = null; 830 private int _order; // order in which fields should be serialized 831 // (if Sequence is specified on containing type's SoapTypeAttribute 832 833 834 // Returns true if this attribute specifies interop xml element values. IsInteropXmlElement()835 public bool IsInteropXmlElement() 836 { 837 return (_explicitlySet & ExplicitlySet.XmlElementName) != 0; 838 } // GetInteropXmlElement 839 840 841 public String XmlElementName 842 { 843 get 844 { 845 // generate this if it hasn't been set yet 846 if ((_xmlElementName == null) && (ReflectInfo != null)) 847 _xmlElementName = ((FieldInfo)ReflectInfo).Name; 848 return _xmlElementName; 849 } 850 851 set 852 { 853 _xmlElementName = value; 854 _explicitlySet |= ExplicitlySet.XmlElementName; 855 } 856 } // XmlElementName 857 858 859 /// <internalonly/> 860 public int Order 861 { 862 get { return _order; } 863 set { _order = value; } 864 } 865 866 } // class SoapFieldAttribute 867 868 869 [AttributeUsage(AttributeTargets.Parameter)] 870 [System.Runtime.InteropServices.ComVisible(true)] 871 public sealed class SoapParameterAttribute : SoapAttribute 872 { 873 } // SoapParameterAttribute 874 875 876 877 // Not actually used as an attribute (just the base for the rest of them) 878 [System.Runtime.InteropServices.ComVisible(true)] 879 public class SoapAttribute : Attribute 880 { 881 /// <internalonly/> 882 protected String ProtXmlNamespace = null; 883 private bool _bUseAttribute = false; 884 private bool _bEmbedded = false; 885 886 /// <internalonly/> 887 protected Object ReflectInfo = null; // Reflection structure on which this attribute was defined 888 889 // IMPORTANT: The caching mechanism is required to set this value before 890 // handing back a SoapAttribute, so that certain values can be automatically 891 // generated. SetReflectInfo(Object info)892 internal void SetReflectInfo(Object info) 893 { 894 ReflectInfo = info; 895 } 896 897 public virtual String XmlNamespace // If this returns null, then this shouldn't be namespace qualified. 898 { 899 get { return ProtXmlNamespace; } 900 set { ProtXmlNamespace = value; } 901 } 902 903 public virtual bool UseAttribute 904 { 905 get { return _bUseAttribute; } 906 set { _bUseAttribute = value; } 907 } 908 909 public virtual bool Embedded // Determines if type should be nested when serializing for SOAP. 910 { 911 get { return _bEmbedded; } 912 set { _bEmbedded = value; } 913 } 914 915 } // class SoapAttribute 916 917 918 // 919 // END OF SOAP ATTRIBUTES 920 // 921 922 923 } // namespace System.Runtime.Remoting 924 925