Esempio n. 1
0
        private void ExtractFromField(FieldInfo fieldInfo, TypeExtraction typExtracted)
        {
            FieldExtraction fextraction = new FieldExtraction()
            {
                Name     = fieldInfo.Name,
                TypeName = fieldInfo.FieldType.ToString()
            };

            typExtracted.Fields.Add(fextraction);
        }
Esempio n. 2
0
        private void ExtractFromProperty(PropertyInfo propInfo, TypeExtraction typExtracted)
        {
            FieldExtraction fextraction = new FieldExtraction()
            {
                Name     = $"_{propInfo.Name}",
                TypeName = propInfo.PropertyType.ToString()
            };

            typExtracted.Fields.Add(fextraction);

            PropertyExtraction pextraction = new PropertyExtraction()
            {
                Name     = propInfo.Name,
                TypeName = propInfo.PropertyType.ToString(),
                HasGet   = propInfo.CanRead,
                HasSet   = propInfo.CanWrite
            };

            typExtracted.Properties.Add(pextraction);
        }
        protected virtual string FormatExtractedType(string header, TypeExtraction extractType)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(header);

            sb.AppendLine("#region Usings");
            sb.AppendLine("#endregion\n");

            sb.AppendLine($"\nnamespace {extractType.Namespace}");
            sb.AppendLine("{");

            sb.AppendLine($"\tpublic class {extractType.Name}");
            sb.AppendLine("\t{");

            sb.AppendLine("\t\t#region Fields");
            foreach (var extractTypeField in extractType.Fields)
            {
                sb.AppendLine($"\t\tpublic {extractTypeField.TypeName} {extractTypeField.Name}");
            }
            sb.AppendLine("\t\t#endregion\n");

            sb.AppendLine("\t\t#region Properties");
            foreach (var propField in extractType.Properties)
            {
                FormatProperty(sb, propField);
            }
            sb.AppendLine("\t\t#endregion\n");

            sb.AppendLine("#region Publics");
            foreach (var extractTypeMethod in extractType.Methods)
            {
                FormatMethod(sb, extractTypeMethod);
            }
            sb.AppendLine("#endregion");

            sb.AppendLine("\t}");
            sb.AppendLine("}");

            return(sb.ToString());
        }
Esempio n. 4
0
        private void ExtractFromType(Type type, ProxyExtraction extraction)
        {
            var name = type.Name;

            if (type.IsGenericType)
            {
                int pos = name.IndexOf("`");
                name = $"{type.Name.Substring(0, pos)}<T>";
            }

            TypeExtraction typExtracted = new TypeExtraction()
            {
                Name       = name,
                Namespace  = type.Namespace,
                Fields     = new List <FieldExtraction>(),
                Properties = new List <PropertyExtraction>(),
                Methods    = new List <MethodExtraction>()
            };

            foreach (var fieldInfo in type.GetFields())
            {
                ExtractFromField(fieldInfo, typExtracted);
            }

            foreach (var propertyInfo in type.GetProperties())
            {
                ExtractFromProperty(propertyInfo, typExtracted);
            }

            foreach (var methodInfo in type.GetMethods())
            {
                ExtractFromMethod(methodInfo, typExtracted);
            }

            extraction.TypeExtractions.Add(typExtracted);
        }
Esempio n. 5
0
        private void ExtractFromMethod(MethodInfo methodInfo, TypeExtraction typExtracted)
        {
            MethodExtraction mextraction = new MethodExtraction()
            {
                Name            = methodInfo.Name,
                ReturnValueType = methodInfo.ReturnType.Name,
                Signature       = methodInfo.ToString(),
                Arguments       = new List <MethodArgument>()
                {
                }
            };

            var parameters = methodInfo.GetParameters();

            foreach (var parameterInfo in parameters)
            {
                MethodArgument arg = new MethodArgument()
                {
                    Name = parameterInfo.Name,
                    Type = parameterInfo.ParameterType.ToString()
                };

                foreach (var parameterInfoCustomAttribute in parameterInfo.CustomAttributes)
                {
                    if (parameterInfoCustomAttribute.AttributeType == typeof(ParamArrayAttribute))
                    {
                        arg.IsParams = true;
                        break;
                    }
                }

                mextraction.Arguments.Add(arg);
            }

            typExtracted.Methods.Add(mextraction);
        }