Beispiel #1
0
 public static Attribute ForLowerCaseProperty()
 {
     return(new Attribute
     {
         Type = new Type(NamesService.GetExtensionTypeName("LowerCasePropertyAttribute"))
     });
 }
Beispiel #2
0
 public EnsureQueryMethod(OdcmClass odcmClass)
 {
     Visibility           = Visibility.Private;
     Name                 = "EnsureQuery";
     FetchedType          = new Type(NamesService.GetConcreteTypeName(odcmClass));
     FetchedTypeInterface = new Type(NamesService.GetConcreteInterfaceName(odcmClass));
     ReturnType           = new Type(NamesService.GetExtensionTypeName("IReadOnlyQueryableSet"), new Type(NamesService.GetConcreteInterfaceName(odcmClass)));
 }
 public CollectionExecuteAsyncMethod(OdcmClass odcmClass)
 {
     Name       = "ExecuteAsync";
     Parameters = Parameter.Empty;
     ReturnType = new Type(new Identifier("global::System.Threading.Tasks", "Task"),
                           new Type(NamesService.GetExtensionTypeName("IPagedCollection"),
                                    new Type(NamesService.GetConcreteInterfaceName(odcmClass))));
 }
Beispiel #4
0
 public static IEnumerable <Property> ForEntityContainer(OdcmClass odcmContainer)
 {
     return(Properties.ForEntityContainerInterface(odcmContainer)
            .Concat(new Property[]
     {
         new AutoProperty("Context", new Type(NamesService.GetExtensionTypeName("DataServiceContextWrapper")),
                          privateSet: true)
     }));
 }
Beispiel #5
0
 public static Field ForStructuralProperty(OdcmProperty property)
 {
     return(new Field
     {
         Name = NamesService.GetPropertyFieldName(property),
         Type = property.IsCollection
             ? new Type(NamesService.GetExtensionTypeName("NonEntityTypeCollectionImpl"), new Type(NamesService.GetConcreteTypeName(property.Type)))
             : TypeService.GetPropertyType(property)
     });
 }
Beispiel #6
0
 public static Class ForCollection(OdcmEntityClass odcmClass)
 {
     return(new Class
     {
         AccessModifier = "internal ",
         BaseClass = new Type(NamesService.GetExtensionTypeName("QueryableSet"),
                              new Type(NamesService.GetConcreteInterfaceName(odcmClass))),
         Constructors = global::Vipr.Writer.CSharp.Lite.Constructors.ForCollection(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.Lite.ImplementedInterfaces.ForCollectionClass(odcmClass),
         Identifier = NamesService.GetCollectionTypeName(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Lite.Methods.ForCollectionClass(odcmClass),
         Indexers = global::Vipr.Writer.CSharp.Lite.Indexers.ForCollection(odcmClass)
     });
 }
Beispiel #7
0
        private void Write(CollectionConstructor collectionConstructor)
        {
            _("internal {0}(global::Microsoft.OData.Client.DataServiceQuery inner," +
              "{1} context," +
              "object entity," +
              "string path)" +
              ": base(inner, context, entity as {2}, path)",
              NamesService.GetCollectionTypeName(collectionConstructor.OdcmClass).Name,
              NamesService.GetExtensionTypeName("DataServiceContextWrapper"),
              NamesService.GetExtensionTypeName("EntityBase"));
            _("{");

            _("}");
        }
Beispiel #8
0
 public static Class ForComplex(OdcmClass odcmClass)
 {
     return(new Class
     {
         AbstractModifier = odcmClass.IsAbstract ? "abstract " : string.Empty,
         AccessModifier = "public ",
         Constructors = global::Vipr.Writer.CSharp.Lite.Constructors.ForComplex(odcmClass),
         BaseClass =
             new Type(odcmClass.Base == null
                 ? NamesService.GetExtensionTypeName("ComplexTypeBase")
                 : NamesService.GetPublicTypeName(odcmClass.Base)),
         Description = odcmClass.Description,
         Fields = global::Vipr.Writer.CSharp.Lite.Fields.ForComplex(odcmClass),
         Identifier = NamesService.GetConcreteTypeName(odcmClass),
         Properties = global::Vipr.Writer.CSharp.Lite.Properties.ForComplex(odcmClass),
     });
 }
Beispiel #9
0
 public static Class ForFetcher(OdcmClass odcmClass)
 {
     return(new Class
     {
         AccessModifier = "internal ",
         BaseClass =
             new Type(odcmClass.Base == null
                 ? NamesService.GetExtensionTypeName("RestShallowObjectFetcher")
                 : NamesService.GetFetcherTypeName(odcmClass.Base)),
         Constructors = global::Vipr.Writer.CSharp.Lite.Constructors.ForFetcher(odcmClass),
         Fields = global::Vipr.Writer.CSharp.Lite.Fields.ForFetcher(odcmClass),
         Identifier = NamesService.GetFetcherTypeName(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.Lite.ImplementedInterfaces.ForFetcherClass(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Lite.Methods.ForFetcherClass(odcmClass),
         Properties = global::Vipr.Writer.CSharp.Lite.Properties.ForFetcher(odcmClass),
     });
 }
Beispiel #10
0
        public static IEnumerable <Interface> ForCollection(OdcmEntityClass odcmClass)
        {
            var interfaces = new List <Interface>();

            foreach (var projection in odcmClass.DistinctProjections())
            {
                var @interface = new Interface
                {
                    Attributes = global::Vipr.Writer.CSharp.Lite.Attributes.ForCollectionInterface,
                    Identifier = NamesService.GetCollectionInterfaceName(odcmClass, projection),
                    Namespace  = NamesService.GetNamespaceName(odcmClass.Namespace),
                    Methods    = global::Vipr.Writer.CSharp.Lite.Methods.ForCollectionInterface(odcmClass, projection),
                    Indexers   = IndexerSignature.ForCollectionInterface(odcmClass, projection),
                    Interfaces = new[] { new Type(NamesService.GetExtensionTypeName("IReadOnlyQueryableSetBase"), new Type(NamesService.GetConcreteInterfaceName(odcmClass))) }
                };

                interfaces.Add(@interface);
            }

            return(interfaces);
        }
Beispiel #11
0
        private void Write(StructuralCollectionProperty property)
        {
            WriteDeclaration(property);

            using (_builder.IndentBraced)
            {
                _("get");

                using (_builder.IndentBraced)
                {
                    _("if (this.{0} == default({1}))", property.FieldName, property.Type);

                    using (_builder.IndentBraced)
                    {
                        _("this.{0} = new {1}<{2}>();", property.FieldName,
                          NamesService.GetExtensionTypeName("NonEntityTypeCollectionImpl"), property.InstanceType);
                        _("this.{0}.SetContainer(() => GetContainingEntity(\"{1}\"));", property.FieldName, property.ModelName);
                    }

                    _("return this.{0};", property.FieldName);
                }
                _("set");
                using (_builder.IndentBraced)
                {
                    _("{0}.Clear();", property.Name);
                    _("if (value != null)");

                    using (_builder.IndentBraced)
                    {
                        _("foreach (var i in value)");

                        using (_builder.IndentBraced)
                        {
                            _("{0}.Add(i);", property.Name);
                        }
                    }
                }
            }
        }
Beispiel #12
0
 private void Write(EntityContainerConstructor entityContainerConstructor)
 {
     _("public {0}(global::System.Uri serviceRoot, global::System.Func<global::System.Threading.Tasks.Task<string>> accessTokenGetter)",
       entityContainerConstructor.Name);
     using (_builder.IndentBraced)
     {
         _("Context = new {0}(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4, accessTokenGetter);", NamesService.GetExtensionTypeName("DataServiceContextWrapper"));
         _("Context.MergeOption = global::Microsoft.OData.Client.MergeOption.OverwriteChanges;");
         _("Context.ResolveName = new global::System.Func<global::System.Type, string>(this.ResolveNameFromType);");
         _("Context.ResolveType = new global::System.Func<string, global::System.Type>(this.ResolveTypeFromName);");
         _("this.OnContextCreated();");
         _("Context.Format.LoadServiceModel = GeneratedEdmModel.GetInstance;");
         _("Context.Format.UseJson();");
     }
     _("partial void OnContextCreated();");
 }