Beispiel #1
0
        public static CodeSnippetTypeMember CreateCast(string typeT, string typeT1, bool useAutoTyping, string @namespace = "",
                                                       GeneratedTypesVisibility visibility = GeneratedTypesVisibility.Public)
        {
            CodeSnippetTypeMember castMember = new CodeSnippetTypeMember();

            @namespace = @namespace.IsNotEmpty() ? $"{@namespace}." : "";
            var visibilityKeyword = visibility.ToKeyword();
            var servicesClassName = @namespace + NameGenerator.GetServicesClassName();

            if (useAutoTyping)
            {
                castMember.Text = String.Concat($"\t\t{visibilityKeyword} static explicit operator ", typeT, "(XElement xe) {  ",
                                                "return (", typeT, ")", Constants.XTypedServices, ".ToXTypedElement(xe,",
                                                servicesClassName, ".Instance as ILinqToXsdTypeManager); }");
            }
            else
            {
                castMember.Text = String.Concat($"\t\t{visibilityKeyword} static explicit operator ", typeT,
                                                "(XElement xe) { return ", Constants.XTypedServices, ".ToXTypedElement<",
                                                GetInnerType(typeT, typeT1), ">(xe,", servicesClassName,
                                                ".Instance as ILinqToXsdTypeManager); }");
            }

            return(castMember);
        }
 /// <summary>
 /// Creates a new <see cref="Namespace"/> instance from given values. Defaults to <see cref="GeneratedTypesVisibility.Public"/> <paramref name="visibility"/>.
 /// </summary>
 /// <param name="schemaUri"></param>
 /// <param name="clrNamespace"></param>
 /// <param name="visibility"></param>
 /// <returns></returns>
 public static Namespace New(string schemaUri, string clrNamespace, GeneratedTypesVisibility visibility = GeneratedTypesVisibility.Public)
 {
     return(new Namespace {
         DefaultVisibility = visibility.ToKeyword(),
         Schema = schemaUri.IsEmpty() ? null : new Uri(schemaUri),
         Clr = clrNamespace
     });
 }
Beispiel #3
0
        public static CodeSnippetTypeMember CreateXRootGetter(string typeName, string fqTypeName, LocalSymbolTable lst,
                                                              GeneratedTypesVisibility visibility = GeneratedTypesVisibility.Public)
        {
            string symbolName = lst.AddMember(typeName);
            CodeSnippetTypeMember castMember = new CodeSnippetTypeMember();

            castMember.Text = String.Concat("\r\n", $"\t\t{visibility.ToKeyword()} ", fqTypeName, " ", symbolName, " {  get {",
                                            "return rootObject as ", fqTypeName, "; } }");
            return(castMember);
        }