Esempio n. 1
0
 public void AddDef( ParamDef Item )
 {
     Item.Indexer = Indexer;
     ParamDefs.Add( Item );
     UpdateIndex();
     NotifyChanged( "ParamDefs" );
 }
Esempio n. 2
0
        // [Test] - cant do this yet as we need Signatures to be loaded, we first need to somehow
        //  mock out the Signatures so we can control the return information.
        public void Convert_MethodDef_WhenParametersAndParametersIncluded_ShouldShowParameters()
        {
            MethodDef method = CreateMethod();

            ParamDef parameter = new ParamDef();

            parameter.Name = "test";
            method.Parameters.Add(parameter);
            parameter.Method = method;

            var convertor = new DisplayNameSignitureConvertor(method, true, true);

            string result = convertor.Convert();

            Assert.AreEqual(string.Empty, result);
        }
 /// <inheritdoc/>
 public override uint GetRid(ParamDef pd)
 {
     if (paramDefInfos.TryGetRid(pd, out uint rid))
     {
         return(rid);
     }
     if (pd == null)
     {
         Error("Param is null");
     }
     else
     {
         Error("Param {0} ({1:X8}) is not defined in this module ({2}). A parameter was removed that is still referenced by this module.", pd, pd.MDToken.Raw, module);
     }
     return(0);
 }
        public TypeRef ResolveParameter(AssemblyDef assembly, ParamDef declaringParameter)
        {
            TypeRef typeRef = null;

            if (_isTypeSigniture)
            {
                TypeSignatureToken typeToken = Tokens.Last() as TypeSignatureToken;
                typeRef = typeToken.ResolveType(assembly, declaringParameter);
            }
            else
            {
                typeRef = _elementType.ResolveToken(assembly);
            }

            return(typeRef);
        }
Esempio n. 5
0
        public override void GenerateDetailedHelp(IOutput output, MessageProvider messageProvider, Command command)
        {
            output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpTitle, command.Name, command.Keyword));

            output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpName, command.Name), true);
            output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpDescription, command.Description), true);
            output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpKeyword, command.Keyword));

            output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpAliases, command.Aliases.Delimited), true);

            output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpUsage, command.GetUsage()));

            if (!command.Parameters.IsEmpty)
            {
                output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpParamTitle), true);

                for (int i = 0; i < command.Parameters.Count; i++)
                {
                    ParamDef paramDef = command.Parameters[i];

                    string validValues = string.Empty;

                    if (paramDef.Type.IsEnum)
                    {
                        validValues = string.Join("|", Enum.GetNames(paramDef.Type));
                    }

                    output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpParam, paramDef.Usage, paramDef.Description, validValues));
                }
            }

            List <Command> decendents = new List <Command>();

            command.GetDecendents(ref decendents, false);
            decendents.RemoveAt(0);

            if (decendents.Count > 0)
            {
                output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpSubCommandTitle), true);

                foreach (Command c in decendents)
                {
                    output.WriteLine(Level.None, messageProvider.GetFormatted(StandardMessages.DetailedHelpSubCommand, c.GetUsage(), c.Description));
                }
            }
        }
Esempio n. 6
0
        ParamDef Clone(MethodDef sourceMethod, MethodDef targetMethod, ParamDef source)
        {
            ParamDef result = new ParamDefUser(source.Name, source.Sequence, source.Attributes);

            result = Context.Fire(new NetfuserEvent.CreateMethodParameter(Context, source, targetMethod, _tm)
            {
                Target = result
            }).Target;
            if (source.HasConstant)
            {
                result.Constant = Clone(source.Constant);
            }
            CopyMarshalType(source, result);
            CopyCustomAttributes(source, result);
            CopyCustomDebugInfo(source, result);
            return(result);
        }
        public void IsIndexer_WhenSetterHasSingleParameters_IsIndexerReturnsFalse()
        {
            ParamDef parameter = new ParamDef();

            MethodDef setMethod = new MethodDef();

            setMethod.Parameters = new System.Collections.Generic.List <ParamDef>();
            setMethod.Parameters.Add(parameter);

            PropertyDef property = new PropertyDef();

            property.Setter = setMethod;

            bool result = property.IsIndexer();

            Assert.AreEqual(false, result);
        }
        public void IsIndexer_WhenGetterHasParameters_IsIndexerReturnsTrue()
        {
            ParamDef parameter = new ParamDef();

            MethodDef getMethod = new MethodDef();

            getMethod.Parameters = new System.Collections.Generic.List <ParamDef>();
            getMethod.Parameters.Add(parameter);

            PropertyDef property = new PropertyDef();

            property.Getter = getMethod;

            bool result = property.IsIndexer();

            Assert.AreEqual(true, result);
        }
Esempio n. 9
0
 bool WriteRefIfByRef(IDecompilerOutput output, TypeSig typeSig, ParamDef pd)
 {
     if (typeSig.RemovePinnedAndModifiers() is ByRefSig)
     {
         if (pd != null && (!pd.IsIn && pd.IsOut))
         {
             output.Write("out", BoxedTextColor.Keyword);
             output.Write(" ", BoxedTextColor.Text);
         }
         else
         {
             output.Write("ref", BoxedTextColor.Keyword);
             output.Write(" ", BoxedTextColor.Text);
         }
         return(true);
     }
     return(false);
 }
        protected List <SyntaxToken> FormatParameterModifiers(ParameterDetails details)
        {
            ParamDef           parameterDefinition = details.Parameter;
            List <SyntaxToken> tokens = new List <SyntaxToken>();

            if (parameterDefinition.IsOut)
            {
                tokens.Add(Constants.KeywordOut);
                tokens.Add(Constants.Space);
            }
            else if (details.TypeDetails.IsByRef)
            {
                tokens.Add(Constants.KeywordRef);
                tokens.Add(Constants.Space);
            }

            return(tokens);
        }
Esempio n. 11
0
        /// <summary>
        /// Converts a generic variable for display.
        /// </summary>
        /// <param name="sb">The current display name for the signiture to append details to.</param>
        /// <param name="sequence">The sequence number of the current generic variable</param>
        /// <param name="parameter">The parameter definition information.</param>
        protected override void ConvertVar(StringBuilder sb, uint sequence, ParamDef parameter)
        {
            // Type Generic Parameter
            GenericTypeRef foundGenericType = null;

            foreach (GenericTypeRef current in _type.GenericTypes)
            {
                if (current.Sequence == sequence)
                {
                    foundGenericType = current;
                    break;
                }
            }
            if (foundGenericType != null)
            {
                sb.Append(foundGenericType.Name);
            }
        }
Esempio n. 12
0
 bool WriteRefIfByRef(ITextOutput output, TypeSig typeSig, ParamDef pd)
 {
     if (typeSig.RemovePinnedAndModifiers() is ByRefSig)
     {
         if (pd != null && (!pd.IsIn && pd.IsOut))
         {
             output.Write("out", TextTokenKind.Keyword);
             output.WriteSpace();
         }
         else
         {
             output.Write("ref", TextTokenKind.Keyword);
             output.WriteSpace();
         }
         return(true);
     }
     return(false);
 }
Esempio n. 13
0
        private static void GetParemeters(JToken itemInput, ParamDef paramDef)
        {
            var item = itemInput.FirstOrDefault(o => o["key"].ToString() == "name");

            paramDef.Name = item["value"].ToString();
            if (itemInput.Any(o => o["key"].ToString() == "type"))
            {
                paramDef.Type = itemInput.FirstOrDefault(o => o["key"].ToString() == "type")["value"].ToString();
            }
            if (itemInput.Any(o => o["key"].ToString() == "format"))
            {
                paramDef.Format = itemInput.FirstOrDefault(o => o["key"].ToString() == "format")["value"].ToString();
                if (paramDef.Format == "date-time")
                {
                    paramDef.Type = paramDef.Format;
                }
            }
        }
        /// <inheritdoc/>
        public override uint GetRid(ParamDef pd)
        {
            uint rid;

            if (paramDefInfos.TryGetRid(pd, out rid))
            {
                return(rid);
            }
            if (pd == null)
            {
                Error("Param is null");
            }
            else
            {
                Error("Param {0} ({1:X8}) is not defined in this module ({2})", pd, pd.MDToken.Raw, module);
            }
            return(0);
        }
Esempio n. 15
0
        public static void MakeAccessible(this ParamDef parameter, AccessMode mode)
        {
            if (parameter.IsAccessible(mode))
            {
                return;
            }
            ParamAttributes attributes = parameter.Attributes;

            if (mode.HasFlag(AccessMode.Read))
            {
                attributes &= ~ParamAttributes.Out;
            }
            if (mode.HasFlag(AccessMode.Write))
            {
                attributes &= ~ParamAttributes.In;
            }
            parameter.Attributes = attributes;
        }
Esempio n. 16
0
        private static PartCodeResult GetPartResult(PartCodeInnput input)
        {
            JToken token        = JToken.Parse(input.Json);
            var    paramDefList = new List <ParamDef>();
            var    ErrorCount   = 0;

            if (input.TemplateName == TemplateType.QueryParamsDef ||
                input.TemplateName == TemplateType.Filters ||
                input.TemplateName == TemplateType.QueryParamsQueryCode)
            {
                foreach (var item in token.SelectToken(input.JsonPath))
                {
                    try
                    {
                        var def = new ParamDef();
                        GetParemeters(item, def);
                        paramDefList.Add(def);
                    }
                    catch { ErrorCount++; }
                }
            }
            else
            {
                foreach (var item in token.SelectToken(input.JsonPath))
                {
                    try
                    {
                        var def = new ParamDef();
                        GetProperties(item, def);
                        paramDefList.Add(def);
                    }
                    catch { ErrorCount++; }
                }
            }

            var result = new PartCodeResult
            {
                TemplateName = input.TemplateName,
                Properties   = paramDefList,
                ErrorCount   = ErrorCount
            };

            return(result);
        }
Esempio n. 17
0
 public static void Set(this ParamDef paramDef, ParamDef source)
 {
     paramDef.Name     = source.Name;
     paramDef.Sequence = source.Sequence;
     //paramDef.Rid = source.Rid;
     if (source.HasMarshalType)
     {
         paramDef.MarshalType = source.MarshalType;
     }
     if (source.HasConstant)
     {
         paramDef.Constant = source.Constant;
     }
     paramDef.Attributes = source.Attributes;
     foreach (var ca in source.CustomAttributes)
     {
         paramDef.CustomAttributes.Add(ca);
     }
 }
Esempio n. 18
0
 private static void FillRefProperties(ParamDef paramDef, JToken refData)
 {
     if (refData.Count() > 1)
     {
         if (refData.Any(o => o["key"].ToString().ToLower() == "enum")
             &&
             refData.Any(o => o["key"].ToString().ToLower() == "x-enumnames")
             )
         {
             var enumNames  = refData.FirstOrDefault(o => o["key"].ToString().ToLower() == "x-enumnames")["value"];
             var enumValues = refData.FirstOrDefault(o => o["key"].ToString().ToLower() == "enum")["value"];
             Dictionary <string, string> EnumDef = new Dictionary <string, string>();
             for (int i = 0; i < enumValues.Count(); i++)
             {
                 if (!EnumDef.Keys.Contains(enumNames[i].ToString()))
                 {
                     EnumDef.Add(enumNames[i].ToString(), enumValues[i].ToString());
                 }
             }
             paramDef.EnumDef = EnumDef;
             paramDef.Type    = "enum";
         }
     }
 }
Esempio n. 19
0
        protected List <TypeDependency> PatchDependency(ModuleDef module, IEnumerable <TypeDependency> dependencies)
        {
            List <TypeDependency> owned = new List <TypeDependency>();

            foreach (TypeDependency type in dependencies)
            {
                if (!TryResolve(module, type.Descriptor.Signature, out TypeDef typeDef))
                {
                    continue;
                }
                owned.Add(type);
                typeDef.MakeAccessible(type.Descriptor.AccessLevel);
                foreach (FieldDescriptor field in type.FieldDependencies)
                {
                    FieldDef fieldDef = Resolve(module, field.Signature);
                    fieldDef.MakeAccessible(field.AccessLevel);
                    fieldDef.IsInitOnly &= field.IsInitOnly;
                }
                foreach (MethodDescriptor method in type.MethodDependencies)
                {
                    MethodDef methodDef = Resolve(module, method.Signature);
                    methodDef.MakeAccessible(method.AccessLevel);
                    if (method.ReturnType != null && !module.ToSig(typeSubstitutions.Substitute(method.ReturnType)).IsAssignable(methodDef.ReturnType, AccessMode.Write))
                    {
                        throw new PatchException("dependency and original have incompatible types");
                    }
                    // TODO: Add other checks (e.g. virtual)
                    foreach (ParameterDescriptor parameter in method.Parameters)
                    {
                        ParamDef parameterDef = Resolve(module, parameter.Signature);
                        parameterDef.MakeAccessible(parameter.AccessMode);
                    }
                }
            }
            return(owned);
        }
Esempio n. 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParameterReflectionNode" /> class.
 /// </summary>
 /// <param name="parameterDefinition">The parameter definition.</param>
 /// <param name="methodDefinition">The method definition.</param>
 /// <param name="parent">The parent.</param>
 public ParameterReflectionNode(ParamDef parameterDefinition, MethodDef methodDefinition, MethodReflectionNode parent)
 {
     _parameterDefinition = parameterDefinition;
     _methodDefinition    = methodDefinition;
     Parent = parent;
 }
Esempio n. 21
0
 public virtual FileTreeNodeFilterResult GetResult(MethodDef method, ParamDef param)
 {
     return(new FileTreeNodeFilterResult());
 }
Esempio n. 22
0
 public virtual DocumentTreeNodeFilterResult GetResult(MethodDef method, ParamDef param) => new DocumentTreeNodeFilterResult();
Esempio n. 23
0
 /// <summary>
 /// Converts a generic variable for cref.
 /// </summary>
 /// <param name="sb">The current cref name for the signiture to append details to.</param>
 /// <param name="sequence">The sequence number of the current generic variable</param>
 /// <param name="parameter">The parameter definition information.</param>
 protected virtual void ConvertMVar(StringBuilder sb, uint sequence, ParamDef parameter)
 {
     sb.Append("``");
     sb.Append(sequence);
 }
 public virtual DocumentTreeNodeFilterResult GetResult(MethodDef method, ParamDef param) => filter.GetResult(method, param);
Esempio n. 25
0
 private int Indexer( ParamDef P )
 {
     return ParamDefs.IndexOf( P );
 }
Esempio n. 26
0
 public ParamInfo(ParamDef paramDef)
 {
     this.paramDef = paramDef;
     this.oldName = paramDef.ParameterDefinition.Name;
     this.newName = paramDef.ParameterDefinition.Name;
 }
Esempio n. 27
0
 public ParamInfo param(ParamDef param)
 {
     return memberInfos.param(param);
 }
Esempio n. 28
0
		/// <inheritdoc/>
		public override uint GetRid(ParamDef pd) {
			uint rid;
			if (paramDefInfos.TryGetRid(pd, out rid))
				return rid;
			if (pd == null)
				Error("Param is null");
			else
				Error("Param {0} ({1:X8}) is not defined in this module ({2}). A parameter was removed that is still referenced by this module.", pd, pd.MDToken.Raw, module);
			return 0;
		}
Esempio n. 29
0
        /// <summary>
        /// Creates a control for a parameter
        /// </summary>
        /// <param name="param">The type of the parameter that will be displayed</param>
        /// <param name="location">The location at which the control should be added</param>
        /// <returns>An IParam object that's been added to the control</returns>
        private IParam AddParam(ParamDef param, Point location)
        {
            UserControl c = null;

            switch (param.ParamType)
            {
            case BoxPropType.Boolean:

                c = new BoolParam();
                break;

            case BoxPropType.DateTime:

                c = new DateTimeParam();
                break;

            case BoxPropType.Enumeration:

                c = new EnumParam();
                (c as EnumParam).EnumValues        = param.EnumValues;
                (c as EnumParam).EnumValueChanged += new EventHandler(ConstructorsViewer_EnumValueChanged);
                break;

            case BoxPropType.Map:

                c = new MapParam();
                break;

            case BoxPropType.Numeric:

                c = new NumericParam();
                break;

            case BoxPropType.Other:

                c = new TextParam();
                (c as TextParam).IsOther = true;
                break;

            case BoxPropType.Point3D:

                c = new Point3DParam();
                break;

            case BoxPropType.Text:

                c = new TextParam();
                break;

            case BoxPropType.TimeSpan:

                c = new TimeSpanParam();
                break;
            }

            (c as IParam).ParamName = param.Name;
            c.Location = location;
            Controls.Add(c);

            return(c as IParam);
        }
Esempio n. 30
0
 public static bool IsReadOnlyParameter(ParamDef pd) => HasIsReadOnlyAttribute(pd?.CustomAttributes);
Esempio n. 31
0
 public void RemoveDef( ParamDef Item )
 {
     ParamDefs.Remove( Item );
     UpdateIndex();
     NotifyChanged( "ParamDefs" );
 }
Esempio n. 32
0
        /// <summary>
        /// Method which performs the actual conversion of a signiture to a cref string.
        /// </summary>
        /// <param name="sb">The string builder to hold the converted text</param>
        /// <param name="assembly">The assembly the current parameter is defined in</param>
        /// <param name="param">The parameter definition, required for token resolution</param>
        /// <param name="currentToken">The current token to converty</param>
        /// <param name="elementType">The type of element the token represents</param>
        /// <param name="resolvedType">The resolved type for this token.</param>
        private void Convert(StringBuilder sb, AssemblyDef assembly, ParamDef param, SignatureToken currentToken, ElementTypes elementType, TypeRef resolvedType)
        {
            StringBuilder convertedSigniture = sb;

            if (currentToken.TokenType == SignatureTokens.Param)
            {
                ParamSignatureToken paramToken = currentToken as ParamSignatureToken;
                SignatureToken      childToken = paramToken.Tokens[paramToken.Tokens.Count - 1];

                if (childToken.TokenType == SignatureTokens.Type)
                {
                    currentToken = childToken;
                    elementType  = ((TypeSignatureToken)childToken).ElementType.ElementType;
                }
                else
                {
                    currentToken = childToken;
                    elementType  = ((ElementTypeSignatureToken)childToken).ElementType;
                }
            }

            TypeSignatureToken        typeToken    = currentToken as TypeSignatureToken;
            ElementTypeSignatureToken elementToken = currentToken as ElementTypeSignatureToken;

            switch (elementType)
            {
            case ElementTypes.Var: ConvertVar(convertedSigniture, typeToken.ElementType.Token, param); break;

            case ElementTypes.MVar: ConvertMVar(convertedSigniture, typeToken.ElementType.Token, param); break;

            case ElementTypes.SZArray:
                // TODO: Fix the custom modifier section
                if (typeToken.Tokens[0] is CustomModifierToken)
                {
                    NotImplementedException ex = new NotImplementedException("Custom modifiers are not implemented on SZArray");
                    ex.Data["token"] = currentToken;
                    throw ex;
                }

                ElementTypes szArrayElementType;
                if (typeToken.Tokens[1].TokenType == SignatureTokens.Type)
                {
                    szArrayElementType = ((TypeSignatureToken)typeToken.Tokens[1]).ElementType.ElementType;
                }
                else
                {
                    szArrayElementType = ((ElementTypeSignatureToken)typeToken.Tokens[1]).ElementType;
                }

                Convert(
                    sb,
                    assembly,
                    param,
                    typeToken.Tokens[1],
                    szArrayElementType,
                    resolvedType);

                convertedSigniture.Append("[]");
                break;

            case ElementTypes.Array:
                ArrayShapeSignatureToken shape = typeToken.Tokens.Last() as ArrayShapeSignatureToken;
                ConvertArray(convertedSigniture, resolvedType, shape);
                break;

            case ElementTypes.GenericInstance:
                TypeRef genericType = ((ElementTypeSignatureToken)typeToken.Tokens[1]).ResolveToken(assembly);
                GetTypeName(convertedSigniture, genericType);

                GenericArgumentCountSignatureToken argsCount = typeToken.GetGenericArgumentCount();
                bool isFirstArgument = true;
                if (argsCount.Count > 0)
                {
                    sb.Append(GenericStart);
                    for (int j = 0; j < argsCount.Count; j++)
                    {
                        if (isFirstArgument)
                        {
                            isFirstArgument = false;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        TypeRef      argResolvedType;
                        ElementTypes elType;
                        if (typeToken.Tokens[j + 3].TokenType == SignatureTokens.ElementType)
                        {
                            ElementTypeSignatureToken gESig = (ElementTypeSignatureToken)typeToken.Tokens[j + 3];
                            argResolvedType = gESig.ResolveToken(assembly);
                            elType          = gESig.ElementType;
                        }
                        else
                        {
                            TypeSignatureToken gTSig = (TypeSignatureToken)typeToken.Tokens[j + 3];
                            argResolvedType = gTSig.ResolveType(assembly, param);
                            elType          = gTSig.ElementType.ElementType;
                        }

                        Convert(
                            sb,
                            assembly,
                            param,
                            typeToken.Tokens[j + 3],
                            elType,
                            argResolvedType);
                    }
                    sb.Append(GenericEnd);
                }
                break;

            case ElementTypes.Class:
            case ElementTypes.ValueType:
            case ElementTypes.Char:
            case ElementTypes.I:
            case ElementTypes.I1:
            case ElementTypes.I2:
            case ElementTypes.I4:
            case ElementTypes.I8:
            case ElementTypes.Object:
            case ElementTypes.R4:
            case ElementTypes.R4_HFA:
            case ElementTypes.R8:
            case ElementTypes.R8_HFA:
            case ElementTypes.String:
            case ElementTypes.U:
            case ElementTypes.U1:
            case ElementTypes.U2:
            case ElementTypes.U4:
            case ElementTypes.U8:
            case ElementTypes.TypedByRef:
            case ElementTypes.Boolean:
                GetTypeName(convertedSigniture, resolvedType);
                break;

            case ElementTypes.Ptr:
                GetTypeName(convertedSigniture, resolvedType);
                convertedSigniture.Append("*");
                break;

            case ElementTypes.FunctionPointer:
                NotImplementedException fnPtrEx = new NotImplementedException("Function Pointer is not implemented yet.");
                fnPtrEx.Data["token"] = currentToken;
                throw fnPtrEx;
            }
        }
Esempio n. 33
0
 void add(ParamDef pd)
 {
     if (pd == null)
         return;
     add(pd.DeclaringMethod);
     add(pd.CustomAttributes);
 }
Esempio n. 34
0
        /// <summary>
        /// Converts the method parameters to a cref path implementation, this in itself
        /// is not enough. This is used by the cref parse methods.
        /// </summary>
        /// <param name="method">The method to convert the parameters for.</param>
        /// <returns>The converted string.</returns>
        protected string Convert(MethodDef method)
        {
            Signature     loadedSigniture    = method.Signiture;
            StringBuilder convertedSigniture = new StringBuilder();

            List <ParamSignatureToken> parametersToConvert = loadedSigniture.GetParameterTokens();

            if (parametersToConvert != null && parametersToConvert.Count > 0)
            {
                bool hadReturnParameter = false;
                bool isFirstParameter   = true;
                convertedSigniture.Append("(");
                for (int i = 0; i < method.Parameters.Count; i++)
                {
                    ParamDef currentParameter = method.Parameters[i];
                    if (currentParameter.Sequence == 0)
                    {
                        hadReturnParameter = true;
                        continue;
                    }
                    if (!IncludeFirstParameter && (i == 0 || hadReturnParameter && i == 1))
                    {
                        continue;
                    }

                    ParamSignatureToken currentToken = parametersToConvert[hadReturnParameter ? i - 1 : i];
                    TypeRef             typeRef      = currentToken.ResolveParameter(method.Assembly, currentParameter);

                    if (isFirstParameter)
                    {
                        isFirstParameter = false;
                    }
                    else
                    {
                        convertedSigniture.Append(ParameterSeperater);
                    }

                    if (ByRefAtFront)
                    {
                        if (currentToken.IsByRef)
                        {
                            convertedSigniture.Append(ByRef);
                        }
                    }

                    this.Convert(
                        convertedSigniture,
                        method.Assembly,
                        currentParameter,
                        currentToken,
                        currentToken.ElementType.ElementType,
                        typeRef);

                    if (!ByRefAtFront)
                    {
                        if (currentToken.IsByRef)
                        {
                            convertedSigniture.Append(ByRef);
                        }
                    }
                }

                convertedSigniture.Append(")");
            }

            return(convertedSigniture.ToString());
        }
Esempio n. 35
0
 public static Function Template1(string name, Target[] targets, TypeBase[] targetTypes, ParamDef ret, params ParamDef[] args)
 {
     var p = new ParameterInfo { Targets = targets, TargetTypes = targetTypes, SizeFlags = SizeFlags.None };
     return new Function { Name = name, Parameters = new[] { p }, ParamList = (f, p2) => args.Select(arg => arg.ParamDecl(f, p2)).ToArray(), Return = (f, p2) => ret.ParamDecl(f, p2) };
 }
Esempio n. 36
0
        public GenCodeOutput GetConfig(GenCodeConfigInput input, Dictionary <string, List <string> > ErrorDict)
        {
            var           Model         = JObject.Parse(input.JsonData);
            GenCodeOutput genCodeConfig = new GenCodeOutput();

            genCodeConfig.Tag = Model["tag"].ToString();
            genCodeConfig.ServiceClassName = genCodeConfig.Tag + "ServiceProxy";

            List <string> dtoNames = new List <string>();

            dtoNames.Add(genCodeConfig.ServiceClassName);

            #region list
            var listApi = new ListApi();
            if (!string.IsNullOrEmpty(input.ListDtoName))
            {
                listApi.ListResultDtoName = input.ListDtoName;
            }
            else
            {
                listApi.ListResultDtoName = Model.SelectToken("$.ListApi.responses[0].value[1].value[0].value.refName").ToString();
            }
            var ListApiName = Model.SelectToken("$.ListApi.path").ToString();
            if (!string.IsNullOrEmpty(ListApiName))
            {
                ListApiName = ListApiName.Split('/', StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
            }
            listApi.JsMethodName = ListApiName;
            dtoNames.Add(listApi.ListResultDtoName);
            genCodeConfig.ListApi = listApi;

            if (!string.IsNullOrEmpty(input.ListItemsDtoName))
            {
                listApi.ListResultDtoItemName = input.ListItemsDtoName;
            }
            else
            {
                try
                {
                    listApi.ListResultDtoItemName = Model.SelectToken("$.ListApi.responses[0].value[1].value[0].value.refData[1].value[1].value[2].value[0].value.refName").ToString();
                }
                catch (Exception)
                {
                    throw new Exception("ListResultDtoItemName Not Found , 它不在默认路径下:$.ListApi.responses[0].value[1].value[0].value.refData[1].value[1].value[2].value[0].value.refName/r/n 请手动指定名称");
                }
            }
            genCodeConfig.ListApi = listApi;
            dtoNames.Add(listApi.ListResultDtoItemName);
            JToken ListReturnPropertiesDef = Model.SelectToken("$.ListApi.responses[0].value[1].value[0].value.refData[1].value[1].value[2].value[0].value.refData[1].value");

            if (!string.IsNullOrEmpty(input.ListPropertiesJsonPath))
            {
                ListReturnPropertiesDef = Model.SelectToken(input.ListPropertiesJsonPath);
            }
            if (ListReturnPropertiesDef != null)
            {
                foreach (var item in ListReturnPropertiesDef)
                {
                    ParamDef paramDef = new ParamDef();
                    try
                    {
                        GetProperties(item, paramDef);
                    }
                    catch
                    {
                        PushDict(ErrorDict, "ListReturnPropertiesDef", item.ToString());
                        continue;
                    }
                    genCodeConfig.ListApi.Properties.Add(paramDef);
                }
            }


            var SelectParams = Model.SelectToken("ListApi.parameters");
            if (!string.IsNullOrEmpty(input.ListParamsJsonPath))
            {
                SelectParams = Model.SelectToken(input.ListParamsJsonPath);
            }
            foreach (var item in SelectParams)
            {
                ParamDef paramDef = new ParamDef();
                try
                {
                    GetParemeters(item, paramDef);
                }
                catch
                {
                    PushDict(ErrorDict, "SelectParams", item.ToString());
                    continue;
                }
                genCodeConfig.ListApi.Parameters.Add(paramDef);
            }

            #endregion

            var EnableCreate = Model["CreateApi"] != null;
            if (EnableCreate)
            {
                var createApi = new Createapi();
                if (!string.IsNullOrWhiteSpace(input.UpdateDtoName))
                {
                    createApi.RequestDtoName = input.UpdateDtoName;
                }
                else
                {
                    var UpdateDtoNamePath = Model.SelectToken("$.CreateApi.parameters[0]");
                    foreach (var o in UpdateDtoNamePath)
                    {
                        if (o["value"] != null && o["value"].Count() > 1)
                        {
                            var item = o["value"].FirstOrDefault();
                            if (item.SelectToken("value.refName") != null)
                            {
                                createApi.RequestDtoName = item.SelectToken("value.refName").ToString();
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                //if (string.IsNullOrWhiteSpace(createApi.RequestDtoName))
                //{
                //    throw new Exception("未在默认路径下找到 CreateDtoName 请指定 CreateDtoName ");
                //}
                var CreateDtoDef = Model.SelectToken("$.CreateApi.parameters[0][3].value[0].value.refData[1].value");
                if (!string.IsNullOrEmpty(input.CreateParamsJsonPath))
                {
                    CreateDtoDef = Model.SelectToken(input.CreateParamsJsonPath);
                }
                if (CreateDtoDef == null)
                {
                    throw new Exception("在指定路径:未找到创建参数清单。");
                }
                foreach (var item in CreateDtoDef)
                {
                    ParamDef paramDef = new ParamDef();
                    try
                    {
                        GetProperties(item, paramDef);
                    }
                    catch
                    {
                        PushDict(ErrorDict, "CreateDtoDef", item.ToString());
                        continue;
                    }
                    createApi.Properties.Add(paramDef);
                }
                var CreateApiName = Model["CreateApi"]["path"].ToString().Split('/', StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
                createApi.JsMethodName = CreateApiName.ToLowerStart();
                dtoNames.Add(createApi.RequestDtoName);
                genCodeConfig.CreateApi = createApi;
            }

            var EnableUpdate = Model["UpdateApi"] != null;
            if (EnableUpdate)
            {
                Updateapi updateapi    = new Updateapi();
                var       UpdateDtoDef = Model.SelectToken("$.UpdateApi.parameters[0][3].value[0].value.refData[1].value");
                if (!string.IsNullOrWhiteSpace(input.UpdateParamsJsonPath))
                {
                    UpdateDtoDef = Model.SelectToken(input.UpdateParamsJsonPath);
                }

                foreach (var item in UpdateDtoDef)
                {
                    ParamDef paramDef = new ParamDef();
                    try
                    {
                        GetProperties(item, paramDef);
                    }
                    catch
                    {
                        PushDict(ErrorDict, "CreateDtoDef", item.ToString());
                        continue;
                    }
                    updateapi.Properties.Add(paramDef);
                }
                if (!string.IsNullOrWhiteSpace(input.UpdateDtoName))
                {
                    updateapi.RequestDtoName = input.UpdateDtoName;
                }
                else
                {
                    var UpdateDtoNamePath = Model.SelectToken("$.UpdateApi.parameters[0]");
                    foreach (var o in UpdateDtoNamePath)
                    {
                        if (o["value"] != null && o["value"].Count() > 1)
                        {
                            var item = o["value"].FirstOrDefault();
                            if (item.SelectToken("value.refName") != null)
                            {
                                updateapi.RequestDtoName = item.SelectToken("value.refName").ToString();
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                //if (string.IsNullOrWhiteSpace(updateapi.RequestDtoName))
                //{
                //    throw new Exception("未在默认路径下找到 CreateDtoName 请指定 CreateDtoName ");
                //}
                dtoNames.Add(updateapi.RequestDtoName);
                var UpdateApiName = Model["UpdateApi"]["path"].ToString().Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
                updateapi.JsMethodName  = UpdateApiName.ToLowerStart();
                genCodeConfig.UpdateApi = updateapi;
            }

            var EnableDelete = Model["DeleteApi"] != null;
            if (EnableDelete)
            {
                Deleteapi deleteapi     = new Deleteapi();
                var       DeleteApiName = Model["DeleteApi"]["path"].ToString().Split('/', StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
                deleteapi.JsMethodName  = DeleteApiName.ToLowerStart();
                genCodeConfig.DeleteApi = deleteapi;
            }

            genCodeConfig.ImportClassNames = dtoNames;

            return(genCodeConfig);
        }
Esempio n. 37
0
 void Add(ParamDef pd)
 {
     if (pd == null)
         return;
     Add(pd.DeclaringMethod);
     Add(pd.CustomAttributes);
     Add(pd.MarshalType);
 }
Esempio n. 38
0
 public void WriteType(ITextColorWriter output, ITypeDefOrRef type, bool includeNamespace, ParamDef pd = null) =>
 TypeToString(TextColorWriterToDecompilerOutput.Create(output), type, includeNamespace, pd);
		/// <inheritdoc/>
		public override uint GetRid(ParamDef pd) {
			uint rid;
			if (paramDefInfos.TryGetRid(pd, out rid))
				return rid;
			if (pd == null)
				Error("Param is null");
			else
				Error("Param {0} ({1:X8}) is not defined in this module ({2})", pd, pd.MDToken.Raw, module);
			return 0;
		}
Esempio n. 40
0
 public virtual FileTreeNodeFilterResult GetResult(MethodDef method, ParamDef param) => new FileTreeNodeFilterResult(FilterType.Hide, false);
Esempio n. 41
0
 public ParamInfo param(ParamDef param)
 {
     return allParamInfos[param];
 }