public DomCecilType(TypeDefinition typeDefinition, bool loadInternal) { this.typeDefinition = typeDefinition; this.loadInternal = loadInternal; this.classType = GetClassType(typeDefinition); this.Name = DomCecilType.RemoveGenericParamSuffix(typeDefinition.Name); this.Namespace = typeDefinition.Namespace; this.Modifiers = GetModifiers(typeDefinition.Attributes); if (typeDefinition.BaseType != null) { this.baseType = DomCecilMethod.GetReturnType(typeDefinition.BaseType); } DomCecilMethod.AddAttributes(this, typeDefinition.CustomAttributes); foreach (TypeReference interfaceReference in typeDefinition.Interfaces) { this.AddInterfaceImplementation(DomCecilMethod.GetReturnType(interfaceReference)); } foreach (GenericParameter parameter in typeDefinition.GenericParameters) { TypeParameter tp = new TypeParameter(parameter.FullName); tp.Variance = (TypeParameterVariance)(((uint)parameter.Attributes) & 3); foreach (TypeReference tr in parameter.Constraints) { tp.AddConstraint(DomCecilMethod.GetReturnType(tr)); } AddTypeParameter(tp); } }
/*CustomAttribute customAttribute; * * public CustomAttribute CustomAttribute { * get { * return customAttribute; * } * }*/ public DomCecilAttribute(CustomAttribute customAttribute) { //this.customAttribute = customAttribute; base.AttributeType = DomCecilMethod.GetReturnType(customAttribute.Constructor); base.Name = customAttribute.Constructor.DeclaringType.FullName; try { foreach (var argument in customAttribute.ConstructorArguments) { AddPositionalArgument(CreateExpressionFor(argument)); } } catch (Exception e) { LoggingService.LogError("Error reading attributes", e); } try { foreach (var namedArgument in customAttribute.Properties) { AddNamedArgument(namedArgument.Name, CreateExpressionFor(namedArgument.Argument)); } } catch (Exception e) { LoggingService.LogError("Error reading attributes", e); } try { foreach (var namedArgument in customAttribute.Fields) { AddNamedArgument(namedArgument.Name, CreateExpressionFor(namedArgument.Argument)); } } catch (Exception e) { LoggingService.LogError("Error reading attributes", e); } }
/*CustomAttribute customAttribute; * * public CustomAttribute CustomAttribute { * get { * return customAttribute; * } * }*/ public DomCecilAttribute(CustomAttribute customAttribute) { //this.customAttribute = customAttribute; base.AttributeType = DomCecilMethod.GetReturnType(customAttribute.Constructor); base.Name = customAttribute.Constructor.DeclaringType.FullName; try { // This Resolve call is required to load enum parameter values. // Without this call, enum parameters are omited. customAttribute.Resolve(); } catch { // If the resolve operation fails, just continue. The enum parameters will // be omited, but there will be other parameters } foreach (object par in customAttribute.ConstructorParameters) { AddPositionalArgument(new System.CodeDom.CodePrimitiveExpression(par)); } foreach (System.Collections.DictionaryEntry entry in customAttribute.Properties) { AddNamedArgument((string)entry.Key, new System.CodeDom.CodePrimitiveExpression(entry.Value)); } foreach (System.Collections.DictionaryEntry entry in customAttribute.Fields) { AddNamedArgument((string)entry.Key, new System.CodeDom.CodePrimitiveExpression(entry.Value)); } }
/* FieldDefinition fieldDefinition; * * public FieldDefinition FieldDefinition { * get { * return fieldDefinition; * } * } */ public DomCecilField(FieldDefinition fieldDefinition) { base.name = fieldDefinition.Name; base.Modifiers = DomCecilType.GetModifiers(fieldDefinition); base.ReturnType = DomCecilMethod.GetReturnType(fieldDefinition.FieldType); DomCecilMethod.AddAttributes(this, fieldDefinition.CustomAttributes); }
public DomCecilMethod(MethodDefinition methodDefinition) { this.methodDefinition = methodDefinition; this.name = methodDefinition.Name; if (methodDefinition.Name == ".ctor") { MethodModifier |= MethodModifier.IsConstructor; } foreach (GenericParameter param in methodDefinition.GenericParameters) { TypeParameter tp = new TypeParameter(param.FullName); tp.Variance = (TypeParameterVariance)(((uint)param.Attributes) & 3); if (param.HasDefaultConstructorConstraint) { tp.TypeParameterModifier |= TypeParameterModifier.HasDefaultConstructorConstraint; } foreach (TypeReference tr in param.Constraints) { tp.AddConstraint(DomCecilMethod.GetReturnType(tr)); } AddTypeParameter(tp); } AddAttributes(this, methodDefinition.CustomAttributes); base.Modifiers = DomCecilType.GetModifiers(methodDefinition); base.ReturnType = DomCecilMethod.GetReturnType(methodDefinition.ReturnType); foreach (ParameterDefinition paramDef in methodDefinition.Parameters) { Add(new DomCecilParameter(paramDef)); } if (this.IsStatic) { foreach (IAttribute attr in this.Attributes) { if (attr.Name == "System.Runtime.CompilerServices.ExtensionAttribute") { MethodModifier |= MethodModifier.IsExtension; break; } } } foreach (MethodReference overrideRef in methodDefinition.Overrides) { if (overrideRef.Name == this.name && IsPublic) { continue; } AddExplicitInterface(GetReturnType(overrideRef.DeclaringType)); } }
public DomCecilEvent(EventDefinition eventDefinition) { this.eventDefinition = eventDefinition; base.name = eventDefinition.Name; base.Modifiers = DomCecilType.GetModifiers(eventDefinition.AddMethod); base.ReturnType = DomCecilMethod.GetReturnType(eventDefinition.EventType); DomCecilMethod.AddAttributes(this, eventDefinition.CustomAttributes); if (!eventDefinition.IsSpecialName) { base.Modifiers &= ~MonoDevelop.Projects.Dom.Modifiers.SpecialName; } }
public DomCecilParameter(ParameterDefinition parameterDefinition) { this.parameterDefinition = parameterDefinition; base.Name = parameterDefinition.Name; // base.modifiers = DomCecilType.GetModifiers (parameterDefinition..Attributes); base.ReturnType = DomCecilMethod.GetReturnType(parameterDefinition.ParameterType); if (parameterDefinition.ParameterType is Mono.Cecil.ByReferenceType) { this.ParameterModifiers = (parameterDefinition.Attributes & ParameterAttributes.Out) == ParameterAttributes.Out ? ParameterModifiers.Out : ParameterModifiers.Ref; } else { this.ParameterModifiers = ParameterModifiers.In; } if ((parameterDefinition.Attributes & ParameterAttributes.Optional) == ParameterAttributes.Optional) { this.ParameterModifiers |= ParameterModifiers.Optional; } if ((parameterDefinition.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault) { this.DefaultValue = new System.CodeDom.CodePrimitiveExpression(parameterDefinition.Constant); } if (ReturnType.ArrayDimensions > 0) { foreach (CustomAttribute customAttribute in parameterDefinition.CustomAttributes) { if (customAttribute.Constructor.DeclaringType.FullName == "System.ParamArrayAttribute") { this.ParameterModifiers |= ParameterModifiers.Params; } } } }