protected string GenSerializerStaticClassCodeByTemplate(Type type, Type[] refTypes, string contentRead, string contentWrite)
    {
        StringBuilder code = new StringBuilder(InitStringBuilderCapacity);

        GenHeaderComment(code);
        NamespaceUtility.GenUsingDirectives(code, refTypes, new [] { "System.IO" });

        code.Append(
            string.Format(
                "\n" +
                "public class {0}\n" +
                "{{\n" +
                "	public static void Read(BinaryReader o)\n"+
                "	{{\n"+
                "{1}" +
                "	}}\n"+
                "\n" +
                "	public static void Write(BinaryWriter o)\n"+
                "	{{\n"+
                "{2}" +
                "	}}\n"+
                "}}\n",
                SerializerFileName(type),
                contentRead,
                contentWrite
                ));

        return(code.ToString());
    }
Example #2
0
        static void ConfigureWcfCountCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("count", (countCommand) =>
            {
                countCommand.Description = "Get WCF Relay Count";

                var connectionStringArgument = countCommand.Argument("connectionString", "Relay ConnectionString");

                countCommand.OnExecute(async() =>
                {
                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    if (string.IsNullOrEmpty(connectionString))
                    {
                        TraceMissingArgument(connectionStringArgument.Name);
                        countCommand.ShowHelp();
                        return(1);
                    }

                    var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                    Uri namespaceUri     = namespaceManager.Address;
                    string namespaceHost = namespaceUri.Host;
                    var tokenProvider    = namespaceManager.Settings.TokenProvider;

                    RelayTraceSource.TraceVerbose($"Getting WcfRelay count for '{namespaceUri}");

                    int count = await NamespaceUtility.GetEntityCountAsync(namespaceUri, tokenProvider, "Relays");
                    RelayTraceSource.TraceInfo(string.Format($"{{0,-{namespaceHost.Length}}}  {{1}}", "Namespace", "WcfRelayCount"));
                    RelayTraceSource.TraceInfo(string.Format($"{{0,-{namespaceHost.Length}}}  {{1}}", namespaceHost, count));

                    return(0);
                });
            });
        }
Example #3
0
        public void Refresh()
        {
            isInstalled = !namespaceclass.IsNullOrEmpty()? NamespaceUtility.IsNamespaceExists(namespaceclass) : true;

            if (!isInstalled)
            {
                isInstalled = !namespaceclass.IsNullOrEmpty()? TypeUtility.IsTypeExist(namespaceclass) : true;
            }

            isPlatformSupported = platforms.IsNullOrEmpty()? true : ArrayUtility.Contains(platforms, EditorUserBuildSettings.activeBuildTarget);
        }
    protected string GenSerializerClassCodeByTemplate(Type type, Type[] refTypes, string construction, string contentRead, string contentWrite)
    {
        StringBuilder code = new StringBuilder(InitStringBuilderCapacity);

        GenHeaderComment(code);
        NamespaceUtility.GenUsingDirectives(code, refTypes, new[] { "System.IO" });

        code.Append(
            string.Format(
                "\n" +
                "public class {0}\n" +
                "{{\n" +
                "	public static {1} Read(BinaryReader o)\n"+
                "	{{\n"+
                (
                    type.IsClass ?
                    "		if(o.ReadBoolean() == false)\n"+
                    "			return {4};\n":""
                ) +
                "		\n"+
                "		{1} d = {5};\n"+
                "{2}" +
                "		return d;\n"+
                "	}}\n"+
                "\n" +
                "	public static void Write(BinaryWriter o, {1} d)\n"+
                "	{{\n"+
                (
                    type.IsClass ?
                    "		o.Write(d != null);\n"+
                    "		if(d == null)\n"+
                    "			return;\n":""
                ) +
                "		\n"+
                "{3}" +
                "	}}\n"+
                "}}\n",
                SerializerFileName(type),
                TypeName(type),
                contentRead,
                contentWrite,
                DefaultValue(type),
                construction
                ));

        return(code.ToString());
    }
Example #5
0
        private INamedTypeSymbol FindClassesWithNameAndAttribute(string fullName, string attribute)
        {
            var name = fullName.Split('.').Last();

            foreach (var comp in projectCompilations.Values)
            {
                INamedTypeSymbol template = comp.GetSymbolsWithName(x => x.Equals(name, System.StringComparison.Ordinal))
                                            .OfType <INamedTypeSymbol>()
                                            .Where(x => NamespaceUtility.IsPartOf(x.ToDisplayString(), fullName))
                                            .FirstOrDefault(x => x.GetAttributes()
                                                            .Any(y => y.AttributeClass.Name.Equals(attribute)));
                if (template != null)
                {
                    return(template);
                }
            }
            return(null);
        }
 //TODO: Not clean. Build a NamespaceUtility that can handle namespaces correctly. See also: Namespace operations in RoslynIntrospector
 internal bool IsSelfReferencingPartial(string partial)
 {
     return(NamespaceUtility.IsPartOf(string.Concat(Namespace, ".", Name), partial));
 }