private static Dictionary <MethodImplKey, int> CalculateMethodImpls(MetadataReader reader) { Dictionary <MethodImplKey, int> result = new Dictionary <MethodImplKey, int>(); int n = reader.GetTableRowCount(TableIndex.MethodImpl); for (int row = 1; row <= n; row++) { MethodImplementation methodImpl = reader.GetMethodImplementation(MetadataTokens.MethodImplementationHandle(row)); // Hold on to the implementing method def but use a simple // index for the implemented method ref token. (We do not map // member refs currently, and since we don't allow changes to // the set of methods a method def implements, the actual // tokens of the implemented methods are not needed.) int methodDefRow = MetadataTokens.GetRowNumber(methodImpl.MethodBody); int index = 1; while (true) { MethodImplKey key = new MethodImplKey(methodDefRow, index); if (!result.ContainsKey(key)) { result.Add(key, row); break; } index++; } } return(result); }
private void CreateExplicitInterfaceImplementations(TypeDefinitionMember member) { List <ITypeDefinitionMember> interfaceMembers = Util.FindRelatedInterfaceMembers(member); foreach (ITypeDefinitionMember interfaceMember in interfaceMembers) { IMethodDefinition methodDef = interfaceMember.ResolvedTypeDefinitionMember as IMethodDefinition; if (methodDef != null) { List <IMethodImplementation> methodImpls = null; methodImpls = GetExplicitImplementationOverrides(member, methodImpls); if (methodImpls != null) { // Make sure implementedmethod is in the closure TrimType trimType = (TrimType)_currentTrimAssembly.GetTypeElement(Util.GetTypeName(Util.ContainingTypeDefinition(interfaceMember))); if (trimType != null) { TrimMember trimMember = trimType.GetMemberElementFromMember(interfaceMember); if (trimMember != null) { MethodImplementation methodImpl = new MethodImplementation(); methodImpl.ImplementedMethod = interfaceMember.ResolvedTypeDefinitionMember as IMethodReference; methodImpl.ImplementingMethod = member as IMethodReference; methodImpl.ContainingType = member.ContainingTypeDefinition; methodImpls.Add(Rewrite(methodImpl)); } } } } } }
public MethodImplEntry(PEFile module, MethodImplementationHandle handle) { this.metadataOffset = module.Reader.PEHeaders.MetadataStartOffset; this.module = module; this.metadata = module.Metadata; this.handle = handle; this.methodImpl = metadata.GetMethodImplementation(handle); }
private void SaveFormValues() { ConfigurationManager config = ConfigurationManager.GetConfigurationManager("WSCF05"); config.Write("ClientCode", rbClient.Checked.ToString()); config.Write("ServerCode", rbServer.Checked.ToString()); config.Write("Properties", cbProperties.Checked.ToString()); config.Write("Serializable", cbFormatSoapActions.Checked.ToString()); config.Write("Collections", cbCollections.Checked.ToString()); config.Write("GenericList", cbGenericList.Checked.ToString()); config.Write("DataBinding", cbDataBinding.Checked.ToString()); config.Write("OrderIdentifiers", cbOrderIds.Checked.ToString()); config.Write("AsyncMethods", cbAsync.Checked.ToString()); config.Write("MultipleFiles", cbMultipleFiles.Checked.ToString()); config.Write("AdjustCasing", cbAdjustCasing.Checked.ToString()); config.Write("ConcurrencyMode", cbConcurrencyMode.Text); config.Write("InstanceContextMode", cbInstanceContextMode.Text); config.Write("UseSynchronizationContext", cbUseSynchronizationContext.Checked.ToString()); config.Write("EnableWsdlEndpoint", cbEnableWsdlEndpoint.Checked.ToString()); config.Write("GenerateSvcFile", cbGenerateSvcFile.Checked.ToString()); config.Write("MethodImplementation", MethodImplementation.ToString()); config.Write("DestinationFilename", tbDestinationFilename.Text); config.Write("DestinationNamespace", tbDestinationNamespace.Text); config.Write("Overwrite", cbOverwrite.Checked.ToString()); // BDS: Modified the code to store the values pasted to the combo box. if (cbWsdlLocation.SelectedItem != null) { config.Write("WSDLLocation", wsdlFileCache[cbWsdlLocation.SelectedIndex].ToString()); } else { config.Write("WSDLLocation", cbWsdlLocation.Text); } config.Write("RememberSettings", cbSettings.Checked.ToString()); string wsdlUrlsString = ""; // Add the current item. if (cbWsdlLocation.SelectedItem == null) { string fname = AddWsdlFileToCache(cbWsdlLocation.Text); } foreach (string path in wsdlFileCache) { wsdlUrlsString += path + ";"; } config.Write("WsdlUrls", wsdlUrlsString); config.Persist(); }
public void MethodImplEntry() { var text = @" public class A { ~A() { } } "; CompileAndVerify(text, assemblyValidator: (assembly) => { var peFileReader = assembly.GetMetadataReader(); // Find the handle and row for A. var pairA = peFileReader.TypeDefinitions.AsEnumerable(). Select(handle => new { handle = handle, row = peFileReader.GetTypeDefinition(handle) }). Single(pair => peFileReader.GetString(pair.row.Name) == "A" && string.IsNullOrEmpty(peFileReader.GetString(pair.row.Namespace))); TypeDefinitionHandle handleA = pairA.handle; TypeDefinition typeA = pairA.row; // Find the handle for A's destructor. MethodDefinitionHandle handleDestructorA = typeA.GetMethods().AsEnumerable(). Single(handle => peFileReader.GetString(peFileReader.GetMethodDefinition(handle).Name) == WellKnownMemberNames.DestructorName); // Find the handle for System.Object. TypeReferenceHandle handleObject = peFileReader.TypeReferences.AsEnumerable(). Select(handle => new { handle = handle, row = peFileReader.GetTypeReference(handle) }). Single(pair => peFileReader.GetString(pair.row.Name) == "Object" && peFileReader.GetString(pair.row.Namespace) == "System").handle; // Find the handle for System.Object's destructor. MemberReferenceHandle handleDestructorObject = peFileReader.MemberReferences.AsEnumerable(). Select(handle => new { handle = handle, row = peFileReader.GetMemberReference(handle) }). Single(pair => pair.row.Parent == (EntityHandle)handleObject && peFileReader.GetString(pair.row.Name) == WellKnownMemberNames.DestructorName).handle; // Find the MethodImpl row for A. MethodImplementation methodImpl = typeA.GetMethodImplementations().AsEnumerable(). Select(handle => peFileReader.GetMethodImplementation(handle)). Single(); // The Class column should point to A. Assert.Equal(handleA, methodImpl.Type); // The MethodDeclaration column should point to System.Object.Finalize. Assert.Equal((EntityHandle)handleDestructorObject, methodImpl.MethodDeclaration); // The MethodDeclarationColumn should point to A's destructor. Assert.Equal((EntityHandle)handleDestructorA, methodImpl.MethodBody); }); }
/// <summary> /// Executes the next <see cref="IDecorator.OnInvoke(Call)"/> and eventually the called method itself. /// </summary> public async Task Next() { var currentCallIndex = _callIndex; try { if (_decorators != null && _callIndex < _decorators.Length) { await _decorators[_callIndex++].OnInvoke(this).ConfigureAwait(false); } else { _proceedInfo.Invoke(); if (_invocation.ReturnValue is Task task && MethodImplementation.IsAsync()) { if (!task.IsCompleted) { // Async methods are executed within interception. // Non-async method returned task is treated as a result // and is not executed within interception. await task.ConfigureAwait(false); } if (task.IsFaulted && task.Exception != null) { task.Exception.Rethrow(); } // Runtime might return Task<T> derived type here. // Discussed in dotnet/runtime#26312 and microsoft/vs-streamjsonrpc#116. if (task.GetType().GetTypeInfo().TryGetGenericTaskType(out var genericTaskType)) { if (genericTaskType.IsTaskWithVoidTaskResult()) { return; } var resultProperty = genericTaskType.GetDeclaredProperty("Result"); if (resultProperty == null) { throw new InvalidOperationException( $"Object of type '{genericTaskType}' was expected to contain a property 'Result'."); } ReturnValue = resultProperty.GetValue(task); } } else { ReturnValue = _invocation.ReturnValue; } }
internal void WriteMethodImpl(MethodImplementation implementation) { if (implementation.UpdateRowOnRebuild) { object[] parts = new object[] { GetMemberIndex(implementation.Class), GetCodedIndex(tablesHeap.MethodDefOrRef, implementation.MethodBody), GetCodedIndex(tablesHeap.MethodDefOrRef, implementation.MethodDeclaration), }; implementation.MetaDataRow = new MetaDataRow(parts); } writer.Write(implementation.MetaDataRow.GenerateBytes()); }
protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() { ArrayBuilder <MethodImplRecord> records = new ArrayBuilder <MethodImplRecord>(); MetadataReader metadataReader = _module.MetadataReader; foreach (var methodImplHandle in _typeDefinition.GetMethodImplementations()) { MethodImplementation methodImpl = metadataReader.GetMethodImplementation(methodImplHandle); EntityHandle methodDeclCheckHandle = methodImpl.MethodDeclaration; HandleKind methodDeclHandleKind = methodDeclCheckHandle.Kind; // We want to check that the type is not an interface matches before actually getting the MethodDesc. // For MethodSpecifications we need to dereference that handle to the underlying member reference to // look at the owning type. if (methodDeclHandleKind == HandleKind.MethodSpecification) { methodDeclCheckHandle = metadataReader.GetMethodSpecification((MethodSpecificationHandle)methodDeclCheckHandle).Method; methodDeclHandleKind = methodDeclCheckHandle.Kind; } MetadataType owningType = null; switch (methodDeclHandleKind) { case HandleKind.MethodDefinition: owningType = ((MethodDesc)_module.GetObject(methodDeclCheckHandle)).OwningType as MetadataType; break; case HandleKind.MemberReference: EntityHandle owningTypeHandle = metadataReader.GetMemberReference((MemberReferenceHandle)methodDeclCheckHandle).Parent; owningType = _module.GetObject(owningTypeHandle) as MetadataType; break; default: Debug.Fail("unexpected methodDeclHandleKind"); break; } if (!owningType.IsInterface) { MethodImplRecord newRecord = new MethodImplRecord( (MethodDesc)_module.GetObject(methodImpl.MethodDeclaration), (MethodDesc)_module.GetObject(methodImpl.MethodBody)); records.Add(newRecord); } } return(records.ToArray()); }
private void AddImplementation(MethodImplementation implementation) { var table = (MethodImplementationTable)_tableStream.GetTable(MetadataTokenType.MethodImpl); // Create and add row. var encoder = _tableStream.GetIndexEncoder(CodedIndex.MethodDefOrRef); var implementationRow = new MetadataRow <uint, uint, uint> { Column1 = GetNewToken(implementation.Class).Rid, Column2 = encoder.EncodeToken(GetMethodToken(implementation.MethodBody)), Column3 = encoder.EncodeToken(GetMethodToken(implementation.MethodDeclaration)) }; table.Add(implementationRow); _members.Add(implementation, implementationRow.MetadataToken); }
/// <summary> /// Create the non-generic version of GetEnumerator and add it to the member list of iterator closure class. /// </summary> private void CreateGetEnumeratorMethodNonGeneric(IteratorClosureInformation iteratorClosure) { // GetEnumerator non-generic version, which delegates to the generic version. // Metadata MethodDefinition nongenericGetEnumerator = new MethodDefinition() { Attributes = new List<ICustomAttribute>(1), InternFactory = this.host.InternFactory, Name = this.host.NameTable.GetNameFor("System.Collections.IEnumerable.GetEnumerator") }; nongenericGetEnumerator.Attributes.Add( new CustomAttribute() { Constructor = this.DebuggerHiddenCtor } ); nongenericGetEnumerator.CallingConvention |= CallingConvention.HasThis; nongenericGetEnumerator.ContainingTypeDefinition = iteratorClosure.ClosureDefinition; nongenericGetEnumerator.Visibility = TypeMemberVisibility.Public; nongenericGetEnumerator.Type = iteratorClosure.NonGenericIEnumeratorInterface; nongenericGetEnumerator.IsVirtual = true; nongenericGetEnumerator.IsNewSlot = true; nongenericGetEnumerator.IsHiddenBySignature = true; nongenericGetEnumerator.IsSealed = true; iteratorClosure.NonGenericGetEnumerator = nongenericGetEnumerator; // Explicitly implements IEnumerable.GetEnumerator(); IMethodReference nongenericGetEnumeratorOriginal = Dummy.MethodReference; foreach (var memref in iteratorClosure.NonGenericIEnumerableInterface.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("GetEnumerator"), false)) { IMethodReference mref = memref as IMethodReference; if (mref != null) { nongenericGetEnumeratorOriginal = mref; break; } } MethodImplementation nonGenericGetEnumeratorImp = new MethodImplementation() { ContainingType = iteratorClosure.ClosureDefinition, ImplementedMethod = nongenericGetEnumeratorOriginal, ImplementingMethod = nongenericGetEnumerator }; iteratorClosure.ClosureDefinition.ExplicitImplementationOverrides.Add(nonGenericGetEnumeratorImp); // Body: call this.GetEnumerator (the generic version). BlockStatement block1 = new BlockStatement(); block1.Statements.Add(new ReturnStatement() { Expression = new MethodCall() { IsStaticCall = false, MethodToCall = iteratorClosure.GenericGetEnumeratorReference, ThisArgument = new ThisReference(), Type = iteratorClosure.NonGenericIEnumeratorInterface } }); SourceMethodBody body1 = new SourceMethodBody(this.host, this.sourceLocationProvider); body1.IsNormalized = true; body1.LocalsAreZeroed = true; body1.Block = block1; body1.MethodDefinition = nongenericGetEnumerator; nongenericGetEnumerator.Body = body1; }
// Virtual function related functionality public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(string declName) { MetadataReader metadataReader = _module.MetadataReader; var stringComparer = metadataReader.StringComparer; ArrayBuilder <MethodImplRecord> foundRecords = new ArrayBuilder <MethodImplRecord>(); foreach (var methodImplHandle in _typeDefinition.GetMethodImplementations()) { MethodImplementation methodImpl = metadataReader.GetMethodImplementation(methodImplHandle); EntityHandle methodDeclCheckHandle = methodImpl.MethodDeclaration; HandleKind methodDeclHandleKind = methodDeclCheckHandle.Kind; // We want to check that the method name matches before actually getting the MethodDesc. For MethodSpecifications // we need to dereference that handle to the underlying member reference to look at name matching. if (methodDeclHandleKind == HandleKind.MethodSpecification) { methodDeclCheckHandle = metadataReader.GetMethodSpecification((MethodSpecificationHandle)methodDeclCheckHandle).Method; methodDeclHandleKind = methodDeclCheckHandle.Kind; } bool foundRecord = false; switch (methodDeclHandleKind) { case HandleKind.MethodDefinition: if (stringComparer.Equals(metadataReader.GetMethodDefinition((MethodDefinitionHandle)methodDeclCheckHandle).Name, declName)) { foundRecord = true; } break; case HandleKind.MemberReference: if (stringComparer.Equals(metadataReader.GetMemberReference((MemberReferenceHandle)methodDeclCheckHandle).Name, declName)) { foundRecord = true; } break; default: Debug.Fail("unexpected methodDeclHandleKind"); break; } if (foundRecord) { MethodImplRecord newRecord = new MethodImplRecord( (MethodDesc)_module.GetObject(methodImpl.MethodDeclaration), (MethodDesc)_module.GetObject(methodImpl.MethodBody)); foundRecords.Add(newRecord); } } if (foundRecords.Count != 0) { return(foundRecords.ToArray()); } return(null); }
internal static Tuple cil_method_implementation(MethodImplementation impl, Method method, Assembly assembly) => new Tuple("cil_method_implementation", impl, method, assembly);
/// <summary> /// Create the generic version of the GetEnumerator for the iterator closure class. /// </summary> /// <param name="iteratorClosure"></param> private void CreateGetEnumeratorMethodGeneric(IteratorClosureInformation iteratorClosure) { // Metadata MethodDefinition genericGetEnumerator = new MethodDefinition() { Attributes = new List<ICustomAttribute>(1), InternFactory = this.host.InternFactory, Name = this.host.NameTable.GetNameFor("System.Collections.Generic.IEnumerable<" + iteratorClosure.ElementType.ToString()+">.GetEnumerator") }; CustomAttribute debuggerHiddenAttribute = new CustomAttribute() { Constructor = this.DebuggerHiddenCtor }; genericGetEnumerator.Attributes.Add(debuggerHiddenAttribute); genericGetEnumerator.CallingConvention |= CallingConvention.HasThis; genericGetEnumerator.ContainingTypeDefinition = iteratorClosure.ClosureDefinition; genericGetEnumerator.Visibility = TypeMemberVisibility.Public; genericGetEnumerator.Type = iteratorClosure.GenericIEnumeratorInterface; genericGetEnumerator.IsVirtual = true; genericGetEnumerator.IsNewSlot = true; genericGetEnumerator.IsHiddenBySignature = true; genericGetEnumerator.IsSealed = true; // Membership iteratorClosure.GenericGetEnumerator = genericGetEnumerator; IMethodReference genericGetEnumeratorOriginal = Dummy.MethodReference; // Explicit implementation of IEnumerable<T>.GetEnumerator foreach (var memref in iteratorClosure.GenericIEnumerableInterface.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("GetEnumerator"), false)) { IMethodReference mref = memref as IMethodReference; if (mref != null) { genericGetEnumeratorOriginal = mref; break; } } var genericGetEnumeratorImp = new MethodImplementation() { ContainingType = iteratorClosure.ClosureDefinition, ImplementingMethod = genericGetEnumerator, ImplementedMethod = genericGetEnumeratorOriginal }; iteratorClosure.ClosureDefinition.ExplicitImplementationOverrides.Add(genericGetEnumeratorImp); // Body var block = GetBodyOfGenericGetEnumerator(iteratorClosure); var body = new SourceMethodBody(this.host, this.sourceLocationProvider); body.LocalsAreZeroed = true; body.IsNormalized = true; body.Block = block; body.MethodDefinition = genericGetEnumerator; genericGetEnumerator.Body = body; }
/// <summary> /// Create two properties: object Current and T Current as the closure class implements both the /// generic and non-generic version of ienumerator. /// /// Current Implementation generates getters, but not the property. /// </summary> /// <param name="iteratorClosure">Information about the closure created when compiling the current iterator method</param> private void CreateIteratorClosureProperties(IteratorClosureInformation iteratorClosure) { // Non-generic version of the get_Current, which returns the generic version of get_Current. MethodDefinition getterNonGenericCurrent = new MethodDefinition() { Attributes = new List<ICustomAttribute>(1), InternFactory = this.host.InternFactory, Name = this.host.NameTable.GetNameFor("System.Collections.IEnumerator.get_Current") }; CustomAttribute debuggerHiddenAttribute = new CustomAttribute(); debuggerHiddenAttribute.Constructor = this.DebuggerHiddenCtor; getterNonGenericCurrent.Attributes.Add(debuggerHiddenAttribute); getterNonGenericCurrent.CallingConvention |= CallingConvention.HasThis; getterNonGenericCurrent.Visibility |= TypeMemberVisibility.Public; getterNonGenericCurrent.ContainingTypeDefinition = iteratorClosure.ClosureDefinition; getterNonGenericCurrent.Type = this.host.PlatformType.SystemObject; getterNonGenericCurrent.IsSpecialName = true; getterNonGenericCurrent.IsVirtual = true; getterNonGenericCurrent.IsNewSlot = true; getterNonGenericCurrent.IsHiddenBySignature = true; getterNonGenericCurrent.IsSealed = true; iteratorClosure.NonGenericGetCurrent = getterNonGenericCurrent; IMethodReference originalMethod = Dummy.MethodReference; foreach (ITypeMemberReference tref in iteratorClosure.NonGenericIEnumeratorInterface.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("get_Current"), false)) { originalMethod = tref as IMethodReference; if (originalMethod != null) break; } // assert originalMethod != Dummy MethodImplementation getterImplementation = new MethodImplementation() { ContainingType = iteratorClosure.ClosureDefinition, ImplementingMethod = getterNonGenericCurrent, ImplementedMethod = originalMethod }; iteratorClosure.ClosureDefinition.ExplicitImplementationOverrides.Add(getterImplementation); List<IStatement> statements = new List<IStatement>(); IFieldReference currentField = iteratorClosure.CurrentFieldReference; BoundExpression thisDotCurr = new BoundExpression() { Definition = currentField, Instance = new ThisReference(), Locations = iteratorClosure.ClosureDefinition.Locations, Type = currentField.Type }; IExpression returnExpression; if (!iteratorClosure.ElementType.IsValueType && TypeHelper.TypesAreAssignmentCompatible(iteratorClosure.ElementType.ResolvedType, this.host.PlatformType.SystemObject.ResolvedType)) { returnExpression = thisDotCurr; } else { Conversion convertion = new Conversion() { CheckNumericRange = false, Type = this.host.PlatformType.SystemObject, TypeAfterConversion = getterNonGenericCurrent.Type, ValueToConvert = thisDotCurr }; returnExpression = convertion; } ReturnStatement returnCurrent = new ReturnStatement() { Expression = returnExpression, Locations = iteratorClosure.ClosureDefinition.Locations }; statements.Add(returnCurrent); BlockStatement block = new BlockStatement() { Statements = statements }; SourceMethodBody body = new SourceMethodBody(this.host, this.sourceLocationProvider); body.IsNormalized = true; body.LocalsAreZeroed = true; body.Block = block; body.MethodDefinition = getterNonGenericCurrent; getterNonGenericCurrent.Body = body; // Create generic version of get_Current, the body of which is simply returning this.current. MethodDefinition getterGenericCurrent = new MethodDefinition() { Attributes = new List<ICustomAttribute>(1), InternFactory = this.host.InternFactory, Name = this.host.NameTable.GetNameFor("System.Collections.Generic.IEnumerator<" + iteratorClosure.ElementType.ToString() +">.get_Current") }; getterGenericCurrent.Attributes.Add(debuggerHiddenAttribute); getterGenericCurrent.CallingConvention |= CallingConvention.HasThis; getterGenericCurrent.Visibility |= TypeMemberVisibility.Public; getterGenericCurrent.ContainingTypeDefinition = iteratorClosure.ClosureDefinition; getterGenericCurrent.Type = iteratorClosure.ElementType; getterGenericCurrent.IsSpecialName = true; getterGenericCurrent.IsVirtual = true; getterGenericCurrent.IsNewSlot = true; getterGenericCurrent.IsHiddenBySignature = true; getterGenericCurrent.IsSealed = true; iteratorClosure.GenericGetCurrent = getterGenericCurrent; originalMethod = Dummy.MethodReference; foreach (ITypeMemberReference tref in iteratorClosure.GenericIEnumeratorInterface.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("get_Current"), false)) { originalMethod = tref as IMethodReference; if (originalMethod != null) break; } MethodImplementation getterImplementation2 = new MethodImplementation() { ContainingType = iteratorClosure.ClosureDefinition, ImplementingMethod = getterGenericCurrent, ImplementedMethod = originalMethod }; iteratorClosure.ClosureDefinition.ExplicitImplementationOverrides.Add(getterImplementation2); statements = new List<IStatement>(); currentField = iteratorClosure.CurrentFieldReference; BoundExpression thisDotCurrent = new BoundExpression() { Definition = currentField, Instance = new ThisReference(), Locations = iteratorClosure.ClosureDefinition.Locations, Type = currentField.Type }; returnCurrent = new ReturnStatement() { Expression = thisDotCurrent, Locations = iteratorClosure.ClosureDefinition.Locations }; statements.Add(returnCurrent); block = new BlockStatement() { Statements = statements }; body = new SourceMethodBody(this.host, this.sourceLocationProvider); body.LocalsAreZeroed = true; body.Block = block; body.MethodDefinition = getterGenericCurrent; getterGenericCurrent.Body = body; }
public ServerHandler(string url, string SessionID, IRegistryCore registry) : base("POST", url) { m_SessionID = SessionID; m_registry = registry; if (m_methods == null) { m_methods = new Dictionary<string, List<MethodImplementation>>(); List<string> alreadyRunPlugins = new List<string>(); foreach (ConnectorBase plugin in ConnectorRegistry.Connectors) { if (alreadyRunPlugins.Contains(plugin.PluginName)) continue; alreadyRunPlugins.Add(plugin.PluginName); foreach (MethodInfo method in plugin.GetType().GetMethods()) { CanBeReflected reflection = (CanBeReflected)Attribute.GetCustomAttribute(method, typeof(CanBeReflected)); if (reflection != null) { string methodName = reflection.RenamedMethod == "" ? method.Name : reflection.RenamedMethod; List<MethodImplementation> methods = new List<MethodImplementation>(); MethodImplementation imp = new MethodImplementation() { Method = method, Reference = plugin, Attribute = reflection }; if (!m_methods.TryGetValue(methodName, out methods)) m_methods.Add(methodName, (methods = new List<MethodImplementation>())); methods.Add(imp); } } } } }
public ServerHandler(string url, string SessionID, IRegistryCore registry) : base("POST", url) { m_SessionID = SessionID; m_registry = registry; m_methods = new Dictionary<string, List<MethodImplementation>>(); List<string> alreadyRunPlugins = new List<string>(); foreach(IAuroraDataPlugin plugin in Aurora.DataManager.DataManager.GetPlugins()) { if (alreadyRunPlugins.Contains(plugin.Name)) continue; alreadyRunPlugins.Add(plugin.Name); foreach (MethodInfo method in plugin.GetType().GetMethods()) { if (Attribute.GetCustomAttribute(method, typeof(CanBeReflected)) != null) { List<MethodImplementation> methods = new List<MethodImplementation>(); MethodImplementation imp = new MethodImplementation() { Method = method, Reference = plugin }; if (!m_methods.TryGetValue(method.Name, out methods)) m_methods.Add(method.Name, (methods = new List<MethodImplementation>())); methods.Add(imp); } } } }
private bool GetMethodInfo(string method, int parameters, out MethodImplementation methodInfo) { List<MethodImplementation> methods = new List<MethodImplementation>(); if (m_methods.TryGetValue(method, out methods)) { if (methods.Count == 1) { methodInfo = methods[0]; return true; } foreach (MethodImplementation m in methods) { if (m.Method.GetParameters().Length == parameters) { methodInfo = m; return true; } } } methodInfo = null; return false; }
private void UpdateMethodImpl(Workspace workspace, MethodImplementation methodImpl) { methodImpl.MetaDataRow.Parts[0] = GetMemberIndex(workspace, methodImpl.Class); methodImpl.MetaDataRow.Parts[1] = GetMemberIndex(workspace, Constructor.OriginalAssembly.NETHeader.TablesHeap.MethodDefOrRef, methodImpl.MethodBody); methodImpl.MetaDataRow.Parts[1] = GetMemberIndex(workspace, Constructor.OriginalAssembly.NETHeader.TablesHeap.MethodDefOrRef, methodImpl.MethodDeclaration); }
/// <summary> /// Create the MoveNext method. This method sets up metadata and calls TranslateIteratorMethodBodyToMoveNextBody /// to compile the body. /// </summary> private void CreateMoveNextMethod(IteratorClosureInformation /*!*/ iteratorClosure, BlockStatement blockStatement) { // Method definition and metadata. MethodDefinition moveNext = new MethodDefinition() { InternFactory = this.host.InternFactory, Name = this.host.NameTable.GetNameFor("MoveNext") }; moveNext.ContainingTypeDefinition = iteratorClosure.ClosureDefinition; moveNext.Visibility = TypeMemberVisibility.Private; moveNext.CallingConvention |= CallingConvention.HasThis; moveNext.Type = this.host.PlatformType.SystemBoolean; moveNext.InternFactory = this.host.InternFactory; moveNext.IsSealed = true; moveNext.IsVirtual = true; moveNext.IsHiddenBySignature = true; moveNext.IsNewSlot = true; iteratorClosure.MoveNext = moveNext; IMethodReference moveNextOriginal = Dummy.MethodReference; foreach (ITypeMemberReference tmref in iteratorClosure.NonGenericIEnumeratorInterface.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("MoveNext"), false)) { moveNextOriginal = tmref as IMethodReference; if (moveNextOriginal != null) break; } // Explicit method implementation MethodImplementation moveNextImp = new MethodImplementation() { ContainingType = iteratorClosure.ClosureDefinition, ImplementingMethod = moveNext, ImplementedMethod = moveNextOriginal }; iteratorClosure.ClosureDefinition.ExplicitImplementationOverrides.Add(moveNextImp); SourceMethodBody body = new SourceMethodBody(this.host, this.sourceLocationProvider, null, this.iteratorLocalCount); IBlockStatement block = TranslateIteratorMethodBodyToMoveNextBody(iteratorClosure, blockStatement); moveNext.Body = body; body.IsNormalized = true; body.LocalsAreZeroed = true; body.Block = block; body.MethodDefinition = moveNext; }
/// <summary> /// Create the Reset method. Like in CSC, this method contains nothing. /// </summary> private void CreateResetMethod(IteratorClosureInformation iteratorClosure) { // System.Collections.IEnumerator.Reset: Simply throws an exception MethodDefinition reset = new MethodDefinition() { Attributes = new List<ICustomAttribute>(1), InternFactory = this.host.InternFactory, Name = this.host.NameTable.GetNameFor("Reset") }; CustomAttribute debuggerHiddenAttribute = new CustomAttribute() { Constructor = this.DebuggerHiddenCtor }; reset.Attributes.Add(debuggerHiddenAttribute); reset.CallingConvention |= CallingConvention.HasThis; reset.Visibility = TypeMemberVisibility.Private; reset.ContainingTypeDefinition = iteratorClosure.ClosureDefinition; reset.Type = this.host.PlatformType.SystemVoid; reset.IsVirtual = true; reset.IsNewSlot = true; reset.IsHiddenBySignature = true; reset.IsSealed = true; iteratorClosure.Reset = reset; // explicitly state that this reset method implements IEnumerator's reset method. IMethodReference resetImplemented = Dummy.MethodReference; foreach (var memref in iteratorClosure.NonGenericIEnumeratorInterface.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("Reset"), false)) { IMethodReference mref = memref as IMethodReference; if (mref != null) { resetImplemented = mref; break; } } MethodImplementation resetImp = new MethodImplementation() { ContainingType = iteratorClosure.ClosureDefinition, ImplementedMethod = resetImplemented, ImplementingMethod = reset }; iteratorClosure.ClosureDefinition.ExplicitImplementationOverrides.Add(resetImp); List<IStatement> statements = new List<IStatement>(); ReturnStatement returnCurrent = new ReturnStatement() { Expression = null, Locations = iteratorClosure.ClosureDefinition.Locations }; statements.Add(returnCurrent); BlockStatement block = new BlockStatement() { Statements = statements }; SourceMethodBody body = new SourceMethodBody(this.host, this.sourceLocationProvider); body.LocalsAreZeroed = true; body.IsNormalized = true; body.Block = block; body.MethodDefinition = reset; reset.Body = body; }
public static string ToString(this MetadataReader reader, MethodImplementation x) => $"{{MethodImpl[{RowId(x):X}]: {reader.ToString( x.MethodBody)} {reader.ToString( x.MethodDeclaration)}}}";
internal static Tuple cil_handler(ExceptionRegion region, MethodImplementation method, int index, int kind, Instruction region_start, Instruction region_end, Instruction handler_start) => new Tuple("cil_handler", region, method, index, kind, region_start, region_end, handler_start);
private void LoadFormValues() { ConfigurationManager config = ConfigurationManager.GetConfigurationManager("WSCF05"); string wsdlUrls = config.Read("WsdlUrls"); //if (wsdlUrls.Length > 0) //{ cbWsdlLocation.Items.Clear(); wsdlUrls = wsdlUrls.Trim(';'); string[] urls = wsdlUrls.Split(';'); // BDS: Changed this code to use new wsdl file cache. for (int urlIndex = 0; urlIndex < urls.Length; urlIndex++) { string fname = AddWsdlFileToCache(urls[urlIndex]); } if (cbWsdlLocation.Items.Count > 0) { cbWsdlLocation.SelectedIndex = 0; } if (wsdlLocation.Length > 0) { if (!wsdlFileCache.Contains(wsdlLocation)) { string fname = AddWsdlFileToCache(wsdlLocation); } else { int wsdlIndex = wsdlFileCache.IndexOf(wsdlLocation); cbWsdlLocation.SelectedIndex = wsdlIndex; } } //} if (config.ReadBoolean("RememberSettings")) { //In an MVP kind of approach, the config settings would be read into // an options class and that would be passed on to the view. cbSettings.Checked = config.ReadBoolean("RememberSettings"); rbClient.Checked = config.ReadBoolean("ClientCode"); rbServer.Checked = config.ReadBoolean("ServerCode"); cbProperties.Checked = config.ReadBoolean("Properties"); cbFormatSoapActions.Checked = config.ReadBoolean("Serializable"); cbCollections.Checked = config.ReadBoolean("Collections"); cbGenericList.Checked = config.ReadBoolean("GenericList"); cbDataBinding.Checked = config.ReadBoolean("DataBinding"); cbOrderIds.Checked = config.ReadBoolean("OrderIdentifiers"); cbAsync.Checked = config.ReadBoolean("AsyncMethods"); cbMultipleFiles.Checked = config.ReadBoolean("MultipleFiles"); cbAdjustCasing.Checked = config.ReadBoolean("AdjustCasing"); cbConcurrencyMode.SelectedItem = config.Read("ConcurrencyMode", "Single"); cbInstanceContextMode.SelectedItem = config.Read("InstanceContextMode", "PerCall"); cbUseSynchronizationContext.Checked = config.ReadBoolean("UseSynchronizationContext"); cbEnableWsdlEndpoint.Checked = config.ReadBoolean("EnableWsdlEndpoint"); cbGenerateSvcFile.Checked = config.ReadBoolean("GenerateSvcFile"); string methodImplementationValue = config.Read("MethodImplementation", MethodImplementation.NotImplementedException.ToString()); MethodImplementation methodImplementation = (MethodImplementation)Enum.Parse(typeof(MethodImplementation), methodImplementationValue); if (methodImplementation == MethodImplementation.NotImplementedException) { rbNotImplementedException.Checked = true; } if (methodImplementation == MethodImplementation.PartialClassMethodCalls) { rbPartialClassMethodCalls.Checked = true; } if (methodImplementation == MethodImplementation.AbstractMethods) { rbAbstractMethods.Checked = true; } tbDestinationFilename.Text = config.Read("DestinationFilename"); tbDestinationNamespace.Text = config.Read("DestinationNamespace"); cbOverwrite.Checked = config.ReadBoolean("Overwrite"); } }
internal static Tuple cil_instruction(Instruction instruction, int opcode, int index, MethodImplementation parent) => new Tuple("cil_instruction", instruction, opcode, index, parent);
private bool GetMethodInfo(string method, int parameters, out MethodImplementation methodInfo) { List<MethodImplementation> methods = new List<MethodImplementation>(); if (m_methods.TryGetValue(method, out methods)) { if (methods.Count == 1) { methodInfo = methods[0]; return true; } foreach (MethodImplementation m in methods) { if (m.Method.GetParameters().Length == parameters) { methodInfo = m; return true; } } } MainConsole.Instance.Warn("COULD NOT FIND METHOD: " + method); methodInfo = null; return false; }
internal static Tuple cil_local_variable(LocalVariable l, MethodImplementation m, int i, Type t) => new Tuple("cil_local_variable", l, m, i, t);
internal static Tuple cil_method_stack_size(MethodImplementation method, int stackSize) => new Tuple("cil_method_stack_size", method, stackSize);
/// <summary> /// DisposeMethod method. Currently the method body does nothing. /// </summary> private void CreateDisposeMethod(IteratorClosureInformation iteratorClosure) { MethodDefinition disposeMethod = new MethodDefinition() { Attributes = new List<ICustomAttribute>(1), InternFactory = this.host.InternFactory, Name = this.host.NameTable.GetNameFor("Dispose") }; disposeMethod.Attributes.Add(new CustomAttribute() { Constructor = this.debuggerHiddenCtor }); disposeMethod.CallingConvention |= CallingConvention.HasThis; disposeMethod.Visibility = TypeMemberVisibility.Public; disposeMethod.ContainingTypeDefinition = iteratorClosure.ClosureDefinition; disposeMethod.Type = this.host.PlatformType.SystemVoid; disposeMethod.IsVirtual = true; disposeMethod.IsNewSlot = true; disposeMethod.IsHiddenBySignature = true; disposeMethod.IsSealed = true; // Add disposeMethod to parent's member list. iteratorClosure.DisposeMethod = disposeMethod; // Explicitly implements IDisposable's dispose. IMethodReference disposeImplemented = Dummy.MethodReference; foreach (var memref in iteratorClosure.DisposableInterface.ResolvedType.GetMembersNamed(this.host.NameTable.GetNameFor("Dispose"), false)) { IMethodReference mref = memref as IMethodReference; if (mref != null) { disposeImplemented = mref; break; } } MethodImplementation disposeImp = new MethodImplementation() { ContainingType = iteratorClosure.ClosureDefinition, ImplementedMethod = disposeImplemented, ImplementingMethod = disposeMethod }; iteratorClosure.ClosureDefinition.ExplicitImplementationOverrides.Add(disposeImp); // Body is a sole return. BlockStatement block = new BlockStatement(); block.Statements.Add(new ReturnStatement() { Expression = null, Locations = iteratorClosure.ClosureDefinition.Locations }); SourceMethodBody body = new SourceMethodBody(this.host, this.sourceLocationProvider); body.LocalsAreZeroed = true; body.IsNormalized = true; body.Block = block; body.MethodDefinition = disposeMethod; disposeMethod.Body = body; }